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