home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / yahoo / yahooP2Pprotocol.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  5.0 KB  |  146 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from util.primitives.mapping import groupify
  5. from yahooP2Psocket import YahooP2PSocket
  6. from yahoolookup import commands, statuses
  7. from yahooutil import yiter_to_dict
  8. from util.lrucache import ExpiringLRU
  9. REMEMBER_MESSAGES_FOR = 300
  10. ACK_LIST = '430'
  11.  
  12. def ack_message(yahoo_connection, d, buddy_key):
  13.     ret = True
  14.     lru = getattr(yahoo_connection, '_msg_acks', None)
  15.     if lru is None:
  16.         lru = yahoo_connection._msg_acks = ExpiringLRU(REMEMBER_MESSAGES_FOR)
  17.     
  18.     ack_message_key = get_ack_message_key(d, buddy_key)
  19.     if ack_message_key is not None:
  20.         if ack_message_key in lru:
  21.             c1 = dict(lru[ack_message_key])
  22.             c2 = dict(d)
  23.             s1 = c1.pop('send_attempt', None)
  24.             s2 = c2.pop('send_attempt', None)
  25.             if s2 is not s2:
  26.                 pass
  27.             elif s2 is not None and s1 != s2:
  28.                 if c1['msgid'] == c2['msgid'] and c1.get('message') == c2.get('message'):
  29.                     ret = False
  30.                 
  31.             
  32.             if not ret:
  33.                 lru[ack_message_key] = lru[ack_message_key]
  34.             else:
  35.                 lru[ack_message_key] = d
  36.         else:
  37.             lru[ack_message_key] = d
  38.     
  39.     dout = type(d)()
  40.     dout['frombuddy'] = d['to']
  41.     dout['to'] = d[buddy_key]
  42.     for k in [
  43.         'msgid',
  44.         'send_attempt']:
  45.         if k in d:
  46.             if k == 'msgid':
  47.                 dout['begin_mode'] = ACK_LIST
  48.                 dout['msgid_ack'] = d['msgid']
  49.                 dout['end_mode'] = ACK_LIST
  50.                 dout.pop('message', None)
  51.             else:
  52.                 dout[k] = d[k]
  53.         k == 'msgid'
  54.     
  55.     yahoo_connection.send('msg_ack', 'available', ydict = dout)
  56.     return ret
  57.  
  58.  
  59. def get_ack_message_key(d, buddy_key):
  60.     if 'msgid' in d:
  61.         return (d[buddy_key], d['to'], buddy_key, d['msgid'])
  62.  
  63.  
  64. class YahooP2P(object):
  65.     
  66.     def __init__(self, yahoo, buddy, me, remote_client, session_id):
  67.         self.yahoo = yahoo
  68.         self.buddy = buddy
  69.         self.me = me
  70.         self.rc = remote_client
  71.         self.socket = YahooP2PSocket(self, self.rc, session_id)
  72.         self.socket.connect(self.rc)
  73.  
  74.     
  75.     def incoming_message_raw(self, ydict_iter):
  76.         return getattr(self.yahoo, 'incoming_message_raw')(ydict_iter)
  77.  
  78.     
  79.     def message_notinoffice_raw(self, ydict_iter):
  80.         return getattr(self.yahoo, 'message_notinoffice_raw')(ydict_iter)
  81.  
  82.     
  83.     def message_brb_raw(self, ydict_iter):
  84.         return getattr(self.yahoo, 'message_brb_raw')(ydict_iter)
  85.  
  86.     
  87.     def message_offline_raw(self, ydict_iter):
  88.         out = list(ydict_iter)
  89.         i = list(out)
  90.         print 'i', i
  91.         messages = groupify(i)
  92.         for d in messages:
  93.             d = yiter_to_dict(d.iteritems())
  94.             if 'message' not in d:
  95.                 continue
  96.             
  97.             if 'frombuddy' not in d:
  98.                 continue
  99.             
  100.             if 'msgid' not in d:
  101.                 d['buddy'] = d['frombuddy']
  102.                 d.pop('frombuddy')
  103.                 for k in d.keys():
  104.                     if k not in ('message', 'buddy', 'to'):
  105.                         d.pop(k)
  106.                         continue
  107.                 
  108.                 self.send('message', 'brb', ydict = d)
  109.                 continue
  110.                 continue
  111.             ack_message(self, d, 'frombuddy')
  112.         
  113.         return getattr(self.yahoo, 'message_offline_raw')(iter(out))
  114.  
  115.     
  116.     def notify_typing(self, typing_status, flag):
  117.         self.yahoo.notify_brb(self.buddy, typing_status, flag)
  118.  
  119.     
  120.     def on_close(self):
  121.         foo = self.yahoo.peertopeers.pop(self.buddy)
  122.  
  123.     
  124.     def on_connect(self):
  125.         self.send('p2pfilexfer', 'available', buddy = self.me, to = self.buddy, flag = '1', typing_status = 'PEERTOPEER', **{
  126.             '2': '1' })
  127.  
  128.     
  129.     def p2pfilexfer_available(self, buddy, to, flag, typing_status, **k):
  130.         if flag == '5':
  131.             self.send('p2pfilexfer', 'available', buddy = to, to = buddy, flag = '6', typing_status = 'PEERTOPEER')
  132.         elif flag == '7':
  133.             self.send('p2pfilexfer', 'available', buddy = to, to = buddy, flag = '7', typing_status = 'PEERTOPEER')
  134.         
  135.  
  136.     
  137.     def send(self, command, status, ydict = { }, **kw):
  138.         self.socket.ysend(commands[command], statuses[status], data = ydict)
  139.  
  140.     
  141.     def Disconnect(self):
  142.         self.socket.close()
  143.         foo = self.yahoo.peertopeers.pop(self.buddy)
  144.  
  145.  
  146.