stdio_test_write.py 923 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- test-case-name: twisted.test.test_stdio.StandardInputOutputTests.test_write -*-
  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_write} to test that
  7. ITransport.write() works 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 WriteChild(protocol.Protocol):
  14. def connectionMade(self):
  15. self.transport.write(b'o')
  16. self.transport.write(b'k')
  17. self.transport.write(b'!')
  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(WriteChild())
  25. reactor.run()