home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / common / hashacct.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.8 KB  |  115 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.                 if self.protocol in ('face', 'facebook'):
  67.                     if 'filters' in data:
  68.                         if 'alerts' in data['filters']:
  69.                             alrts = [
  70.                                 True] * 7
  71.                             alrts[:len(data['filters']['alerts'])] = data['filters']['alerts']
  72.                             data['filters']['alerts'] = alrts
  73.                         
  74.                     
  75.             except Exception:
  76.                 print 'data was: %r' % self.data
  77.                 print_exc()
  78.                 data = None
  79.  
  80.         result = (''.join((lambda .0: for c in .0:
  81. str(c))([
  82.             self.id,
  83.             self.protocol,
  84.             uname_str(self.username),
  85.             password_str(self.password)])), data)
  86.         return result
  87.  
  88.     
  89.     def protocol_info(self, proto = sentinel):
  90.         protocols = protocols
  91.         import common.protocolmeta
  92.         return None[protocols if proto is not sentinel else self.protocol]
  93.  
  94.     
  95.     def _total_hash(self):
  96.         return getattr(self, '_total_hash_', None)
  97.  
  98.     _total_hash = property(_total_hash)
  99.     
  100.     def store_hash(self, hash = sentinel):
  101.         self._total_hash_ = None if hash is not sentinel else self.total_hash()
  102.  
  103.  
  104.  
  105. class HashedAccounts(object):
  106.     
  107.     def calc_hash(self):
  108.         if not hasattr(self, 'xml_element_name'):
  109.             return sorted((lambda .0: for a in .0:
  110. a._total_hash)(self))
  111.         return dict((lambda .0: for a in .0:
  112. (a.id, a.total_hash()))(self))
  113.  
  114.  
  115.