Пример #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)
Пример #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)
Пример #3
0
    def __init__(self,
                 disco,
                 xmlnode_or_name,
                 item_category=None,
                 item_type=None,
                 replace=False):
        """Initialize an `DiscoIdentity` object.

        :Parameters:
            - `disco`: the disco#info reply `self` is a part of.
            - `xmlnode_or_name`: XML element describing the identity or the
              name of the item described.
            - `item_category`: category of the item described.
            - `item_type`: type of the item described.
            - `replace`: if `True` than all other <identity/> elements in
              `disco` will be removed.
        :Types:
            - `disco`: `DiscoItems`
            - `xmlnode_or_name`: `libxml2.xmlNode` or `unicode`
            - `item_category`: `unicode`
            - `item_type`: `unicode`
            - `replace`: `bool`
        """
        self.disco = disco
        if disco and replace:
            old = disco.xpath_ctxt.xpathEval("d:identity")
            if old:
                for n in old:
                    n.unlinkNode()
                    n.freeNode()
        if isinstance(xmlnode_or_name, libxml2.xmlNode):
            if disco is None:
                self.xmlnode = xmlnode_or_name.copyNode(1)
            else:
                self.xmlnode = xmlnode_or_name
        elif not item_category:
            raise ValueError, "DiscoInfo requires category"
        elif not item_type:
            raise ValueError, "DiscoInfo requires type"
        else:
            if disco:
                self.xmlnode = disco.xmlnode.newChild(None, "identity", None)
            else:
                self.xmlnode = common_root.newChild(None, "identity", None)
                ns = self.xmlnode.newNs(DISCO_INFO_NS, None)
                self.xmlnode.setNs(ns)
            self.set_name(xmlnode_or_name)
            self.set_category(item_category)
            self.set_type(item_type)
        self.xpath_ctxt = common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d", DISCO_INFO_NS)
Пример #4
0
    def __init__(self,
                 disco,
                 xmlnode_or_jid,
                 node=None,
                 name=None,
                 action=None):
        """Initialize an `DiscoItem` object.

        :Parameters:
            - `disco`: the disco#items reply `self` is a part of.
            - `xmlnode_or_jid`: XML element describing the item or the JID of
              the item.
            - `node`: disco node of the item.
            - `name`: name of the item.
            - `action`: 'action' attribute of the item.
        :Types:
            - `disco`: `DiscoItems`
            - `xmlnode_or_jid`: `libxml2.xmlNode` or `JID`
            - `node`: `unicode`
            - `name`: `unicode`
            - `action`: `unicode`
        """
        self.disco = disco
        if isinstance(xmlnode_or_jid, JID):
            if disco:
                self.xmlnode = disco.xmlnode.newChild(None, "item", None)
            else:
                self.xmlnode = common_root.newChild(None, "item", None)
                ns = self.xmlnode.newNs(DISCO_ITEMS_NS, None)
                self.xmlnode.setNs(ns)
            self.set_jid(xmlnode_or_jid)
            self.set_name(name)
            self.set_node(node)
            self.set_action(action)
        else:
            if disco is None:
                self.xmlnode = xmlnode_or_jid.copyNode(1)
            else:
                self.xmlnode = xmlnode_or_jid
            if name:
                self.set_name(name)
            if node:
                self.set_node(node)
            if action:
                self.set_action(action)
        self.xpath_ctxt = common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d", DISCO_ITEMS_NS)
Пример #5
0
    def __init__(self, disco, xmlnode_or_name, item_category=None, item_type=None, replace=False):
        """Initialize an `DiscoIdentity` object.

        :Parameters:
            - `disco`: the disco#info reply `self` is a part of.
            - `xmlnode_or_name`: XML element describing the identity or the
              name of the item described.
            - `item_category`: category of the item described.
            - `item_type`: type of the item described.
            - `replace`: if `True` than all other <identity/> elements in
              `disco` will be removed.
        :Types:
            - `disco`: `DiscoItems`
            - `xmlnode_or_name`: `libxml2.xmlNode` or `unicode`
            - `item_category`: `unicode`
            - `item_type`: `unicode`
            - `replace`: `bool`
        """
        self.disco=disco
        if disco and replace:
            old=disco.xpath_ctxt.xpathEval("d:identity")
            if old:
                for n in old:
                    n.unlinkNode()
                    n.freeNode()
        if isinstance(xmlnode_or_name,libxml2.xmlNode):
            if disco is None:
                self.xmlnode=xmlnode_or_name.copyNode(1)
            else:
                self.xmlnode=xmlnode_or_name
        elif not item_category:
            raise ValueError,"DiscoInfo requires category"
        elif not item_type:
            raise ValueError,"DiscoInfo requires type"
        else:
            if disco:
                self.xmlnode=disco.xmlnode.newChild(None,"identity",None)
            else:
                self.xmlnode=common_root.newChild(None,"identity",None)
                ns=self.xmlnode.newNs(DISCO_INFO_NS,None)
                self.xmlnode.setNs(ns)
            self.set_name(xmlnode_or_name)
            self.set_category(item_category)
            self.set_type(item_type)
        self.xpath_ctxt=common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d",DISCO_INFO_NS)
