Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / twisted / test / | server ip : 172.67.156.115 your ip : 172.69.59.145 H O M E |
Filename | /usr/lib/python2.7/dist-packages/twisted/test/stdio_test_halfclose.py |
Size | 1.86 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 24-Jan-2012 06:55 |
Last accessed | 07-Jul-2025 00:07 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
# -*- test-case-name: twisted.test.test_stdio.StandardInputOutputTestCase.test_readConnectionLost -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Main program for the child process run by
L{twisted.test.test_stdio.StandardInputOutputTestCase.test_readConnectionLost}
to test that IHalfCloseableProtocol.readConnectionLost works for process
transports.
"""
import sys, _preamble
from zope.interface import implements
from twisted.internet.interfaces import IHalfCloseableProtocol
from twisted.internet import stdio, protocol
from twisted.python import reflect, log
class HalfCloseProtocol(protocol.Protocol):
"""
A protocol to hook up to stdio and observe its transport being
half-closed. If all goes as expected, C{exitCode} will be set to C{0};
otherwise it will be set to C{1} to indicate failure.
"""
implements(IHalfCloseableProtocol)
exitCode = None
def connectionMade(self):
"""
Signal the parent process that we're ready.
"""
self.transport.write("x")
def readConnectionLost(self):
"""
This is the desired event. Once it has happened, stop the reactor so
the process will exit.
"""
self.exitCode = 0
reactor.stop()
def connectionLost(self, reason):
"""
This may only be invoked after C{readConnectionLost}. If it happens
otherwise, mark it as an error and shut down.
"""
if self.exitCode is None:
self.exitCode = 1
log.err(reason, "Unexpected call to connectionLost")
reactor.stop()
if __name__ == '__main__':
reflect.namedAny(sys.argv[1]).install()
log.startLogging(file(sys.argv[2], 'w'))
from twisted.internet import reactor
protocol = HalfCloseProtocol()
stdio.StandardIO(protocol)
reactor.run()
sys.exit(protocol.exitCode)
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Main program for the child process run by
L{twisted.test.test_stdio.StandardInputOutputTestCase.test_readConnectionLost}
to test that IHalfCloseableProtocol.readConnectionLost works for process
transports.
"""
import sys, _preamble
from zope.interface import implements
from twisted.internet.interfaces import IHalfCloseableProtocol
from twisted.internet import stdio, protocol
from twisted.python import reflect, log
class HalfCloseProtocol(protocol.Protocol):
"""
A protocol to hook up to stdio and observe its transport being
half-closed. If all goes as expected, C{exitCode} will be set to C{0};
otherwise it will be set to C{1} to indicate failure.
"""
implements(IHalfCloseableProtocol)
exitCode = None
def connectionMade(self):
"""
Signal the parent process that we're ready.
"""
self.transport.write("x")
def readConnectionLost(self):
"""
This is the desired event. Once it has happened, stop the reactor so
the process will exit.
"""
self.exitCode = 0
reactor.stop()
def connectionLost(self, reason):
"""
This may only be invoked after C{readConnectionLost}. If it happens
otherwise, mark it as an error and shut down.
"""
if self.exitCode is None:
self.exitCode = 1
log.err(reason, "Unexpected call to connectionLost")
reactor.stop()
if __name__ == '__main__':
reflect.namedAny(sys.argv[1]).install()
log.startLogging(file(sys.argv[2], 'w'))
from twisted.internet import reactor
protocol = HalfCloseProtocol()
stdio.StandardIO(protocol)
reactor.run()
sys.exit(protocol.exitCode)