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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import hooks
  5. import logging
  6. from rpc.jsonrpc import Dsuccess, Derror
  7. log = logging.getLogger('social.network')
  8. from util import try_this, Storage
  9. from common import AccountBase, profile, UpdateMixin, FromNetMixin, pref
  10.  
  11. class SocialNetwork(UpdateMixin, AccountBase, FromNetMixin):
  12.     filters = { }
  13.     header_funcs = []
  14.     timer = Null
  15.     
  16.     def __init__(self, enabled = True, **options):
  17.         AccountBase.__init__(self, **options)
  18.         UpdateMixin.__init__(self, **options)
  19.         FromNetMixin.__init__(self, **options)
  20.         self.enabled = enabled
  21.         self._dirty_error = True
  22.  
  23.     
  24.     def dirty(self):
  25.         return self._dirty
  26.  
  27.     dirty = property(dirty)
  28.     
  29.     def display_name(self):
  30.         return (try_this,)((lambda : getattr(self, pref('social.display_attr'))), self.username)
  31.  
  32.     display_name = property(display_name)
  33.     
  34.     def _decryptedpw(self):
  35.         return profile.plain_pw(self.password)
  36.  
  37.     
  38.     def update_info(self, **info):
  39.         force = info.pop('force', None)
  40.         self._dirty_error = True
  41.         for k, v in info.iteritems():
  42.             setattr(self, k, v)
  43.         
  44.         self.notify()
  45.         profile.update_account(self, force = force)
  46.  
  47.     
  48.     def get_options(self):
  49.         
  50.         try:
  51.             get_opts = super(SocialNetwork, self).get_options
  52.         except AttributeError:
  53.             opts = { }
  54.  
  55.         opts = get_opts()
  56.         opts.pop('updatefreq', None)
  57.         return opts
  58.  
  59.     
  60.     def icon(self):
  61.         skin = skin
  62.         import gui
  63.         try_this = try_this
  64.         import util
  65.         return (None, try_this)((lambda : skin.get('serviceicons.%s' % self.protocol)), None)
  66.  
  67.     icon = property(icon)
  68.     
  69.     def error_link(self):
  70.         reason = self.Reasons
  71.         if self.protocol_info().get('needs_password', True):
  72.             bplinkref = ((_('Edit Account'),), (lambda : profile.account_manager.edit(self, True)))
  73.         else:
  74.             bplinkref = ((_('Retry'),), (lambda : self.Connect()))
  75.         linkref = {
  76.             reason.BAD_PASSWORD: bplinkref,
  77.             reason.CONN_FAIL: ((_('Retry'),), (lambda : self.Connect())),
  78.             reason.OTHER_USER: ((_('Reconnect'),), (lambda : self.update_now())),
  79.             reason.CONN_LOST: ((_('Retry'),), (lambda : self.update_now())),
  80.             reason.WILL_RECONNECT: ((_('Retry'),), (lambda : self.update_now())),
  81.             reason.NONE: None }
  82.         if self.offline_reason in linkref:
  83.             return linkref[self.offline_reason]
  84.         log.debug("Couldn't find offline reason %r in linkref dictionary. Returning None for error_link", self.offline_reason)
  85.         return None
  86.  
  87.     
  88.     def service(self):
  89.         raise NotImplementedError
  90.  
  91.     service = property(service)
  92.     
  93.     def protocol(self):
  94.         raise NotImplementedError
  95.  
  96.     protocol = property(protocol)
  97.     
  98.     def Connect(self, *a, **k):
  99.         raise NotImplementedError
  100.  
  101.     
  102.     def Disconnect(self, *a, **k):
  103.         raise NotImplementedError
  104.  
  105.     
  106.     def disconnect(self, *a, **k):
  107.         raise NotImplementedError
  108.  
  109.     
  110.     def observe_count(self, callback):
  111.         return NotImplemented
  112.  
  113.     
  114.     def observe_state(self, callback):
  115.         return NotImplemented
  116.  
  117.     
  118.     def unobserve_count(self, callback):
  119.         return NotImplemented
  120.  
  121.     
  122.     def unobserve_state(self, callback):
  123.         return NotImplemented
  124.  
  125.  
  126. import weakref
  127. weak_socialfeeds = weakref.WeakValueDictionary()
  128.  
  129. def on_dirty(ctx):
  130.     
  131.     try:
  132.         feed = weak_socialfeeds[ctx]
  133.     except KeyError:
  134.         log.warning('SocialFeed marked dirty but not in weak dictionary: %r', ctx)
  135.  
  136.     feed.set_dirty()
  137.  
  138. hooks.register('social.feed.mark_dirty', on_dirty)
  139.  
  140. class SocialFeed(object):
  141.     
  142.     def __init__(self, id_, feed_context, get_feed_items, render_items, set_dirty = None):
  143.         self.id = id_
  144.         self.context = feed_context
  145.         self.get_feed_items = get_feed_items
  146.         self.render_items = render_items
  147.         self.iterators = { }
  148.         hooks.notify('social.feed.created', self.id)
  149.         self.set_dirty_cb = set_dirty
  150.         weak_socialfeeds[self.id] = self
  151.  
  152.     
  153.     def set_dirty(self):
  154.         if self.set_dirty_cb is not None:
  155.             self.set_dirty_cb()
  156.         else:
  157.             log.warning('%r dirty hook called, but has no callback', self)
  158.  
  159.     
  160.     def get_iterator(self):
  161.         iterator_info = Storage(id = self.id, context = self.context, iterator = self.get_feed_items())
  162.         return hooks.reduce('social.feed.iterator', iterator_info).iterator
  163.  
  164.     
  165.     def new_ids(self, ids):
  166.         hooks.notify('social.feed.updated', self.id, ids)
  167.  
  168.     
  169.     def jscall_initialize_feed(self, webview, _id):
  170.         self.iterators.pop(webview, None)
  171.  
  172.     
  173.     def jscall_next_item(self, webview, id):
  174.         
  175.         try:
  176.             it = self.iterators[webview]
  177.         except KeyError:
  178.             it = self.iterators[webview] = self.get_iterator()
  179.  
  180.         
  181.         try:
  182.             item = it.next()
  183.         except StopIteration:
  184.             Derror(id, webview)
  185.  
  186.         Dsuccess(id, webview, html = self.render_items([
  187.             item], self.context))
  188.  
  189.  
  190.