home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import cPickle
- from util.observe import Observable
- from common import HashedAccount
- from common.actions import ActionMeta, action
- from common import profile
- from util import dictdiff
-
- class AccountBase(Observable, HashedAccount):
- max_error_tolerance = 3
- __metaclass__ = ActionMeta
- _ids = []
-
- def next_id(cls):
- i = len(cls._ids) - 1
- for i, j in enumerate(sorted(set(cls._ids))):
- if i != j:
- break
- continue
- else:
- i += 1
- cls._ids.insert(i, i)
- return i
-
- next_id = classmethod(next_id)
-
- def __init__(self, name, password, **options):
- Observable.__init__(self)
- self.name = name
- self.password = password
- self.id = None if 'id' in options else self.next_id()
- self.alias = options.pop('alias', None)
- self.error_count = 0
-
-
- def popupids(self):
- return set((self,))
-
- popupids = property(popupids)
-
- def rename_gui(self):
- GetTextFromUser = GetTextFromUser
- import gui.toolbox
- localalias = self.alias
- if localalias is None:
- localalias = ''
-
- s = GetTextFromUser(_('Enter an alias for %s:' % self.name), caption = _('Rename %s' % self.name), default_value = localalias, limit = 32)
- if s is not None:
- if s == '' or s.strip():
- None(self.rename if s else None)
- return s
-
-
- rename_gui = action()(rename_gui)
- alias = None
-
- def rename(self, newalias):
- oldalias = self.alias
- self.alias = newalias
- self.notify('alias', oldalias, newalias)
- profile.update_account(self)
-
-
- def username(self):
- return self.name
-
- username = property(username)
-
- def protocol_class(self):
- proto_init = proto_init
- import common.protocolmeta
- return proto_init(self.protocol)
-
-
- def _repr(self):
- return '<%s %r (%s) %s, %r>' % (self.__class__.__name__, self.name, getattr(self, 'protocol', None), getattr(self, 'state', None), getattr(self, 'offline_reason', None))
-
- _repr = staticmethod(_repr)
-
- def __repr__(self):
- return self._repr(self)
-
-
- def default(self, key):
- defaults = self.protocol_info()['defaults']
- return defaults[key]
-
-
- def get_options(self):
- opts = self._get_options()
- d = self.protocol_info()['defaults']
- return dictdiff(d, opts)
-
-
- def _decryptedpw(self):
- return profile.plain_pw(self.password)
-
-
- def _crypt_set_pw(self, value):
- self.password = profile.crypt_pw(value)
-
-
-
- class FromNetMixin(object):
-
- def __init__(self, *a, **k):
- pass
-
-
- def from_net(cls, info, **extra):
- proto_init = proto_init
- import common.protocolmeta
- Class = proto_init(info.protocol)
- cls._ids.insert(info.id, info.id)
- if not all((lambda .0: for c in .0:
- isinstance(c, str))(extra)):
- pprint = pprint
- import pprint
- pprint(extra)
-
- extra.update(**cPickle.loads(info.data))
- return Class(name = info.username, password = info.password, id = info.id, **extra)
-
- from_net = classmethod(from_net)
-
-
- class SimpleAccountSerializer(object):
-
- def __init__(self, **options):
- for key in self.protocol_info()['defaults'].iterkeys():
-
- try:
- val = options[key]
- except KeyError:
- val = self.default(key)
-
- setattr(self, key, val)
-
-
-
- def update_info(self, **info):
- for item in self.protocol_info()['new_details']:
- info.pop(item['store'], None)
-
- super(SimpleAccountSerializer, self).update_info(**info)
-
-
- def get_options(self):
- opts = super(SimpleAccountSerializer, self).get_options()
- for k in self.protocol_info()['defaults'].iterkeys():
- v = getattr(self, k)
- if v != self.default(k):
- opts[k] = v
- continue
-
- return opts
-
-
-