~certify-web-dev/twisted/certify-staging

« back to all changes in this revision

Viewing changes to twisted/test/stdio_test_loseconn.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-01-02 19:38:17 UTC
  • mfrom: (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100102193817-jphp464ppwh7dulg
Tags: 9.0.0-1
* python-twisted: Depend on the python-twisted-* 9.0 packages.
* python-twisted: Depend on python-zope.interface only. Closes: #557781.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
 
11
11
import sys
12
12
 
 
13
from twisted.internet.error import ConnectionDone
13
14
from twisted.internet import stdio, protocol
14
 
from twisted.python import reflect
 
15
from twisted.python import reflect, log
15
16
 
16
17
class LoseConnChild(protocol.Protocol):
 
18
    exitCode = 0
 
19
 
17
20
    def connectionMade(self):
18
21
        self.transport.loseConnection()
19
22
 
20
23
 
21
24
    def connectionLost(self, reason):
22
 
        reactor.stop()
 
25
        """
 
26
        Check that C{reason} is a L{Failure} wrapping a L{ConnectionDone}
 
27
        instance and stop the reactor.  If C{reason} is wrong for some reason,
 
28
        log something about that in C{self.errorLogFile} and make sure the
 
29
        process exits with a non-zero status.
 
30
        """
 
31
        try:
 
32
            try:
 
33
                reason.trap(ConnectionDone)
 
34
            except:
 
35
                log.err(None, "Problem with reason passed to connectionLost")
 
36
                self.exitCode = 1
 
37
        finally:
 
38
            reactor.stop()
23
39
 
24
40
 
25
41
if __name__ == '__main__':
26
42
    reflect.namedAny(sys.argv[1]).install()
 
43
    log.startLogging(file(sys.argv[2], 'w'))
27
44
    from twisted.internet import reactor
28
 
    stdio.StandardIO(LoseConnChild())
 
45
    protocol = LoseConnChild()
 
46
    stdio.StandardIO(protocol)
29
47
    reactor.run()
 
48
    sys.exit(protocol.exitCode)