~vishvananda/nova/network-refactor

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/test/process_twisted.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""A process that reads from stdin and out using Twisted."""
 
2
 
 
3
### Twisted Preamble
 
4
# This makes sure that users don't have to set up their environment
 
5
# specially in order to run these programs from bin/.
 
6
import sys, os, string
 
7
pos = string.find(os.path.abspath(sys.argv[0]), os.sep+'Twisted')
 
8
if pos != -1:
 
9
    sys.path.insert(0, os.path.abspath(sys.argv[0])[:pos+8])
 
10
sys.path.insert(0, os.curdir)
 
11
### end of preamble
 
12
 
 
13
 
 
14
from twisted.python import log
 
15
from zope.interface import implements
 
16
from twisted.internet import interfaces
 
17
 
 
18
log.startLogging(sys.stderr)
 
19
 
 
20
from twisted.internet import protocol, reactor, stdio
 
21
 
 
22
 
 
23
class Echo(protocol.Protocol):
 
24
    implements(interfaces.IHalfCloseableProtocol)
 
25
    
 
26
    def connectionMade(self):
 
27
        print "connection made"
 
28
    
 
29
    def dataReceived(self, data):
 
30
        self.transport.write(data)
 
31
 
 
32
    def readConnectionLost(self):
 
33
        print "readConnectionLost"
 
34
        self.transport.loseConnection()
 
35
    def writeConnectionLost(self):
 
36
        print "writeConnectionLost"
 
37
    
 
38
    def connectionLost(self, reason):
 
39
        print "connectionLost", reason
 
40
        reactor.stop()
 
41
 
 
42
stdio.StandardIO(Echo())
 
43
reactor.run()