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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import logging
  5. import util
  6. import util.primitives.error_handling as EH
  7. import lxml.etree as etree
  8. import common
  9. import operator
  10. import traceback
  11. log = logging.getLogger('linkedin.objects')
  12.  
  13. def _populate(cls, attrgetters, o):
  14.     vals = { }
  15.     pyattrs = cls.py_attrs
  16.     etattrs = cls.etree_attrs
  17.     for attr, etattr, getter in zip(pyattrs, etattrs, attrgetters):
  18.         k = attr
  19.         
  20.         try:
  21.             child = getter(o)
  22.         except AttributeError:
  23.             v = None
  24.  
  25.         if getattr(child, 'pyval', None) is None:
  26.             v = child
  27.         else:
  28.             v = child.pyval
  29.         vals[k] = v
  30.     
  31.     
  32.     try:
  33.         return cls(**vals)
  34.     except Exception:
  35.         e = None
  36.         traceback.print_exc()
  37.         log.error('Error populating %r: %r', cls.__name__, etree.tostring(o, pretty_print = True))
  38.  
  39.  
  40.  
  41. class LinkedInObject(object):
  42.     etree_attrs = ()
  43.     py_attrs = ()
  44.     
  45.     def __init__(self, **kw):
  46.         self.__dict__.update(kw)
  47.  
  48.     
  49.     def get_attr_getters(cls):
  50.         ags = None
  51.         if ags is None:
  52.             ags = cls.etree_attrgetters = map(operator.attrgetter, cls.etree_attrs)
  53.         
  54.         return ags
  55.  
  56.     get_attr_getters = classmethod(get_attr_getters)
  57.     
  58.     def from_etree(cls, o):
  59.         attrgetters = cls.get_attr_getters()
  60.         x = _populate(cls, attrgetters, o)
  61.         x.orig = o
  62.         return x
  63.  
  64.     from_etree = classmethod(from_etree)
  65.  
  66.  
  67. class LinkedInFriend(LinkedInObject):
  68.     etree_attrs = ('id', 'first-name', 'last-name', 'headline', 'location.name', 'location.country.code', 'industry', 'site-standard-profile-request.url', 'picture-url', 'current-status')
  69.     py_attrs = ('id', 'first_name', 'last_name', 'headline', 'location_name', 'location_country', 'industry', 'profile_url', 'picture_url', 'status')
  70.     
  71.     def __init__(self, **k):
  72.         LinkedInObject.__init__(self, **k)
  73.         self.status = unicode(self.status)
  74.  
  75.     
  76.     def name(self):
  77.         if self.first_name and self.last_name:
  78.             return u'%s %s' % (self.first_name, self.last_name)
  79.         if bool(self.first_name) ^ bool(self.last_name):
  80.             if not self.first_name:
  81.                 pass
  82.             return self.last_name
  83.         return u'Unknown User'
  84.  
  85.     name = property(name)
  86.     
  87.     def __repr__(self):
  88.         return '<%s id=%r name=%r>' % (type(self).__name__, getattr(self, 'id', None), self.name)
  89.  
  90.  
  91.  
  92. class LinkedInGroup(LinkedInObject):
  93.     etree_attrs = LinkedInObject.etree_attrs + ('id', 'name', 'site-group-request.url')
  94.     py_attrs = LinkedInObject.py_attrs + ('id', 'name', 'url')
  95.  
  96.  
  97. class LinkedInComment(LinkedInObject):
  98.     LIKE = _(u'Like! (via http://digsby.com)')
  99.     DISLIKE = _(u'Dislike! (via  http://digsby.com)')
  100.     etree_attrs = ('sequence-number', 'comment', 'person')
  101.     py_attrs = ('sequence_number', 'text', 'person')
  102.     
  103.     def __init__(self, **kw):
  104.         LinkedInObject.__init__(self, **kw)
  105.         if not isinstance(self.person, LinkedInObject):
  106.             self.person = LinkedInFriend.from_etree(self.person)
  107.         
  108.  
  109.     
  110.     def is_like(self):
  111.         if self.text == self.LIKE:
  112.             pass
  113.         return common.pref('linkedin.like_enabled', type = bool, default = True)
  114.  
  115.     is_like = property(is_like)
  116.     
  117.     def is_dislike(self):
  118.         if self.text == self.DISLIKE:
  119.             pass
  120.         return common.pref('linkedin.dislike_enabled', type = bool, default = True)
  121.  
  122.     is_dislike = property(is_dislike)
  123.     
  124.     def userid(self):
  125.         return self.person.id
  126.  
  127.     userid = property(userid)
  128.  
  129.  
  130. class LinkedInNetworkUpdate(LinkedInObject):
  131.     _subclasses = { }
  132.     etree_attrs = ('timestamp', 'update-type', 'update-key', 'update-content.person', 'is-commentable', 'update-comments')
  133.     py_attrs = ('timestamp', 'type', 'update_key', 'person', 'supports_comments', 'comments')
  134.     
  135.     def __init__(self, **kw):
  136.         LinkedInObject.__init__(self, **kw)
  137.         self.timestamp /= 1000
  138.         self.person = LinkedInFriend.from_etree(self.person)
  139.         self.load_comments(self.comments)
  140.  
  141.     
  142.     def load_comments(self, comments_element):
  143.         if comments_element is not None:
  144.             
  145.             try:
  146.                 self.num_comments = int(comments_element.attrib['total'])
  147.             except Exception:
  148.                 e = None
  149.                 self.num_comments = 0
  150.             except:
  151.                 None<EXCEPTION MATCH>Exception
  152.             
  153.  
  154.         None<EXCEPTION MATCH>Exception
  155.         comment_list = getattr(comments_element, 'update-comment', [])
  156.         comments = []
  157.         for c in comment_list:
  158.             
  159.             try:
  160.                 comment = LinkedInComment.from_etree(c)
  161.             except Exception:
  162.                 e = None
  163.                 import traceback
  164.                 traceback.print_exc()
  165.                 continue
  166.  
  167.             comments.append(comment)
  168.         
  169.         self.comments = comments
  170.  
  171.     
  172.     def from_etree(cls, o):
  173.         cls = cls._subclasses.get(getattr(o, 'update-type').pyval, cls)
  174.         attrgetters = cls.get_attr_getters()
  175.         x = _populate(cls, attrgetters, o)
  176.         x.orig = o
  177.         return x
  178.  
  179.     from_etree = classmethod(from_etree)
  180.     
  181.     def id(self):
  182.         update_key = getattr(self, 'update_key', None)
  183.         if update_key is not None:
  184.             return update_key
  185.         return '%s-%s-%s' % (self.type, self.timestamp, self.person.id)
  186.  
  187.     id = property(id)
  188.     
  189.     def register_update_type(cls, name):
  190.         
  191.         def wrapper(c):
  192.             cls._subclasses[name] = c
  193.             return c
  194.  
  195.         return wrapper
  196.  
  197.     register_update_type = classmethod(register_update_type)
  198.     
  199.     def user_likes(self, userid):
  200.         if not self.comments:
  201.             return False
  202.         for comment in self.comments:
  203.             if comment.is_like and comment.userid == userid:
  204.                 return True
  205.         
  206.         return False
  207.  
  208.     
  209.     def user_dislikes(self, userid):
  210.         if not self.comments:
  211.             return False
  212.         for comment in self.comments:
  213.             if comment.is_dislike and comment.userid == userid:
  214.                 return True
  215.         
  216.         return False
  217.  
  218.     
  219.     def get_likers(self):
  220.         return _[1]
  221.  
  222.     
  223.     def get_dislikers(self):
  224.         return _[1]
  225.  
  226.     
  227.     def get_comments(self):
  228.         return _[1]
  229.  
  230.  
  231. LINU_Answ = LinkedInNetworkUpdate.register_update_type('ANSW')(<NODE:12>)
  232.  
  233. class LINU_App(LinkedInNetworkUpdate):
  234.     etree_attrs = LinkedInNetworkUpdate.etree_attrs + ('update-content.person.person-activities.activity.body',)
  235.     py_attrs = LinkedInNetworkUpdate.py_attrs + ('body',)
  236.  
  237. LINU_Appm = LinkedInNetworkUpdate.register_update_type('APPS')(LinkedInNetworkUpdate.register_update_type('APPM')(<NODE:12>))
  238. LINU_Conn = LinkedInNetworkUpdate.register_update_type('CONN')(<NODE:12>)
  239. LINU_Ncon = LinkedInNetworkUpdate.register_update_type('NCON')(<NODE:12>)
  240. LINU_Ccem = LinkedInNetworkUpdate.register_update_type('CCEM')(<NODE:12>)
  241. LINU_Jobs = LinkedInNetworkUpdate.register_update_type('JOBS')(<NODE:12>)
  242. LINU_Jobp = LinkedInNetworkUpdate.register_update_type('JOBP')(<NODE:12>)
  243. LINU_Jgrp = LinkedInNetworkUpdate.register_update_type('JGRP')(<NODE:12>)
  244. LINU_Pict = LinkedInNetworkUpdate.register_update_type('PICT')(<NODE:12>)
  245. LINU_Picu = LinkedInNetworkUpdate.register_update_type('PICU')(<NODE:12>)
  246. LINU_Recu = LinkedInNetworkUpdate.register_update_type('RECU')(<NODE:12>)
  247. LINU_Prec = LinkedInNetworkUpdate.register_update_type('PREC')(LinkedInNetworkUpdate.register_update_type('SVPR')(<NODE:12>))
  248. LINU_Prfu = LinkedInNetworkUpdate.register_update_type('PROF')(LinkedInNetworkUpdate.register_update_type('PRFU')(<NODE:12>))
  249. LINU_Qstn = LinkedInNetworkUpdate.register_update_type('QSTN')(<NODE:12>)
  250. LINU_Stat = LinkedInNetworkUpdate.register_update_type('STAT')(<NODE:12>)
  251.