home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / jabber / objects / shared_status / status.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  5.7 KB  |  122 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. from jabber.objects.shared_status import SHARED_STATUS_NS
  5. from pyxmpp.objects import StanzaPayloadObject
  6. from pyxmpp.iq import Iq
  7. import jabber
  8. import libxml2
  9. import util
  10. from util.primitives.error_handling import try_this as try_
  11.  
  12. class StatusList(StanzaPayloadObject, list):
  13.     show = None
  14.     xml_element_name = 'status-list'
  15.     xml_element_namespace = SHARED_STATUS_NS
  16.     
  17.     def __init__(self, xmlnode_or_sequence, show = None):
  18.         list.__init__(self)
  19.         if isinstance(xmlnode_or_sequence, libxml2.xmlNode):
  20.             self._StatusList__from_xml(xmlnode_or_sequence)
  21.         elif show:
  22.             self.show = show
  23.         
  24.         self[:] = xmlnode_or_sequence
  25.  
  26.     
  27.     def complete_xml_element(self, xmlnode, doc):
  28.         if self.show is not None:
  29.             xmlnode.setProp('show', self.show.encode('utf-8'))
  30.         
  31.         for status in self:
  32.             xmlnode.newTextChild(None, 'status', status.encode('utf-8'))
  33.         
  34.  
  35.     
  36.     def __from_xml(self, xmlnode, *a, **k):
  37.         show_l = jabber.jabber_util.xpath_eval(xmlnode, '@show', namespaces = {
  38.             'gss': SHARED_STATUS_NS })
  39.         if show_l:
  40.             show = show_l[0]
  41.             self.show = show.getContent().decode('utf-8')
  42.         
  43.         self[:] = (lambda .0: for node in .0:
  44. node.getContent().decode('utf-8'))(jabber.jabber_util.xpath_eval(xmlnode, 'gss:status/text()', namespaces = {
  45.             'gss': SHARED_STATUS_NS }))
  46.  
  47.  
  48.  
  49. class SharedStatus(StanzaPayloadObject, util.primitives.mapping.odict):
  50.     xml_element_name = 'query'
  51.     xml_element_namespace = SHARED_STATUS_NS
  52.     version = 2
  53.     status_max = None
  54.     status_list_max = None
  55.     status_list_contents_max = None
  56.     status_min_ver = None
  57.     invisible = None
  58.     
  59.     def __init__(self, xmlnode):
  60.         util.primitives.mapping.odict.__init__(self)
  61.         if isinstance(xmlnode, libxml2.xmlNode):
  62.             self._SharedStatus__from_xml(xmlnode)
  63.         
  64.  
  65.     
  66.     def __from_xml(self, xmlnode, *a, **k):
  67.         sls = [ StatusList(node) for node in jabber.jabber_util.xpath_eval(xmlnode, 'gss:query/gss:status-list[@show]', namespaces = {
  68.             'gss': SHARED_STATUS_NS }) ]
  69.         self.update((lambda .0: for l in .0:
  70. (l.show, l))(sls))
  71.         status = jabber.jabber_util.xpath_eval(xmlnode, 'gss:query/gss:status/text()', namespaces = {
  72.             'gss': SHARED_STATUS_NS })
  73.         show = jabber.jabber_util.xpath_eval(xmlnode, 'gss:query/gss:show/text()', namespaces = {
  74.             'gss': SHARED_STATUS_NS })
  75.         self.status = [] if status else None
  76.         self.show = [] if show else None
  77.         query_l = jabber.jabber_util.xpath_eval(xmlnode, 'gss:query', namespaces = {
  78.             'gss': SHARED_STATUS_NS })
  79.         query = None if query_l else None
  80.         if query is not None:
  81.             self.status_max = (try_,)((lambda : int(query.prop('status-max'))), None)
  82.             self.status_list_max = (try_,)((lambda : int(query.prop('status-list-max'))), None)
  83.             self.status_list_contents_max = (try_,)((lambda : int(query.prop('status-list-contents-max'))), None)
  84.             self.status_min_ver = (try_,)((lambda : int(query.prop('status-min-ver'))), None)
  85.         
  86.         invis = jabber.jabber_util.xpath_eval(xmlnode, 'gss:query/gss:invisible/@value', namespaces = {
  87.             'gss': SHARED_STATUS_NS })
  88.         self.node = xmlnode
  89.         self.invisible = None if invis else None
  90.  
  91.     
  92.     def complete_xml_element(self, xmlnode, doc):
  93.         xmlnode.setProp('version', unicode(self.version).encode('utf-8'))
  94.         if self.status is not None:
  95.             if not self.status_max:
  96.                 pass
  97.             xmlnode.newTextChild(None, 'status', self.status[:None].encode('utf-8'))
  98.         
  99.         if self.show is not None:
  100.             xmlnode.newTextChild(None, 'show', self.show.encode('utf-8'))
  101.         else:
  102.             xmlnode.newTextChild(None, 'show', u'default'.encode('utf-8'))
  103.         for status_list in self.values():
  104.             status_list.as_xml(xmlnode, doc)
  105.         
  106.         for attr in ('status-max', 'status-list-max', 'status-list-contents-max', 'status-min-ver'):
  107.             val = getattr(self, attr.replace('-', '_'), None)
  108.             if val is not None:
  109.                 xmlnode.setProp(attr, str(val))
  110.                 continue
  111.         
  112.         invis = xmlnode.newChild(None, 'invisible', None)
  113.         invis.setProp('value', str(bool(self.invisible)).lower())
  114.  
  115.     
  116.     def make_push(self, gtalk_protocol):
  117.         iq = Iq(stanza_type = 'set')
  118.         self.as_xml(parent = iq.xmlnode)
  119.         return iq
  120.  
  121.  
  122.