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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from jabber import jbuddy, jabber_util
  5. from util import Timer, callsback
  6. from common import pref, profile
  7. from common.actions import action
  8. from objects import ip, pagetime
  9. from pyxmpp.presence import Presence
  10. from jabber.JabberResource import JabberResource
  11. jbuddy_caps = jbuddy.caps
  12. import logging
  13. log = logging.getLogger('digsby.buddy')
  14.  
  15. def no_widgets(self, *a, **k):
  16.     return not (self.iswidget)
  17.  
  18.  
  19. class DigsbyResource(JabberResource):
  20.     away_is_idle = True
  21.  
  22.  
  23. class DigsbyBuddy(jbuddy):
  24.     away_is_idle = True
  25.     resource_class = DigsbyResource
  26.     
  27.     def __init__(self, jabber_, jid, rosteritem = None):
  28.         jbuddy.__init__(self, jabber_, jid, rosteritem)
  29.         iswidget = iswidget
  30.         import digsby.widgets.widget
  31.         self.iswidget = iswidget(self)
  32.         self.ip = None
  33.         self.online_time = None
  34.         profile.account_manager.buddywatcher.unregister(self)
  35.  
  36.     
  37.     def is_video_widget(self):
  38.         node = self.jid.node
  39.         if node:
  40.             pass
  41.         return node.startswith('video.')
  42.  
  43.     is_video_widget = property(is_video_widget)
  44.     
  45.     def remove(self, callback = None):
  46.         ret = jbuddy.remove(self, callback = callback)
  47.         if self.iswidget:
  48.             
  49.             def goaway():
  50.                 
  51.                 try:
  52.                     pres = Presence(stanza_type = 'unavailable', status = 'Logged Out', to_jid = self.jid)
  53.                     self.protocol.stream.send(pres)
  54.                 except (AttributeError, Exception):
  55.                     pass
  56.  
  57.  
  58.             Timer(3, goaway).start()
  59.         
  60.         return ret
  61.  
  62.     remove = action()(callsback(remove))
  63.     
  64.     def caps(self):
  65.         cs = []
  66.         caps = caps
  67.         import common
  68.         if self.id in self.protocol.bots:
  69.             cs.append(caps.BOT)
  70.         
  71.         if self.iswidget:
  72.             cs.extend([
  73.                 caps.INFO,
  74.                 caps.IM])
  75.         else:
  76.             cs.extend(jbuddy.get_caps(self))
  77.         return cs
  78.  
  79.     caps = property(caps)
  80.     
  81.     def service(self):
  82.         return 'digsby'
  83.  
  84.     service = property(service)
  85.     
  86.     def serviceicon(self):
  87.         skin = skin
  88.         import gui
  89.         if not self.iswidget:
  90.             return skin.get('serviceicons.digsby')
  91.         return skin.get('serviceicons.widget')
  92.  
  93.     serviceicon = property(serviceicon)
  94.     
  95.     def update_presence(self, presence, buddy = None):
  96.         groups = jabber_util.xpath_eval(presence.xmlnode, 'd:group', {
  97.             'd': 'digsby:setgroup' })
  98.         if groups:
  99.             
  100.             try:
  101.                 self.widget_to_group(groups[0].getContent())
  102.             except Exception:
  103.                 pass
  104.             except:
  105.                 None<EXCEPTION MATCH>Exception
  106.             
  107.  
  108.         None<EXCEPTION MATCH>Exception
  109.         ips = jabber_util.xpath_eval(presence.xmlnode, 'i:ip', {
  110.             'i': ip.IP_NS })
  111.         if ips:
  112.             
  113.             try:
  114.                 self.ip = ip.Ip(ips[0]).ip
  115.             except Exception:
  116.                 pass
  117.             except:
  118.                 None<EXCEPTION MATCH>Exception
  119.             
  120.  
  121.         None<EXCEPTION MATCH>Exception
  122.         pagetimes = jabber_util.xpath_eval(presence.xmlnode, 'p:pagetime', {
  123.             'p': pagetime.PAGETIME_NS })
  124.         if pagetimes:
  125.             
  126.             try:
  127.                 self.online_time = pagetime.PageTime(pagetimes[0]).pagetime / 1000
  128.             except Exception:
  129.                 pass
  130.             except:
  131.                 None<EXCEPTION MATCH>Exception
  132.             
  133.  
  134.         None<EXCEPTION MATCH>Exception
  135.         jbuddy.update_presence(self, presence, buddy = buddy)
  136.  
  137.     
  138.     def widget_to_group(self, groupname, callback = None):
  139.         log.info('%s add_to_group %s', self, groupname)
  140.         pending = self.pending_adds
  141.         if groupname in pending:
  142.             log.info('ignoring request.')
  143.         else:
  144.             pending.add(groupname)
  145.         item = self.protocol.roster.get_item_by_jid(self.id).clone()
  146.         if groupname not in item.groups:
  147.             item.groups[:] = [
  148.                 groupname]
  149.             query = item.make_roster_push()
  150.             
  151.             def onsuccess(_s):
  152.                 pending.discard(groupname)
  153.                 callback.success()
  154.  
  155.             
  156.             def onerror(_s = (None, None, (None, None, None), None)):
  157.                 pending.discard(groupname)
  158.                 log.warning('error adding %r to %s', self.id, groupname)
  159.                 callback.error()
  160.  
  161.             self.protocol.send_cb(query, success = onsuccess, error = onerror, timeout = onerror)
  162.         
  163.  
  164.     widget_to_group = action(needs = ((unicode, 'Group name'),))(callsback(widget_to_group))
  165.     icon_disabled = property((lambda : True), (lambda : pass))
  166.     
  167.     def cache_icon(self, *a, **k):
  168.         if not self.icon_disabled:
  169.             return super(DigsbyBuddy, self).cache_icon(*a, **k)
  170.  
  171.     
  172.     def _disk_cacheable(self):
  173.         return not (self.iswidget)
  174.  
  175.     _disk_cacheable = property(_disk_cacheable)
  176.  
  177.