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.

1234567891011121314151617181920212223242526272829303132
  1. import logging
  2. try:
  3. import Queue as queue
  4. except ImportError:
  5. import queue
  6. from .templates import AttributeDict
  7. logger = logging.getLogger('itchat')
  8. class Queue(queue.Queue):
  9. def put(self, message):
  10. queue.Queue.put(self, Message(message))
  11. class Message(AttributeDict):
  12. def download(self, fileName):
  13. if hasattr(self.text, '__call__'):
  14. return self.text(fileName)
  15. else:
  16. return b''
  17. def __getitem__(self, value):
  18. if value in ('isAdmin', 'isAt'):
  19. v = value[0].upper() + value[1:] # ''[1:] == ''
  20. logger.debug('%s is expired in 1.3.0, use %s instead.' % (value, v))
  21. value = v
  22. return super(Message, self).__getitem__(value)
  23. def __str__(self):
  24. return '{%s}' % ', '.join(
  25. ['%s: %s' % (repr(k),repr(v)) for k,v in self.items()])
  26. def __repr__(self):
  27. return '<%s: %s>' % (self.__class__.__name__.split('.')[-1],
  28. self.__str__())