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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from common.Conversation import Conversation
  5. from util import dictadd, callsback
  6. from yahoobuddy import YahooBuddy
  7. from yahoolookup import ykeys
  8. from  import yahooformat
  9. from logging import getLogger
  10. log = getLogger('yahoo.convo')
  11.  
  12. class YahooConvoBase(Conversation):
  13.     
  14.     def __init__(self, protocol):
  15.         Conversation.__init__(self, protocol)
  16.         self.__dict__.update(buddies = protocol.buddies, self_buddy = protocol.self_buddy)
  17.  
  18.     
  19.     def buddy_join(self, buddy):
  20.         self.typing_status[buddy] = None
  21.         if buddy not in self.room_list:
  22.             self.room_list.append(buddy)
  23.             super(YahooConvoBase, self).buddy_join(buddy)
  24.         
  25.  
  26.     
  27.     def buddy_leave(self, buddy):
  28.         if buddy in self.room_list:
  29.             self.room_list.remove(buddy)
  30.             del self.typing_status[buddy]
  31.         
  32.         super(YahooConvoBase, self).buddy_leave(buddy)
  33.  
  34.     
  35.     def incoming_message(self, buddy, message, timestamp = None, content_type = 'text/yahoortf'):
  36.         if not isinstance(buddy, YahooBuddy):
  37.             raise TypeError()
  38.         isinstance(buddy, YahooBuddy)
  39.         if content_type == 'text/html':
  40.             message = yahooformat.tohtml(message)
  41.             message = yahooformat.fix_font_size(message)
  42.         
  43.         if content_type == 'text/yahoortf':
  44.             message = yahooformat.tohtml(message.encode('xml'))
  45.             content_type = 'text/html'
  46.         
  47.         message = newlines_to_brs(message)
  48.         self.typing_status[buddy] = None
  49.         if timestamp is None:
  50.             kws = { }
  51.         else:
  52.             kws = dict(timestamp = timestamp)
  53.         kws['content_type'] = content_type
  54.         if self.received_message(buddy, message, **kws):
  55.             Conversation.incoming_message(self)
  56.         
  57.  
  58.     
  59.     def myname(self):
  60.         return self.self_buddy.name
  61.  
  62.     myname = property(myname)
  63.     
  64.     def send_typing_status(self, status = None):
  65.         pass
  66.  
  67.  
  68.  
  69. class YahooConvo(YahooConvoBase):
  70.     ischat = False
  71.     
  72.     def __init__(self, parent_protocol, buddy):
  73.         YahooConvoBase.__init__(self, parent_protocol)
  74.         self.buddy_join(parent_protocol.self_buddy)
  75.         self.buddy_join(buddy)
  76.         self.name = buddy.alias
  77.         self.to_from = {
  78.             '1': self.myname,
  79.             '5': buddy.name }
  80.  
  81.     
  82.     def _send_message(self, message, auto = False, callback = None, **options):
  83.         network_msg = message.format_as('yahoo')
  84.         network_msg = network_msg.encode('utf-8')
  85.         d = {
  86.             ykeys['message']: network_msg,
  87.             ykeys['msg_encoding']: '1' }
  88.         import YahooProtocol
  89.         servicekey = YahooProtocol.PROTOCOL_CODES.get(self.buddy.service, None)
  90.         if servicekey is not None:
  91.             d[ykeys['buddy_service']] = servicekey
  92.         
  93.         log.info('Sending message to %r. buddy_service=%r', self.buddy, self.buddy.service == 'msn')
  94.         
  95.         try:
  96.             self.protocol.send('message', 'offline', dictadd(self.to_from, d))
  97.         except Exception:
  98.             e = None
  99.             callback.error(e)
  100.  
  101.         callback.success()
  102.  
  103.     _send_message = callsback(_send_message)
  104.     
  105.     def self_buddy(self):
  106.         return self.protocol.self_buddy
  107.  
  108.     self_buddy = property(self_buddy)
  109.     
  110.     def send_typing_status(self, status = None):
  111.         typing_now = status == 'typing'
  112.         None(log.debug, 'sending %styping' if not typing_now else '')
  113.         None(self.protocol.send, 'notify', [
  114.             'typing',
  115.             'typing_status',
  116.             'TYPING',
  117.             'frombuddy',
  118.             self.self_buddy.name,
  119.             'message',
  120.             '',
  121.             'flag' if typing_now else '0',
  122.             'to',
  123.             self.buddy.name])
  124.  
  125.     
  126.     def exit(self):
  127.         self.protocol.exit_conversation(self)
  128.         Conversation.exit(self)
  129.  
  130.     
  131.     def __repr__(self):
  132.         return '<%s with %s from %s>' % (self.__class__.__name__, self.buddy, self.protocol.username)
  133.  
  134.  
  135.  
  136. class YahooConf(YahooConvoBase):
  137.     ischat = True
  138.     
  139.     def __init__(self, parent_protocol, name):
  140.         YahooConvoBase.__init__(self, parent_protocol)
  141.         self.name = name
  142.  
  143.     
  144.     def _bind_reconnect(self):
  145.         pass
  146.  
  147.     
  148.     def chat_room_name(self):
  149.         return self.name
  150.  
  151.     chat_room_name = property(chat_room_name)
  152.     
  153.     def invite(self, buddy, message = None, callback = None):
  154.         bname = getattr(buddy, 'name', buddy)
  155.         self.protocol.invite_to_conference(self.name, bname, message, callback = callback)
  156.  
  157.     invite = callsback(invite)
  158.     
  159.     def _send_message(self, message, callback = None):
  160.         users = []
  161.         _[1]
  162.         callback.success()
  163.  
  164.     _send_message = callsback(_send_message)
  165.     
  166.     def exit(self):
  167.         buddies_to_notify_of_exit = []
  168.         for buddy in self.other_buddies:
  169.             buddies_to_notify_of_exit.extend([
  170.                 'conf_from',
  171.                 buddy.name])
  172.         
  173.         self.protocol.send('conflogoff', 'available', [
  174.             'frombuddy',
  175.             self.self_buddy.name,
  176.             'conf_name',
  177.             self.name] + buddies_to_notify_of_exit)
  178.         Conversation.exit(self)
  179.  
  180.     
  181.     def __repr__(self):
  182.         return '<YahooConf %s (%d members)>' % (self.name, len(self.room_list))
  183.  
  184.  
  185.  
  186. class YahooChat(YahooConvoBase):
  187.     
  188.     def __init__(self, parent_protocol, name = 'Yahoo Chat', topic = ''):
  189.         YahooConvoBase.__init__(self, parent_protocol)
  190.         self.name = name
  191.         self.topic = topic
  192.  
  193.     
  194.     def _send_message(self, message):
  195.         log.info_s('send_message for %r: %s', self, message)
  196.         self.protocol.send('comment', 'available', dictadd(dict(frombuddy = self.myname, room_name = self.name, chat_message = message.format_as('yahoo')), {
  197.             '124': '1' }))
  198.  
  199.     
  200.     def exit(self):
  201.         log.info('YahooChat exit: sending chatlogout_available')
  202.         self.protocol.send('chatlogout', 'available', frombuddy = self.myname)
  203.         Conversation.exit(self)
  204.  
  205.     
  206.     def __repr__(self):
  207.         return '<YahooChat %s (%d members, topic: %s)' % (self.name, len(self.room_list), self.topic)
  208.  
  209.  
  210.  
  211. def newlines_to_brs(s, br = '<br />'):
  212.     return s.replace('\r\n', '\n').replace('\n', br).replace('\r', br)
  213.  
  214.