Пример #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)
Пример #7
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)
Пример #8
0
    def __init__(self,disco,xmlnode_or_jid,node=None,name=None,action=None):
        """Initialize an `DiscoItem` object.

        :Parameters:
            - `disco`: the disco#items reply `self` is a part of.
            - `xmlnode_or_jid`: XML element describing the item or the JID of
              the item.
            - `node`: disco node of the item.
            - `name`: name of the item.
            - `action`: 'action' attribute of the item.
        :Types:
            - `disco`: `DiscoItems`
            - `xmlnode_or_jid`: `libxml2.xmlNode` or `JID`
            - `node`: `unicode`
            - `name`: `unicode`
            - `action`: `unicode`
        """
        self.disco=disco
        if isinstance(xmlnode_or_jid,JID):
            if disco:
                self.xmlnode=disco.xmlnode.newChild(None,"item",None)
            else:
                self.xmlnode=common_root.newChild(None,"item",None)
                ns=self.xmlnode.newNs(DISCO_ITEMS_NS,None)
                self.xmlnode.setNs(ns)
            self.set_jid(xmlnode_or_jid)
            self.set_name(name)
            self.set_node(node)
            self.set_action(action)
        else:
            if disco is None:
                self.xmlnode=xmlnode_or_jid.copyNode(1)
            else:
                self.xmlnode=xmlnode_or_jid
            if name:
                self.set_name(name)
            if node:
                self.set_node(node)
            if action:
                self.set_action(action)
        self.xpath_ctxt=common_doc.xpathNewContext()
        self.xpath_ctxt.setContextNode(self.xmlnode)
        self.xpath_ctxt.xpathRegisterNs("d",DISCO_ITEMS_NS)
Пример #9
0
    def __init__(self, xmlnode_or_cond, ns=None, copy=True, parent=None):
        """Initialize an ErrorNode object.

        :Parameters:
            - `xmlnode_or_cond`: XML node to be wrapped into this object
              or error condition name.
            - `ns`: XML namespace URI of the error condition element (to be
              used when the provided node has no namespace).
            - `copy`: When `True` then the XML node will be copied,
              otherwise it is only borrowed.
            - `parent`: Parent node for the XML node to be copied or created.
        :Types:
            - `xmlnode_or_cond`: `libxml2.xmlNode` or `unicode`
            - `ns`: `unicode`
            - `copy`: `bool`
            - `parent`: `libxml2.xmlNode`"""
        if type(xmlnode_or_cond) is str:
            xmlnode_or_cond = unicode(xmlnode_or_cond, "utf-8")
        self.xmlnode = None
        self.borrowed = 0
        if isinstance(xmlnode_or_cond, libxml2.xmlNode):
            self.__from_xml(xmlnode_or_cond, ns, copy, parent)
        elif isinstance(xmlnode_or_cond, ErrorNode):
            if not copy:
                raise TypeError, "ErrorNodes may only be copied"
            self.ns = from_utf8(xmlnode_or_cond.ns.getContent())
            self.xmlnode = xmlnode_or_cond.xmlnode.docCopyNode(common_doc, 1)
            if not parent:
                parent = common_root
            parent.addChild(self.xmlnode)
        elif ns is None:
            raise ValueError, "Condition namespace not given"
        else:
            if parent:
                self.xmlnode = parent.newChild(common_ns, "error", None)
                self.borrowed = 1
            else:
                self.xmlnode = common_root.newChild(common_ns, "error", None)
            cond = self.xmlnode.newChild(None, to_utf8(xmlnode_or_cond), None)
            ns = cond.newNs(ns, None)
            cond.setNs(ns)
            self.ns = from_utf8(ns.getContent())
Пример #10
0
    def __init__(self,xmlnode_or_cond,ns=None,copy=True,parent=None):
        """Initialize an ErrorNode object.

        :Parameters:
            - `xmlnode_or_cond`: XML node to be wrapped into this object
              or error condition name.
            - `ns`: XML namespace URI of the error condition element (to be
              used when the provided node has no namespace).
            - `copy`: When `True` then the XML node will be copied,
              otherwise it is only borrowed.
            - `parent`: Parent node for the XML node to be copied or created.
        :Types:
            - `xmlnode_or_cond`: `libxml2.xmlNode` or `unicode`
            - `ns`: `unicode`
            - `copy`: `bool`
            - `parent`: `libxml2.xmlNode`"""
        if type(xmlnode_or_cond) is str:
            xmlnode_or_cond=unicode(xmlnode_or_cond,"utf-8")
        self.xmlnode=None
        self.borrowed=0
        if isinstance(xmlnode_or_cond,libxml2.xmlNode):
            self.__from_xml(xmlnode_or_cond,ns,copy,parent)
        elif isinstance(xmlnode_or_cond,ErrorNode):
            if not copy:
                raise TypeError, "ErrorNodes may only be copied"
            self.ns=from_utf8(xmlnode_or_cond.ns.getContent())
            self.xmlnode=xmlnode_or_cond.xmlnode.docCopyNode(common_doc,1)
            if not parent:
                parent=common_root
            parent.addChild(self.xmlnode)
        elif ns is None:
            raise ValueError, "Condition namespace not given"
        else:
            if parent:
                self.xmlnode=parent.newChild(common_ns,"error",None)
                self.borrowed=1
            else:
                self.xmlnode=common_root.newChild(common_ns,"error",None)
            cond=self.xmlnode.newChild(None,to_utf8(xmlnode_or_cond),None)
            ns=cond.newNs(ns,None)
            cond.setNs(ns)
            self.ns=from_utf8(ns.getContent())