home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.6)
-
- import logging
- import util
- import util.primitives.error_handling as EH
- import lxml.etree as etree
- import common
- import operator
- import traceback
- log = logging.getLogger('linkedin.objects')
- PRIVATE = 'private'
-
- class PrivacyException(Exception):
- pass
-
-
- def _populate(cls, attrgetters, o):
- vals = { }
- pyattrs = cls.py_attrs
- etattrs = cls.etree_attrs
- for attr, etattr, getter in zip(pyattrs, etattrs, attrgetters):
- k = attr
-
- try:
- child = getter(o)
- except AttributeError:
- v = None
-
- if getattr(child, 'pyval', None) is None:
- v = child
- else:
- v = child.pyval
- vals[k] = v
-
-
- try:
- return cls(**vals)
- except Exception:
- e = None
- log.error('Error populating %r: %r: %r', cls.__name__, e, etree.tostring(o, pretty_print = True))
-
-
-
- class LinkedInObject(object):
- etree_attrs = ()
- py_attrs = ()
-
- def __init__(self, **kw):
- self.__dict__.update(kw)
-
-
- def get_attr_getters(cls):
- ags = None
- if ags is None:
- ags = cls.etree_attrgetters = map(operator.attrgetter, cls.etree_attrs)
-
- return ags
-
- get_attr_getters = classmethod(get_attr_getters)
-
- def from_etree(cls, o):
- attrgetters = cls.get_attr_getters()
- x = _populate(cls, attrgetters, o)
- if x is not None:
- x.orig = o
-
- return x
-
- from_etree = classmethod(from_etree)
-
-
- class LinkedInFriend(LinkedInObject):
- etree_attrs = ('id', 'first-name', 'last-name', 'headline', 'location.name', 'location.country.code', 'industry', 'site-standard-profile-request.url', 'picture-url', 'current-status')
- py_attrs = ('id', 'first_name', 'last_name', 'headline', 'location_name', 'location_country', 'industry', 'profile_url', 'picture_url', 'status')
-
- def __init__(self, **k):
- LinkedInObject.__init__(self, **k)
- if self.id == PRIVATE:
- raise PrivacyException()
- self.id == PRIVATE
- self.status = unicode(self.status)
-
-
- def name(self):
- if self.first_name and self.last_name:
- return u'%s %s' % (self.first_name, self.last_name)
- if bool(self.first_name) ^ bool(self.last_name):
- if not self.first_name:
- pass
- return self.last_name
- return u'Unknown User'
-
- name = property(name)
-
- def __repr__(self):
- return '<%s id=%r name=%r>' % (type(self).__name__, getattr(self, 'id', None), self.name)
-
-
-
- class LinkedInGroup(LinkedInObject):
- etree_attrs = LinkedInObject.etree_attrs + ('id', 'name', 'site-group-request.url')
- py_attrs = LinkedInObject.py_attrs + ('id', 'name', 'url')
-
-
- class LinkedInComment(LinkedInObject):
- LIKE = _(u'Like! (via http://digsby.com)')
- DISLIKE = _(u'Dislike! (via http://digsby.com)')
- etree_attrs = ('sequence-number', 'comment', 'person')
- py_attrs = ('sequence_number', 'text', 'person')
-
- def __init__(self, **kw):
- LinkedInObject.__init__(self, **kw)
- if not isinstance(self.person, LinkedInObject):
- self.person = LinkedInFriend.from_etree(self.person)
-
- if self.person is None:
- raise PrivacyException()
- self.person is None
-
-
- def is_like(self):
- if self.text == self.LIKE:
- pass
- return common.pref('linkedin.like_enabled', type = bool, default = True)
-
- is_like = property(is_like)
-
- def is_dislike(self):
- if self.text == self.DISLIKE:
- pass
- return common.pref('linkedin.dislike_enabled', type = bool, default = True)
-
- is_dislike = property(is_dislike)
-
- def userid(self):
- return self.person.id
-
- userid = property(userid)
-
-
- class LinkedInNetworkUpdate(LinkedInObject):
- _subclasses = { }
- etree_attrs = ('timestamp', 'update-type', 'update-key', 'update-content.person', 'is-commentable', 'update-comments')
- py_attrs = ('timestamp', 'type', 'update_key', 'person', 'supports_comments', 'comments')
-
- def __init__(self, **kw):
- LinkedInObject.__init__(self, **kw)
- self.timestamp /= 1000
- self.person = LinkedInFriend.from_etree(self.person)
- if self.person is None:
- raise PrivacyException()
- self.person is None
- self.load_comments(self.comments)
-
-
- def load_comments(self, comments_element):
- if comments_element is not None:
-
- try:
- self.num_comments = int(comments_element.attrib['total'])
- except Exception:
- e = None
- self.num_comments = 0
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
- comment_list = getattr(comments_element, 'update-comment', [])
- comments = []
- for c in comment_list:
-
- try:
- comment = LinkedInComment.from_etree(c)
- except Exception:
- e = None
- import traceback
- traceback.print_exc()
- continue
-
- if comment is not None:
- comments.append(comment)
- continue
-
- self.comments = comments
-
-
- def from_etree(cls, o):
- cls = cls._subclasses.get(getattr(o, 'update-type').pyval, cls)
- attrgetters = cls.get_attr_getters()
- x = _populate(cls, attrgetters, o)
- if x is not None:
- x.orig = o
-
- return x
-
- from_etree = classmethod(from_etree)
-
- def id(self):
- update_key = getattr(self, 'update_key', None)
- if update_key is not None:
- return update_key
- return '%s-%s-%s' % (self.type, self.timestamp, self.person.id)
-
- id = property(id)
-
- def register_update_type(cls, name):
-
- def wrapper(c):
- cls._subclasses[name] = c
- return c
-
- return wrapper
-
- register_update_type = classmethod(register_update_type)
-
- def user_likes(self, userid):
- if not self.comments:
- return False
- for comment in self.comments:
- if comment.is_like and comment.userid == userid:
- return True
-
- return False
-
-
- def user_dislikes(self, userid):
- if not self.comments:
- return False
- for comment in self.comments:
- if comment.is_dislike and comment.userid == userid:
- return True
-
- return False
-
-
- def get_likers(self):
- return _[1]
-
-
- def get_dislikers(self):
- return _[1]
-
-
- def get_comments(self):
- return _[1]
-
-
- LINU_Answ = LinkedInNetworkUpdate.register_update_type('ANSW')(<NODE:12>)
-
- class LINU_App(LinkedInNetworkUpdate):
- etree_attrs = LinkedInNetworkUpdate.etree_attrs + ('update-content.person.person-activities.activity.body',)
- py_attrs = LinkedInNetworkUpdate.py_attrs + ('body',)
-
- LINU_Appm = LinkedInNetworkUpdate.register_update_type('APPS')(LinkedInNetworkUpdate.register_update_type('APPM')(<NODE:12>))
- LINU_Conn = LinkedInNetworkUpdate.register_update_type('CONN')(<NODE:12>)
- LINU_Ncon = LinkedInNetworkUpdate.register_update_type('NCON')(<NODE:12>)
- LINU_Ccem = LinkedInNetworkUpdate.register_update_type('CCEM')(<NODE:12>)
- LINU_Jobs = LinkedInNetworkUpdate.register_update_type('JOBS')(<NODE:12>)
- LINU_Jobp = LinkedInNetworkUpdate.register_update_type('JOBP')(<NODE:12>)
- LINU_Jgrp = LinkedInNetworkUpdate.register_update_type('JGRP')(<NODE:12>)
- LINU_Pict = LinkedInNetworkUpdate.register_update_type('PICT')(<NODE:12>)
- LINU_Picu = LinkedInNetworkUpdate.register_update_type('PICU')(<NODE:12>)
- LINU_Recu = LinkedInNetworkUpdate.register_update_type('RECU')(<NODE:12>)
- LINU_Prec = LinkedInNetworkUpdate.register_update_type('PREC')(LinkedInNetworkUpdate.register_update_type('SVPR')(<NODE:12>))
- LINU_Prfu = LinkedInNetworkUpdate.register_update_type('PROF')(LinkedInNetworkUpdate.register_update_type('PRFU')(<NODE:12>))
- LINU_Qstn = LinkedInNetworkUpdate.register_update_type('QSTN')(<NODE:12>)
- LINU_Stat = LinkedInNetworkUpdate.register_update_type('STAT')(<NODE:12>)
-