home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / pyxmpp / objects.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  2.1 KB  |  88 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. __revision__ = '$Id: objects.py 714 2010-04-05 10:20:10Z jajcus $'
  5. __docformat__ = 'restructuredtext en'
  6. import libxml2
  7. from pyxmpp.xmlextra import common_doc
  8.  
  9. class StanzaPayloadObject(object):
  10.     xml_element_name = None
  11.     xml_element_namespace = None
  12.     
  13.     def as_xml(self, parent = None, doc = None):
  14.         if parent:
  15.             if not doc:
  16.                 n = parent
  17.                 while n:
  18.                     if n.type == 'xml_document':
  19.                         doc = n
  20.                         break
  21.                     
  22.                     n = n.parent
  23.                 if not doc:
  24.                     doc = common_doc
  25.                 
  26.             
  27.             
  28.             try:
  29.                 ns = parent.searchNsByHref(doc, self.xml_element_namespace)
  30.             except libxml2.treeError:
  31.                 ns = None
  32.  
  33.             xmlnode = parent.newChild(ns, self.xml_element_name, None)
  34.             if not ns:
  35.                 ns = xmlnode.newNs(self.xml_element_namespace, None)
  36.                 xmlnode.setNs(ns)
  37.             
  38.             doc1 = doc
  39.         elif doc:
  40.             doc1 = doc
  41.         else:
  42.             doc1 = libxml2.newDoc('1.0')
  43.         xmlnode = doc1.newChild(None, self.xml_element_name, None)
  44.         ns = xmlnode.newNs(self.xml_element_namespace, None)
  45.         xmlnode.setNs(ns)
  46.         self.complete_xml_element(xmlnode, doc1)
  47.         if doc or parent:
  48.             return xmlnode
  49.         doc1.setRootElement(xmlnode)
  50.         return doc1
  51.  
  52.     
  53.     def complete_xml_element(self, xmlnode, doc):
  54.         pass
  55.  
  56.  
  57.  
  58. class StanzaPayloadWrapperObject(object):
  59.     
  60.     def as_xml(self, parent = None, doc = None):
  61.         if parent:
  62.             if not doc:
  63.                 n = parent
  64.                 while n:
  65.                     if n.type == 'xml_document':
  66.                         doc = n
  67.                         break
  68.                     
  69.                     n = n.parent
  70.                 if not doc:
  71.                     doc = common_doc
  72.                 
  73.             
  74.             copy = self.xmlnode.docCopyNode(doc, True)
  75.             parent.addChild(copy)
  76.             return copy
  77.         if not doc:
  78.             doc1 = libxml2.newDoc('1.0')
  79.         else:
  80.             doc1 = doc
  81.         xmlnode = doc1.addChild(self.xmlnode.docCopyNode(doc, True))
  82.         doc1.setRootElement(xmlnode)
  83.         if doc:
  84.             return xmlnode
  85.         return doc1
  86.  
  87.  
  88.