~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/test/stdio_test_loseconn.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
# -*- test-case-name: twisted.test.test_stdio.StandardInputOutputTestCase.test_loseConnection -*-
 
2
# Copyright (c) 2006-2007 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
"""
 
6
Main program for the child process run by
 
7
L{twisted.test.test_stdio.StandardInputOutputTestCase.test_loseConnection} to
 
8
test that ITransport.loseConnection() works for process transports.
 
9
"""
 
10
 
 
11
import sys
 
12
 
 
13
from twisted.internet.error import ConnectionDone
 
14
from twisted.internet import stdio, protocol
 
15
from twisted.python import reflect, log
 
16
 
 
17
class LoseConnChild(protocol.Protocol):
 
18
    exitCode = 0
 
19
 
 
20
    def connectionMade(self):
 
21
        self.transport.loseConnection()
 
22
 
 
23
 
 
24
    def connectionLost(self, reason):
 
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()
 
39
 
 
40
 
 
41
if __name__ == '__main__':
 
42
    reflect.namedAny(sys.argv[1]).install()
 
43
    log.startLogging(file(sys.argv[2], 'w'))
 
44
    from twisted.internet import reactor
 
45
    protocol = LoseConnChild()
 
46
    stdio.StandardIO(protocol)
 
47
    reactor.run()
 
48
    sys.exit(protocol.exitCode)