home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / common / __init__.pyo (.txt) next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  6.8 KB  |  209 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 delpref(pref):
  143.     profile = profile
  144.     import digsbyprofile
  145.     prefs = getattr(profile, 'prefs', { })
  146.     prefs.pop(pref, None)
  147.  
  148.  
  149. def silence_notifications(connection, duration = None):
  150.     info('Silencing notifications from %r', connection)
  151.     connection._notifyquiet = True
  152.     
  153.     def afterTimeout():
  154.         connection._notifyquiet = False
  155.         info('Unsilencing notifications from %r', connection)
  156.  
  157.     if duration is None:
  158.         duration = pref('notifications.quiet_time', 5)
  159.     
  160.     timer = Timer(duration, afterTimeout)
  161.     timer.start()
  162.     return timer
  163.  
  164. from inspect import getargspec
  165.  
  166. def bind(actionname):
  167.     
  168.     def wrap(func):
  169.         args = getargspec(func)[0]
  170.         if len(args) == 1 and args[0] == 'self':
  171.             
  172.             def cb(win, func = func):
  173.                 return func(win)
  174.  
  175.         else:
  176.             
  177.             def cb(win, func = func):
  178.                 return func()
  179.  
  180.         add_action_callback = add_action_callback
  181.         import gui.input
  182.         add_action_callback(actionname, cb)
  183.         return func
  184.  
  185.     return wrap
  186.  
  187. from hashacct import HashedAccount
  188. from Protocol import Protocol as protocol
  189. from Protocol import StateMixin
  190. from AsyncSocket import AsyncSocket as socket
  191. from Buddy import Buddy as buddy
  192. from Buddy import write_hashes, get_bname
  193. from Conversation import Conversation
  194. from actions import ActionMeta, action, Action, ActionError
  195. from timeoutsocket import TimeoutSocket, TimeoutSocketOne
  196. from hydrasocket import HydraSocket
  197. from filetransfer import FileTransfer, OutgoingFileTransfer, IncomingFileTransfer, IncomingHTTPFileTransfer
  198. from accountbase import AccountBase, FromNetMixin
  199. from statusmessage import StatusMessage, StatusMessageException, acct_reduce
  200. from UpdateMixin import UpdateMixin
  201. from notifications import fire
  202. import commandline
  203.  
  204. try:
  205.     from contacts.Contact import ContactCapabilities as caps
  206. except ImportError:
  207.     pass
  208.  
  209.