home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / msn / p9 / MSNP9Notification.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  4.4 KB  |  113 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. import logging
  6. from util.primitives.funcs import get, isint
  7. from util.xml_tag import tag
  8. import msn
  9. from msn import Message
  10. from msn.p8 import Notification as Super
  11. log = logging.getLogger('msn.p9.ns')
  12. defcb = dict(trid = True, callback = sentinel)
  13.  
  14. class MSNP9Notification(Super):
  15.     events = Super.events | set(('recv_sms', 'contact_icon_info'))
  16.     versions = [
  17.         'MSNP9']
  18.     
  19.     def _set_buddy_icon(self, status, clientid, icon_data, callback):
  20.         if icon_data is not None:
  21.             import hashlib
  22.             hash = hashlib.sha1(icon_data).digest()
  23.             import random
  24.             fn = 'temp%d.dat' % random.randint(1, 1000)
  25.             self.icon_obj = msn.MSNObject(Creator = self.self_buddy.name, Type = '3', Location = fn, Size = len(icon_data), SHA1D = hash)
  26.             self.self_buddy.msn_obj = self.icon_obj
  27.             self.self_buddy.notify('icon_hash')
  28.             log.debug('setting icon obj')
  29.         
  30.         self.send_chg(status, clientid, callback = callback)
  31.  
  32.     
  33.     def _get_buddy_icon(self, name, callback):
  34.         log.info('get buddy icon: %s', name)
  35.  
  36.     
  37.     def _parse_iln_nln(self, msg):
  38.         log.debug('got iln/nln')
  39.         args = Super._parse_iln_nln(self, msg)
  40.         iconinfo = msn.util.url_decode(get(msg.args, 4, ''))
  41.         msnobj = None
  42.         if '<' in iconinfo and '>' in iconinfo:
  43.             
  44.             try:
  45.                 msnobj = msn.MSNObject.parse(iconinfo)
  46.             except Exception:
  47.                 e = None
  48.                 log.error("Error parsing msn object (%r). here's data: %r", e, iconinfo)
  49.             except:
  50.                 None<EXCEPTION MATCH>Exception
  51.             
  52.  
  53.         None<EXCEPTION MATCH>Exception
  54.         return (args, msnobj)
  55.  
  56.     
  57.     def recv_iln(self, msg):
  58.         (args, msnobj) = self._parse_iln_nln(msg)
  59.         name = args[0]
  60.         self.event('contact_online_initial', *args)
  61.         self.event('contact_icon_info', name, msnobj)
  62.  
  63.     
  64.     def recv_nln(self, msg):
  65.         (args, msnobj) = self._parse_iln_nln(msg)
  66.         name = args[0]
  67.         self.event('contact_online', *args)
  68.         self.event('contact_icon_info', name, msnobj)
  69.  
  70.     
  71.     def recv_chg(self, msg):
  72.         Super.recv_chg(self, msg)
  73.         if not msg.args:
  74.             self.icon_obj = None
  75.         else:
  76.             msnobj = msg.args[-1]
  77.             self.icon_obj = msn.MSNObject.parse(msn.util.url_decode(msnobj))
  78.         self.event('contact_icon_info', self._username, self.icon_obj)
  79.  
  80.     
  81.     def recv_ipg(self, msg):
  82.         log.debug('Received IPG command')
  83.         log.debug(str(msg))
  84.         n = tag(msg.payload)
  85.         sender = n.FROM['name']
  86.         message = n.MSG.BODY.TEXT
  87.         if sender.startswith('tel:+'):
  88.             sender = sender[4:]
  89.         
  90.         self.event('recv_sms', sender, unicode(message))
  91.  
  92.     
  93.     def send_png(self):
  94.         log.debug('ping')
  95.         self.socket.send(Message('PNG'))
  96.         log.info('pinged')
  97.  
  98.     
  99.     def send_chg(self, code, client_id, callback = None):
  100.         if code.lower() == 'fln':
  101.             code = 'HDN'
  102.         
  103.         iconobj = getattr(self, 'icon_obj', None)
  104.         if iconobj:
  105.             msnobj = msn.util.url_encode(iconobj.to_xml())
  106.         else:
  107.             msnobj = ''
  108.         if not callback:
  109.             pass
  110.         self.socket.send(Message('CHG', code, str(client_id), msnobj), trid = True, callback = sentinel)
  111.  
  112.  
  113.