You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

loopback.py 757B

5 years ago
12345678910111213141516171819202122232425262728
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Loopback helper used in test_ssh and test_recvline
  5. """
  6. from __future__ import division, absolute_import
  7. from twisted.protocols import loopback
  8. class LoopbackRelay(loopback.LoopbackRelay):
  9. clearCall = None
  10. def logPrefix(self):
  11. return "LoopbackRelay(%r)" % (self.target.__class__.__name__,)
  12. def write(self, data):
  13. loopback.LoopbackRelay.write(self, data)
  14. if self.clearCall is not None:
  15. self.clearCall.cancel()
  16. from twisted.internet import reactor
  17. self.clearCall = reactor.callLater(0, self._clearBuffer)
  18. def _clearBuffer(self):
  19. self.clearCall = None
  20. loopback.LoopbackRelay.clearBuffer(self)