home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / facebook / fbutil.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  3.0 KB  |  85 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from hashlib import md5
  5. from util.primitives.error_handling import traceguard, try_this
  6. import logging
  7.  
  8. def signature(secret, **kw):
  9.     return md5(''.join((lambda .0: for k, v in .0:
  10. '='.join((str(k), str(v))))(sorted(kw.items()))) + secret).hexdigest()
  11.  
  12.  
  13. def trim_profiles(stream_dict):
  14.     post_profiles = extract_profile_ids(stream_dict)
  15.     trimmed = set()
  16.     for key in stream_dict['profiles']:
  17.         if key not in post_profiles:
  18.             trimmed.add(key)
  19.             continue
  20.     
  21.     profiles_len = len(stream_dict['profiles'])
  22.     for key in trimmed:
  23.         stream_dict['profiles'].pop(key)
  24.     
  25.     if len(trimmed):
  26.         log = logging.getLogger('fbutil').info
  27.     else:
  28.         log = logging.getLogger('fbutil').debug
  29.     log('trimmed %d of %d profiles, %d remain', len(trimmed), profiles_len, len(stream_dict['profiles']))
  30.     log('trimmed %r', trimmed)
  31.     log('profiles %r', stream_dict['profiles'].keys())
  32.  
  33. POST_ID_NAMES = frozenset(('viewer_id', 'actor_id', 'target_id', 'source_id'))
  34. IGNORED = (KeyError, IndexError, TypeError)
  35.  
  36. def extract_profile_ids(stream):
  37.     ret = set()
  38.     for None in stream['posts']:
  39.         post = None
  40.         for None in POST_ID_NAMES:
  41.             key = None
  42.             
  43.             try:
  44.                 (traceguard, traceguard.__exit__, try_this)((lambda : ret.add(post[key])), ignore = IGNORED)
  45.             finally:
  46.                 pass
  47.  
  48.         
  49.         
  50.         try:
  51.             (traceguard.__exit__, try_this)((lambda : ret.update(post['likes']['sample'])), ignore = IGNORED)
  52.         finally:
  53.             pass
  54.  
  55.         traceguard.__enter__()
  56.         
  57.         try:
  58.             (traceguard.__exit__, try_this)((lambda : ret.update(post['likes']['friends'])), ignore = IGNORED)
  59.         finally:
  60.             pass
  61.  
  62.     
  63.     for post_comments in stream['comments'].values():
  64.         for None in post_comments:
  65.             comment = None
  66.             
  67.             try:
  68.                 (traceguard.__exit__, try_this)((lambda : ret.add(comment['fromid'])), ignore = IGNORED)
  69.             finally:
  70.                 pass
  71.  
  72.         
  73.     
  74.     for None in stream.get('notifications', []):
  75.         notification = None
  76.         
  77.         try:
  78.             (traceguard.__exit__, try_this)((lambda : ret.add(notification['sender_id'])), ignore = IGNORED)
  79.         finally:
  80.             pass
  81.  
  82.     
  83.     return ret
  84.  
  85.