home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / common / accountbase.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  5.8 KB  |  162 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import cPickle
  5. from util.observe import Observable
  6. from common import HashedAccount
  7. from common.actions import ActionMeta, action
  8. from common import profile
  9. from util import dictdiff
  10.  
  11. class AccountBase(Observable, HashedAccount):
  12.     max_error_tolerance = 3
  13.     __metaclass__ = ActionMeta
  14.     _ids = []
  15.     
  16.     def next_id(cls):
  17.         i = len(cls._ids) - 1
  18.         for i, j in enumerate(sorted(set(cls._ids))):
  19.             if i != j:
  20.                 break
  21.                 continue
  22.         else:
  23.             i += 1
  24.         cls._ids.insert(i, i)
  25.         return i
  26.  
  27.     next_id = classmethod(next_id)
  28.     
  29.     def __init__(self, name, password, **options):
  30.         Observable.__init__(self)
  31.         self.name = name
  32.         self.password = password
  33.         self.id = None if 'id' in options else self.next_id()
  34.         self.alias = options.pop('alias', None)
  35.         self.error_count = 0
  36.  
  37.     
  38.     def popupids(self):
  39.         return set((self,))
  40.  
  41.     popupids = property(popupids)
  42.     
  43.     def rename_gui(self):
  44.         GetTextFromUser = GetTextFromUser
  45.         import gui.toolbox
  46.         localalias = self.alias
  47.         if localalias is None:
  48.             localalias = ''
  49.         
  50.         s = GetTextFromUser(_('Enter an alias for %s:' % self.name), caption = _('Rename %s' % self.name), default_value = localalias, limit = 32)
  51.         if s is not None:
  52.             if s == '' or s.strip():
  53.                 None(self.rename if s else None)
  54.                 return s
  55.         
  56.  
  57.     rename_gui = action()(rename_gui)
  58.     alias = None
  59.     
  60.     def rename(self, newalias):
  61.         oldalias = self.alias
  62.         self.alias = newalias
  63.         self.notify('alias', oldalias, newalias)
  64.         profile.update_account(self)
  65.  
  66.     
  67.     def username(self):
  68.         return self.name
  69.  
  70.     username = property(username)
  71.     
  72.     def protocol_class(self):
  73.         proto_init = proto_init
  74.         import common.protocolmeta
  75.         return proto_init(self.protocol)
  76.  
  77.     
  78.     def _repr(self):
  79.         return '<%s %r (%s) %s, %r>' % (self.__class__.__name__, self.name, getattr(self, 'protocol', None), getattr(self, 'state', None), getattr(self, 'offline_reason', None))
  80.  
  81.     _repr = staticmethod(_repr)
  82.     
  83.     def __repr__(self):
  84.         return self._repr(self)
  85.  
  86.     
  87.     def default(self, key):
  88.         defaults = self.protocol_info()['defaults']
  89.         return defaults[key]
  90.  
  91.     
  92.     def get_options(self):
  93.         opts = self._get_options()
  94.         d = self.protocol_info()['defaults']
  95.         return dictdiff(d, opts)
  96.  
  97.     
  98.     def _decryptedpw(self):
  99.         return profile.plain_pw(self.password)
  100.  
  101.     
  102.     def _crypt_set_pw(self, value):
  103.         self.password = profile.crypt_pw(value)
  104.  
  105.  
  106.  
  107. class FromNetMixin(object):
  108.     
  109.     def __init__(self, *a, **k):
  110.         pass
  111.  
  112.     
  113.     def from_net(cls, info, **extra):
  114.         proto_init = proto_init
  115.         import common.protocolmeta
  116.         Class = proto_init(info.protocol)
  117.         cls._ids.insert(info.id, info.id)
  118.         if not all((lambda .0: for c in .0:
  119. isinstance(c, str))(extra)):
  120.             pprint = pprint
  121.             import pprint
  122.             pprint(extra)
  123.         
  124.         extra.update(**cPickle.loads(info.data))
  125.         return Class(name = info.username, password = info.password, id = info.id, **extra)
  126.  
  127.     from_net = classmethod(from_net)
  128.  
  129.  
  130. class SimpleAccountSerializer(object):
  131.     
  132.     def __init__(self, **options):
  133.         for key in self.protocol_info()['defaults'].iterkeys():
  134.             
  135.             try:
  136.                 val = options[key]
  137.             except KeyError:
  138.                 val = self.default(key)
  139.  
  140.             setattr(self, key, val)
  141.         
  142.  
  143.     
  144.     def update_info(self, **info):
  145.         for item in self.protocol_info()['new_details']:
  146.             info.pop(item['store'], None)
  147.         
  148.         super(SimpleAccountSerializer, self).update_info(**info)
  149.  
  150.     
  151.     def get_options(self):
  152.         opts = super(SimpleAccountSerializer, self).get_options()
  153.         for k in self.protocol_info()['defaults'].iterkeys():
  154.             v = getattr(self, k)
  155.             if v != self.default(k):
  156.                 opts[k] = v
  157.                 continue
  158.         
  159.         return opts
  160.  
  161.  
  162.