PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/emesene/e3/papylib/papyon/papyon/service/OfflineIM/rsi.py

https://github.com/esmanhotto/emesene
Python | 82 lines | 46 code | 14 blank | 22 comment | 1 complexity | 44f3cf83851d3995ae2af34da34e6e90 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. #
  3. # papyon - a python client library for Msn
  4. #
  5. # Copyright (C) 2007 Johann Prieur <johann.prieur@gmail.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. from papyon.util.async import *
  21. from papyon.util.element_tree import XMLTYPE
  22. from papyon.service.OfflineIM.constants import *
  23. from papyon.service.SingleSignOn import *
  24. from papyon.service.SOAPService import SOAPService
  25. import email
  26. import logging
  27. __all__ = ['RSI']
  28. logger = logging.getLogger('papyon.service')
  29. class RSI(SOAPService):
  30. def __init__(self, sso, proxies=None):
  31. self._sso = sso
  32. self._tokens = {}
  33. SOAPService.__init__(self, "RSI", proxies)
  34. def GetMetadata(self, callback, errback):
  35. self.__soap_request(callback, errback,
  36. self._service.GetMetadata,
  37. ())
  38. def _HandleGetMetadataResponse(self, callback, errback, response, user_data):
  39. run(callback, response.text)
  40. def GetMessage(self, callback, errback, message_id, mark_as_read):
  41. self.__soap_request(callback, errback,
  42. self._service.GetMessage,
  43. (message_id, XMLTYPE.bool.encode(mark_as_read)))
  44. def _HandleGetMessageResponse(self, callback, errback, response, user_data):
  45. m = email.message_from_string(response.text)
  46. run_id = m.get('X-OIM-Run-Id')[1:-1]
  47. seq_num = int(m.get('X-OIM-Sequence-Num'))
  48. if m.get_content_type().split('/')[1] == 'vnd.ms-msnipg':
  49. # FIXME : process the IPG data
  50. # http://www.amsn-project.net/forums/viewtopic.php?p=21744
  51. # set a mobile sender flag
  52. return
  53. run(callback, run_id, seq_num, m.get_payload().decode('base64'))
  54. def DeleteMessages(self, callback, errback, message_ids):
  55. self.__soap_request(callback, errback,
  56. self._service.DeleteMessages,
  57. (message_ids,))
  58. @RequireSecurityTokens(LiveService.MESSENGER)
  59. def __soap_request(self, callback, errback, method, args):
  60. token = str(self._tokens[LiveService.MESSENGER])
  61. self._soap_request(method, (token,), args, callback, errback)
  62. def _HandleSOAPResponse(self, request_id, callback, errback,
  63. soap_response, user_data):
  64. run(callback)
  65. def _HandleSOAPFault(self, request_id, callback, errback,
  66. soap_response, user_data):
  67. error = OfflineMessagesBoxError.from_fault(soap_response.fault)
  68. run(errback, error)