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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from util.primitives import dictdiff
  5. import cPickle
  6. from traceback import print_exc
  7. from base64 import b64encode
  8.  
  9. def uname_str(name):
  10.     if isinstance(name, unicode):
  11.         return name.encode('utf8')
  12.     return str(name)
  13.  
  14.  
  15. def password_str(password):
  16.     password = str(password)
  17.     return b64encode(password)
  18.  
  19.  
  20. class HashedAccount(object):
  21.     
  22.     def min_hash(self):
  23.         return ''.join((lambda .0: for c in .0:
  24. str(c))([
  25.             self.id,
  26.             self.protocol,
  27.             uname_str(self.username)]))
  28.  
  29.     
  30.     def total_hash(self):
  31.         if not hasattr(self, 'xml_element_name'):
  32.             data = self.get_options()
  33.         else:
  34.             
  35.             try:
  36.                 if self.data is not None:
  37.                     data = cPickle.loads(self.data)
  38.                     
  39.                     try:
  40.                         d = self.protocol_info()['defaults']
  41.                     except KeyError:
  42.                         d = { }
  43.  
  44.                     data = dictdiff(d, data)
  45.                     import common.protocolmeta as pm
  46.                     if self.protocol in pm.improtocols.keys():
  47.                         for k in data.keys():
  48.                             if k not in d:
  49.                                 data.pop(k)
  50.                                 continue
  51.                         
  52.                     else:
  53.                         
  54.                         try:
  55.                             opts = self.protocol_info()['whitelist_opts']
  56.                         except KeyError:
  57.                             opts = ()
  58.  
  59.                         for k in data.keys():
  60.                             if k not in opts:
  61.                                 data.pop(k)
  62.                                 continue
  63.                         
  64.                 else:
  65.                     data = None
  66.             except Exception:
  67.                 print 'data was: %r' % self.data
  68.                 print_exc()
  69.                 data = None
  70.  
  71.         result = (''.join((lambda .0: for c in .0:
  72. str(c))([
  73.             self.id,
  74.             self.protocol,
  75.             uname_str(self.username),
  76.             password_str(self.password)])), data)
  77.         return result
  78.  
  79.     
  80.     def protocol_info(self, proto = sentinel):
  81.         protocols = protocols
  82.         import common.protocolmeta
  83.         return None[protocols if proto is not sentinel else self.protocol]
  84.  
  85.     
  86.     def _total_hash(self):
  87.         return getattr(self, '_total_hash_', None)
  88.  
  89.     _total_hash = property(_total_hash)
  90.     
  91.     def store_hash(self, hash = sentinel):
  92.         self._total_hash_ = None if hash is not sentinel else self.total_hash()
  93.  
  94.  
  95.  
  96. class HashedAccounts(object):
  97.     
  98.     def calc_hash(self):
  99.         if not hasattr(self, 'xml_element_name'):
  100.             return sorted((lambda .0: for a in .0:
  101. a._total_hash)(self))
  102.         return dict((lambda .0: for a in .0:
  103. (a.id, a.total_hash()))(self))
  104.  
  105.  
  106.