stdio_test_consumer.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- test-case-name: twisted.test.test_stdio.StandardInputOutputTests.test_consumer -*-
  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_consumer} to test
  7. that process transports implement IConsumer properly.
  8. """
  9. from __future__ import absolute_import, division
  10. import sys
  11. from twisted.python import log, reflect
  12. from twisted.internet import stdio, protocol
  13. from twisted.protocols import basic
  14. def failed(err):
  15. log.startLogging(sys.stderr)
  16. log.err(err)
  17. class ConsumerChild(protocol.Protocol):
  18. def __init__(self, junkPath):
  19. self.junkPath = junkPath
  20. def connectionMade(self):
  21. d = basic.FileSender().beginFileTransfer(open(self.junkPath, 'rb'),
  22. self.transport)
  23. d.addErrback(failed)
  24. d.addCallback(lambda ign: self.transport.loseConnection())
  25. def connectionLost(self, reason):
  26. reactor.stop()
  27. if __name__ == '__main__':
  28. reflect.namedAny(sys.argv[1]).install()
  29. from twisted.internet import reactor
  30. stdio.StandardIO(ConsumerChild(sys.argv[2]))
  31. reactor.run()