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.

avatar.py 1.4KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- test-case-name: twisted.conch.test.test_conch -*-
  2. from __future__ import absolute_import, division
  3. from zope.interface import implementer
  4. from twisted.conch.error import ConchError
  5. from twisted.conch.interfaces import IConchUser
  6. from twisted.conch.ssh.connection import OPEN_UNKNOWN_CHANNEL_TYPE
  7. from twisted.python import log
  8. from twisted.python.compat import nativeString
  9. @implementer(IConchUser)
  10. class ConchUser:
  11. def __init__(self):
  12. self.channelLookup = {}
  13. self.subsystemLookup = {}
  14. def lookupChannel(self, channelType, windowSize, maxPacket, data):
  15. klass = self.channelLookup.get(channelType, None)
  16. if not klass:
  17. raise ConchError(OPEN_UNKNOWN_CHANNEL_TYPE, "unknown channel")
  18. else:
  19. return klass(remoteWindow=windowSize,
  20. remoteMaxPacket=maxPacket,
  21. data=data, avatar=self)
  22. def lookupSubsystem(self, subsystem, data):
  23. log.msg(repr(self.subsystemLookup))
  24. klass = self.subsystemLookup.get(subsystem, None)
  25. if not klass:
  26. return False
  27. return klass(data, avatar=self)
  28. def gotGlobalRequest(self, requestType, data):
  29. # XXX should this use method dispatch?
  30. requestType = nativeString(requestType.replace(b'-', b'_'))
  31. f = getattr(self, "global_%s" % requestType, None)
  32. if not f:
  33. return 0
  34. return f(data)