Exemplo n.º 1
0
    def __init__(self,xmlnode_or_node=None):
        """Initialize an `DiscoItems` object.

        Wrap an existing disco#items XML element or create a new one.

        :Parameters:
            - `xmlnode_or_node`: XML node to be wrapped into `self` or an item
              node name.
        :Types:
            - `xmlnode_or_node`: `libxml2.xmlNode` or `unicode`"""
        self.xmlnode=None
        self.xpath_ctxt=None
        if isinstance(xmlnode_or_node,libxml2.xmlNode):
            ns=xmlnode_or_node.ns()
            if ns.getContent() != DISCO_ITEMS_NS:
                raise ValueError, "Bad disco-items namespace"
            self.xmlnode=xmlnode_or_node.docCopyNode(common_doc,1)
            common_root.addChild(self.xmlnode)
            self.ns=self.xmlnode.ns()
        else:
            self.xmlnode=common_root.newChild(None,"query",None)
            self.ns=self.xmlnode.newNs(DISCO_ITEMS_NS,None)
            self.xmlnode.setNs(self.ns)
            self.set_node(xmlnode_or_node)
        self.xpath_ctxt=common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d",DISCO_ITEMS_NS)
Exemplo n.º 2
0
    def __init__(self, xmlnode_or_node=None):
        """Initialize an `DiscoItems` object.

        Wrap an existing disco#items XML element or create a new one.

        :Parameters:
            - `xmlnode_or_node`: XML node to be wrapped into `self` or an item
              node name.
        :Types:
            - `xmlnode_or_node`: `libxml2.xmlNode` or `unicode`"""
        self.xmlnode = None
        self.xpath_ctxt = None
        if isinstance(xmlnode_or_node, libxml2.xmlNode):
            ns = xmlnode_or_node.ns()
            if ns.getContent() != DISCO_ITEMS_NS:
                raise ValueError, "Bad disco-items namespace"
            self.xmlnode = xmlnode_or_node.docCopyNode(common_doc, 1)
            common_root.addChild(self.xmlnode)
            self.ns = self.xmlnode.ns()
        else:
            self.xmlnode = common_root.newChild(None, "query", None)
            self.ns = self.xmlnode.newNs(DISCO_ITEMS_NS, None)
            self.xmlnode.setNs(self.ns)
            self.set_node(xmlnode_or_node)
        self.xpath_ctxt = common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d", DISCO_ITEMS_NS)
Exemplo n.º 3
0
 def remove(self):
     """Remove `self` from the containing `DiscoInfo` object."""
     if self.disco is None:
         return
     self.xmlnode.unlinkNode()
     oldns=self.xmlnode.ns()
     ns=self.xmlnode.newNs(oldns.getContent(),None)
     self.xmlnode.replaceNs(oldns,ns)
     common_root.addChild(self.xmlnode())
     self.disco=None
Exemplo n.º 4
0
 def remove(self):
     """Remove `self` from the containing `DiscoInfo` object."""
     if self.disco is None:
         return
     self.xmlnode.unlinkNode()
     oldns = self.xmlnode.ns()
     ns = self.xmlnode.newNs(oldns.getContent(), None)
     self.xmlnode.replaceNs(oldns, ns)
     common_root.addChild(self.xmlnode())
     self.disco = None
Exemplo n.º 5
0
    def __init__(self, xmlnode=None, copy=True, parent=None):
        """
        Copy MucXBase object or create a new one, possibly
        based on or wrapping an XML node.

        :Parameters:
            - `xmlnode`: is the object to copy or an XML node to wrap.
            - `copy`: when `True` a copy of the XML node provided will be included
              in `self`, the node will be copied otherwise.
            - `parent`: parent node for the created/copied XML element.
        :Types:
            - `xmlnode`: `MucXBase` or `libxml2.xmlNode`
            - `copy`: `bool`
            - `parent`: `libxml2.xmlNode`
        """
        if self.ns==None:
            raise RuntimeError,"Pure virtual class called"
        self.xmlnode=None
        self.borrowed=False
        if isinstance(xmlnode,libxml2.xmlNode):
            if copy:
                self.xmlnode=xmlnode.docCopyNode(common_doc,1)
                common_root.addChild(self.xmlnode)
            else:
                self.xmlnode=xmlnode
                self.borrowed=True
            if copy:
                ns=xmlnode.ns()
                xmlextra.replace_ns(self.xmlnode, ns, common_ns)
        elif isinstance(xmlnode,MucXBase):
            if not copy:
                raise TypeError, "MucXBase may only be copied"
            self.xmlnode=xmlnode.xmlnode.docCopyNode(common_doc,1)
            common_root.addChild(self.xmlnode)
        elif xmlnode is not None:
            raise TypeError, "Bad MucX constructor argument"
        else:
            if parent:
                self.xmlnode=parent.newChild(None,self.element,None)
                self.borrowed=True
            else:
                self.xmlnode=common_root.newChild(None,self.element,None)
            ns=self.xmlnode.newNs(self.ns,None)
            self.xmlnode.setNs(ns)
Exemplo n.º 6
0
    def __init__(self, xmlnode=None, copy=True, parent=None):
        """
        Copy MucXBase object or create a new one, possibly
        based on or wrapping an XML node.

        :Parameters:
            - `xmlnode`: is the object to copy or an XML node to wrap.
            - `copy`: when `True` a copy of the XML node provided will be included
              in `self`, the node will be copied otherwise.
            - `parent`: parent node for the created/copied XML element.
        :Types:
            - `xmlnode`: `MucXBase` or `libxml2.xmlNode`
            - `copy`: `bool`
            - `parent`: `libxml2.xmlNode`
        """
        if self.ns == None:
            raise RuntimeError, "Pure virtual class called"
        self.xmlnode = None
        self.borrowed = False
        if isinstance(xmlnode, libxml2.xmlNode):
            if copy:
                self.xmlnode = xmlnode.docCopyNode(common_doc, 1)
                common_root.addChild(self.xmlnode)
            else:
                self.xmlnode = xmlnode
                self.borrowed = True
            if copy:
                ns = xmlnode.ns()
                xmlextra.replace_ns(self.xmlnode, ns, common_ns)
        elif isinstance(xmlnode, MucXBase):
            if not copy:
                raise TypeError, "MucXBase may only be copied"
            self.xmlnode = xmlnode.xmlnode.docCopyNode(common_doc, 1)
            common_root.addChild(self.xmlnode)
        elif xmlnode is not None:
            raise TypeError, "Bad MucX constructor argument"
        else:
            if parent:
                self.xmlnode = parent.newChild(None, self.element, None)
                self.borrowed = True
            else:
                self.xmlnode = common_root.newChild(None, self.element, None)
            ns = self.xmlnode.newNs(self.ns, None)
            self.xmlnode.setNs(ns)