stdio_test_hostpeer.py 1021 B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- test-case-name: twisted.test.test_stdio.StandardInputOutputTests.test_hostAndPeer -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Main program for the child process run by
  6. L{twisted.test.test_stdio.StandardInputOutputTests.test_hostAndPeer} to test
  7. that ITransport.getHost() and ITransport.getPeer() work for process transports.
  8. """
  9. from __future__ import absolute_import, division
  10. import sys
  11. from twisted.internet import stdio, protocol
  12. from twisted.python import reflect
  13. class HostPeerChild(protocol.Protocol):
  14. def connectionMade(self):
  15. self.transport.write(b'\n'.join([
  16. str(self.transport.getHost()).encode('ascii'),
  17. str(self.transport.getPeer()).encode('ascii')]))
  18. self.transport.loseConnection()
  19. def connectionLost(self, reason):
  20. reactor.stop()
  21. if __name__ == '__main__':
  22. reflect.namedAny(sys.argv[1]).install()
  23. from twisted.internet import reactor
  24. stdio.StandardIO(HostPeerChild())
  25. reactor.run()