home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / common / __init__.pyo (.txt) next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  7.1 KB  |  219 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import util
  5. callsback = util.callsback
  6. Timer = util.Timer
  7. from logging import getLogger
  8. log = getLogger('common')
  9. info = log.info
  10.  
  11. def setfakeprefs(userprefs):
  12.     profile = profile
  13.     import common
  14.     _prefs.update(userprefs)
  15.  
  16. castables = (int, float, long, unicode)
  17. _prefs = { }
  18. _defaultprefs = { }
  19.  
  20. def set_active_prefs(prefs, defaults = None):
  21.     global _prefs, _defaultprefs
  22.     if defaults is None:
  23.         defaults = { }
  24.     
  25.     _prefs = prefs
  26.     _defaultprefs = defaults
  27.  
  28.  
  29. def pref(pref, default = sentinel, type = sentinel):
  30.     if default is sentinel:
  31.         default = _defaultprefs.get(pref, default)
  32.     
  33.     if default is sentinel:
  34.         val = _prefs[pref]
  35.     else:
  36.         val = _prefs.get(pref, default)
  37.     if type is sentinel or val.__class__ is type:
  38.         return val
  39.     if type in castables:
  40.         
  41.         try:
  42.             val = type(val)
  43.         except ValueError:
  44.             val.__class__ is type
  45.             val.__class__ is type
  46.             if default is sentinel:
  47.                 raise TypeError('pref val was incorrect type: %r' % val)
  48.             default is sentinel
  49.             return default
  50.         except:
  51.             val.__class__ is type
  52.  
  53.         return val
  54.     type in castables
  55.     if not isinstance(val, type):
  56.         if default is sentinel:
  57.             raise TypeError('pref val was incorrect type: %r' % val)
  58.         default is sentinel
  59.         return default
  60.     isinstance(val, type)
  61.     return val
  62.  
  63.  
  64. class prefprop(object):
  65.     __slots__ = ('pref', 'default', 'type')
  66.     
  67.     def __init__(self, pref, default = sentinel, type = sentinel):
  68.         self.pref = pref
  69.         self.default = default
  70.         self.type = type
  71.  
  72.     
  73.     def __repr__(self):
  74.         
  75.         try:
  76.             msg = repr(self.pref)
  77.             if self.default is not sentinel:
  78.                 msg += ', default=%r' % self.default
  79.             
  80.             if self.type is not sentinel:
  81.                 msg += ', type=%r' % self.type
  82.         except Exception:
  83.             msg = '???'
  84.  
  85.         return '<prefprop %s>' % msg
  86.  
  87.     
  88.     def __get__(self, obj, objtype = None):
  89.         
  90.         try:
  91.             return profile.prefs[self.pref]
  92.         except KeyError:
  93.             if self.default is sentinel:
  94.                 raise 
  95.             self.default is sentinel
  96.             return self.default
  97.  
  98.  
  99.  
  100.  
  101. def netcall(callable, callback = None):
  102.     call_later = call_later
  103.     import AsyncoreThread
  104.     call_later(callable, callback = callback)
  105.  
  106. netcall = callsback(netcall)
  107.  
  108. class _profile_proxy(object):
  109.     
  110.     def __getattr__(self, attr):
  111.         import digsbyprofile
  112.         globals()['digsbyprofile'] = digsbyprofile
  113.         object.__setattr__(self, '__getattr__', (lambda attr, dp = digsbyprofile: getattr(dp.profile, attr)))
  114.         return getattr(digsbyprofile.profile, attr)
  115.  
  116.     
  117.     def __setattr__(self, key, val):
  118.         raise NotImplementedError()
  119.  
  120.     
  121.     def __call__(self):
  122.         profile = profile
  123.         import digsbyprofile
  124.         return profile
  125.  
  126.     
  127.     def __nonzero__(self):
  128.         profile = profile
  129.         import digsbyprofile
  130.         return profile is not None
  131.  
  132.  
  133. profile = _profile_proxy()
  134.  
  135. def setpref(pref, val):
  136.     profile = profile
  137.     import digsbyprofile
  138.     prefs = getattr(profile, 'prefs', { })
  139.     prefs[pref] = val
  140.  
  141.  
  142. def setprefif(pref, val):
  143.     profile = profile
  144.     import digsbyprofile
  145.     prefs = getattr(profile, 'prefs', { })
  146.     if prefs.get(pref, sentinel) != val:
  147.         setpref(pref, val)
  148.         return True
  149.     return False
  150.  
  151.  
  152. def delpref(pref):
  153.     profile = profile
  154.     import digsbyprofile
  155.     prefs = getattr(profile, 'prefs', { })
  156.     prefs.pop(pref, None)
  157.  
  158.  
  159. def silence_notifications(connection, duration = None):
  160.     info('Silencing notifications from %r', connection)
  161.     connection._notifyquiet = True
  162.     
  163.     def afterTimeout():
  164.         connection._notifyquiet = False
  165.         info('Unsilencing notifications from %r', connection)
  166.  
  167.     if duration is None:
  168.         duration = pref('notifications.quiet_time', 5)
  169.     
  170.     timer = Timer(duration, afterTimeout)
  171.     timer.start()
  172.     return timer
  173.  
  174. from inspect import getargspec
  175.  
  176. def bind(actionname):
  177.     
  178.     def wrap(func):
  179.         args = getargspec(func)[0]
  180.         if len(args) == 1 and args[0] == 'self':
  181.             
  182.             def cb(win, func = func):
  183.                 return func(win)
  184.  
  185.         else:
  186.             
  187.             def cb(win, func = func):
  188.                 return func()
  189.  
  190.         add_action_callback = add_action_callback
  191.         import gui.input
  192.         add_action_callback(actionname, cb)
  193.         return func
  194.  
  195.     return wrap
  196.  
  197. from hashacct import HashedAccount
  198. from Protocol import Protocol as protocol
  199. from Protocol import StateMixin
  200. from AsyncSocket import AsyncSocket as socket
  201. from Buddy import Buddy as buddy
  202. from Buddy import write_hashes, get_bname
  203. from Conversation import Conversation
  204. from actions import ActionMeta, action, Action, ActionError
  205. from timeoutsocket import TimeoutSocket, TimeoutSocketOne
  206. from hydrasocket import HydraSocket
  207. from filetransfer import FileTransfer, OutgoingFileTransfer, IncomingFileTransfer, IncomingHTTPFileTransfer
  208. from accountbase import AccountBase, FromNetMixin
  209. from statusmessage import StatusMessage, StatusMessageException, acct_reduce
  210. from UpdateMixin import UpdateMixin
  211. from notifications import fire
  212. import commandline
  213.  
  214. try:
  215.     from contacts.Contact import ContactCapabilities as caps
  216. except ImportError:
  217.     pass
  218.  
  219.