home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / common / __init__.pyo (.txt) next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  6.5 KB  |  195 lines

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