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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import libxml2
  5. from pyxmpp.objects import StanzaPayloadObject
  6. from pyxmpp.xmlextra import common_doc, get_node_ns_uri
  7. CHATSTATES_NS = 'http://jabber.org/protocol/chatstates'
  8. VALID_CHATSTATES = [
  9.     'active',
  10.     'composing',
  11.     'gone',
  12.     'inactive',
  13.     'paused']
  14.  
  15. class ChatState(StanzaPayloadObject):
  16.     xml_element_namespace = CHATSTATES_NS
  17.     
  18.     def __init__(self, xmlnode_or_type):
  19.         if isinstance(xmlnode_or_type, libxml2.xmlNode):
  20.             self.from_xml(xmlnode_or_type)
  21.         else:
  22.             self.xml_element_name = xmlnode_or_type
  23.  
  24.     
  25.     def valid_state(self):
  26.         return self.xml_element_name in VALID_CHATSTATES
  27.  
  28.     
  29.     def from_xml(self, xmlnode):
  30.         self.xml_element_name = xmlnode.name
  31.         if xmlnode.type != 'element':
  32.             raise ValueError, 'XML node is not a chat state (not en element)'
  33.         xmlnode.type != 'element'
  34.         ns = get_node_ns_uri(xmlnode)
  35.         if ns and ns != self.xml_element_namespace:
  36.             raise ValueError, 'XML node is not a chat state descriptor'
  37.         ns != self.xml_element_namespace
  38.         if not self.valid_state():
  39.             import warnings
  40.             warnings.warn('XML node with name: %r is not a valid chat state' % self.xml_element_name)
  41.         
  42.  
  43.     
  44.     def __str__(self):
  45.         n = self.as_xml(doc = common_doc)
  46.         r = n.serialize()
  47.         n.unlinkNode()
  48.         n.freeNode()
  49.         return r
  50.  
  51.  
  52.