home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / social / network.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  7.6 KB  |  189 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.         self._dirty_error = True
  40.         for k, v in info.iteritems():
  41.             setattr(self, k, v)
  42.         
  43.         self.notify()
  44.         profile.update_account(self)
  45.  
  46.     
  47.     def get_options(self):
  48.         
  49.         try:
  50.             get_opts = super(SocialNetwork, self).get_options
  51.         except AttributeError:
  52.             opts = { }
  53.  
  54.         opts = get_opts()
  55.         opts.pop('updatefreq', None)
  56.         return opts
  57.  
  58.     
  59.     def icon(self):
  60.         skin = skin
  61.         import gui
  62.         try_this = try_this
  63.         import util
  64.         return (None, try_this)((lambda : skin.get('serviceicons.%s' % self.protocol)), None)
  65.  
  66.     icon = property(icon)
  67.     
  68.     def error_link(self):
  69.         reason = self.Reasons
  70.         if self.protocol_info().get('needs_password', True):
  71.             bplinkref = ((_('Edit Account'),), (lambda : profile.account_manager.edit(self, True)))
  72.         else:
  73.             bplinkref = ((_('Retry'),), (lambda : self.Connect()))
  74.         linkref = {
  75.             reason.BAD_PASSWORD: bplinkref,
  76.             reason.CONN_FAIL: ((_('Retry'),), (lambda : self.Connect())),
  77.             reason.OTHER_USER: ((_('Reconnect'),), (lambda : self.update_now())),
  78.             reason.CONN_LOST: ((_('Retry'),), (lambda : self.update_now())),
  79.             reason.WILL_RECONNECT: ((_('Retry'),), (lambda : self.update_now())),
  80.             reason.NONE: None }
  81.         if self.offline_reason in linkref:
  82.             return linkref[self.offline_reason]
  83.         log.debug("Couldn't find offline reason %r in linkref dictionary. Returning None for error_link", self.offline_reason)
  84.         return None
  85.  
  86.     
  87.     def service(self):
  88.         raise NotImplementedError
  89.  
  90.     service = property(service)
  91.     
  92.     def protocol(self):
  93.         raise NotImplementedError
  94.  
  95.     protocol = property(protocol)
  96.     
  97.     def Connect(self, *a, **k):
  98.         raise NotImplementedError
  99.  
  100.     
  101.     def Disconnect(self, *a, **k):
  102.         raise NotImplementedError
  103.  
  104.     
  105.     def disconnect(self, *a, **k):
  106.         raise NotImplementedError
  107.  
  108.     
  109.     def observe_count(self, callback):
  110.         return NotImplemented
  111.  
  112.     
  113.     def observe_state(self, callback):
  114.         return NotImplemented
  115.  
  116.     
  117.     def unobserve_count(self, callback):
  118.         return NotImplemented
  119.  
  120.     
  121.     def unobserve_state(self, callback):
  122.         return NotImplemented
  123.  
  124.  
  125. import weakref
  126. weak_socialfeeds = weakref.WeakValueDictionary()
  127.  
  128. def on_dirty(ctx):
  129.     
  130.     try:
  131.         feed = weak_socialfeeds[ctx]
  132.     except KeyError:
  133.         log.warning('SocialFeed marked dirty but not in weak dictionary: %r', ctx)
  134.  
  135.     feed.set_dirty()
  136.  
  137. hooks.register('social.feed.mark_dirty', on_dirty)
  138.  
  139. class SocialFeed(object):
  140.     
  141.     def __init__(self, id_, feed_context, get_feed_items, render_items, set_dirty = None):
  142.         self.id = id_
  143.         self.context = feed_context
  144.         self.get_feed_items = get_feed_items
  145.         self.render_items = render_items
  146.         self.iterators = { }
  147.         hooks.notify('social.feed.created', self.id)
  148.         self.set_dirty_cb = set_dirty
  149.         weak_socialfeeds[self.id] = self
  150.  
  151.     
  152.     def set_dirty(self):
  153.         if self.set_dirty_cb is not None:
  154.             self.set_dirty_cb()
  155.         else:
  156.             log.warning('%r dirty hook called, but has no callback', self)
  157.  
  158.     
  159.     def get_iterator(self):
  160.         iterator_info = Storage(id = self.id, context = self.context, iterator = self.get_feed_items())
  161.         return hooks.reduce('social.feed.iterator', iterator_info).iterator
  162.  
  163.     
  164.     def new_ids(self, ids):
  165.         hooks.notify('social.feed.updated', self.id, ids)
  166.  
  167.     
  168.     def jscall_initialize_feed(self, webview, _id):
  169.         self.iterators.pop(webview, None)
  170.  
  171.     
  172.     def jscall_next_item(self, webview, id):
  173.         
  174.         try:
  175.             it = self.iterators[webview]
  176.         except KeyError:
  177.             it = self.iterators[webview] = self.get_iterator()
  178.  
  179.         
  180.         try:
  181.             item = it.next()
  182.         except StopIteration:
  183.             Derror(id, webview)
  184.  
  185.         Dsuccess(id, webview, html = self.render_items([
  186.             item], self.context))
  187.  
  188.  
  189.