コード例 #1
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def _find_namespace_for_prefix(node, prefix):

    "Find the namespace definition node in the given 'node' for 'prefix'."

    current = libxml2mod.xmlNodeGetNsDefs(node)
    while current is not None:
        if libxml2mod.name(current) == prefix:
            return current
        current = libxml2mod.next(current)
    return None
コード例 #2
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def _find_namespace_for_prefix(node, prefix):

    "Find the namespace definition node in the given 'node' for 'prefix'."

    current = libxml2mod.xmlNodeGetNsDefs(node)
    while current is not None:
        if libxml2mod.name(current) == prefix:
            return current
        current = libxml2mod.next(current)
    return None
コード例 #3
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def Node_childNodes(node):

    # NOTE: Consider a generator instead.

    child_nodes = []
    node = libxml2mod.children(node)
    while node is not None:
        # Remove doctypes.
        if Node_nodeType(node) != xml.dom.Node.DOCUMENT_TYPE_NODE:
            child_nodes.append(node)
        node = libxml2mod.next(node)
    return child_nodes
コード例 #4
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def Node_childNodes(node):

    # NOTE: Consider a generator instead.

    child_nodes = []
    node = libxml2mod.children(node)
    while node is not None:
        # Remove doctypes.
        if Node_nodeType(node) != xml.dom.Node.DOCUMENT_TYPE_NODE:
            child_nodes.append(node)
        node = libxml2mod.next(node)
    return child_nodes
コード例 #5
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def _get_invented_prefix(node, ns):
    current = libxml2mod.xmlNodeGetNsDefs(node)
    prefixes = []
    while current is not None:
        current_prefix = libxml2mod.name(current)
        prefixes.append(current_prefix)
        current = libxml2mod.next(current)
    i = 0
    while 1:
        prefix = "NS%d" % i
        if prefix not in prefixes:
            return prefix
        i += 1
コード例 #6
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def _get_invented_prefix(node, ns):
    current = libxml2mod.xmlNodeGetNsDefs(node)
    prefixes = []
    while current is not None:
        current_prefix = libxml2mod.name(current)
        prefixes.append(current_prefix)
        current = libxml2mod.next(current)
    i = 0
    while 1:
        prefix = "NS%d" % i
        if prefix not in prefixes:
            return prefix
        i += 1
コード例 #7
0
 def __getattr__(self, attr):
     if attr == "parent":
         ret = libxml2mod.parent(self._o)
         if ret == None:
             return None
         return xmlNode(_obj=ret)
     elif attr == "properties":
         ret = libxml2mod.properties(self._o)
         if ret == None:
             return None
         return xmlAttr(_obj=ret)
     elif attr == "children":
         ret = libxml2mod.children(self._o)
         if ret == None:
             return None
         return xmlNode(_obj=ret)
     elif attr == "last":
         ret = libxml2mod.last(self._o)
         if ret == None:
             return None
         return xmlNode(_obj=ret)
     elif attr == "next":
         ret = libxml2mod.next(self._o)
         if ret == None:
             return None
         return xmlNode(_obj=ret)
     elif attr == "prev":
         ret = libxml2mod.prev(self._o)
         if ret == None:
             return None
         return xmlNode(_obj=ret)
     elif attr == "content":
         return libxml2mod.xmlNodeGetContent(self._o)
     elif attr == "name":
         return libxml2mod.name(self._o)
     elif attr == "type":
         return libxml2mod.type(self._o)
     elif attr == "doc":
         ret = libxml2mod.doc(self._o)
         if ret == None:
             if self.type == "document_xml" or self.type == "document_html":
                 return xmlDoc(_obj=self._o)
             else:
                 return None
         return xmlDoc(_obj=ret)
     raise AttributeError,attr
コード例 #8
0
 def __getattr__(self, attr):
     if attr == "parent":
         ret = libxml2mod.parent(self._o)
         if ret == None:
             return None
         return nodeWrap(ret)
     elif attr == "properties":
         ret = libxml2mod.properties(self._o)
         if ret == None:
             return None
         return xmlAttr(_obj=ret)
     elif attr == "children":
         ret = libxml2mod.children(self._o)
         if ret == None:
             return None
         return nodeWrap(ret)
     elif attr == "last":
         ret = libxml2mod.last(self._o)
         if ret == None:
             return None
         return nodeWrap(ret)
     elif attr == "next":
         ret = libxml2mod.next(self._o)
         if ret == None:
             return None
         return nodeWrap(ret)
     elif attr == "prev":
         ret = libxml2mod.prev(self._o)
         if ret == None:
             return None
         return nodeWrap(ret)
     elif attr == "content":
         return libxml2mod.xmlNodeGetContent(self._o)
     elif attr == "name":
         return libxml2mod.name(self._o)
     elif attr == "type":
         return libxml2mod.type(self._o)
     elif attr == "doc":
         ret = libxml2mod.doc(self._o)
         if ret == None:
             if self.type == "document_xml" or self.type == "document_html":
                 return xmlDoc(_obj=self._o)
             else:
                 return None
         return xmlDoc(_obj=ret)
     raise AttributeError(attr)
コード例 #9
0
ファイル: macrolib.py プロジェクト: kp7/plan
def _find_namespace(node, ns, prefix):

    """
    Find the namespace definition node in the given 'node' for the given 'ns'
    and 'prefix'.
    """

    new_ns = None
    current = libxml2mod.xmlNodeGetNsDefs(node)
    while current is not None:
        if _check_namespace(current, ns, prefix):
            new_ns = current
            break
        current = libxml2mod.next(current)
    if new_ns is None:
        node_ns = libxml2mod.xmlNodeGetNs(node)
        if node_ns is not None and _check_namespace(node_ns, ns, prefix):
            new_ns = node_ns
    return new_ns
コード例 #10
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def _find_namespace(node, ns, prefix):

    """
    Find the namespace definition node in the given 'node' for the given 'ns'
    and 'prefix'.
    """

    # Special treatment for XML namespace.

    if prefix == "xml" and ns == xml.dom.XML_NAMESPACE:
        return libxml2mod.xmlSearchNsByHref(Node_ownerDocument(node), node, xml.dom.XML_NAMESPACE)

    new_ns = None
    current = libxml2mod.xmlNodeGetNsDefs(node)
    while current is not None:
        if _check_namespace(current, ns, prefix):
            new_ns = current
            break
        current = libxml2mod.next(current)
    if new_ns is None:
        node_ns = libxml2mod.xmlNodeGetNs(node)
        if node_ns is not None and _check_namespace(node_ns, ns, prefix):
            new_ns = node_ns
    return new_ns
コード例 #11
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def Node_attributes(node):
    attributes = {}

    # Include normal attributes.

    current = libxml2mod.properties(node)
    while current is not None:
        ns = libxml2mod.xmlNodeGetNs(current)
        if ns is not None:
            attributes[(get_ns(ns), libxml2mod.name(current))] = current
        else:
            attributes[(None, libxml2mod.name(current))] = current
        current = libxml2mod.next(current)

    # Include xmlns attributes.

    #current = libxml2mod.xmlNodeGetNsDefs(node)
    #while current is not None:
    #    ns = get_ns(current)
    #    prefix = libxml2mod.name(current)
    #    attributes[(xml.dom.XMLNS_NAMESPACE, "xmlns:" + prefix)] = ns # NOTE: Need a real node here.
    #    current = libxml2mod.next(current)

    return attributes
コード例 #12
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def _find_namespace(node, ns, prefix):

    """
    Find the namespace definition node in the given 'node' for the given 'ns'
    and 'prefix'.
    """

    # Special treatment for XML namespace.

    if prefix == "xml" and ns == xml.dom.XML_NAMESPACE:
        return libxml2mod.xmlSearchNsByHref(Node_ownerDocument(node), node, xml.dom.XML_NAMESPACE)

    new_ns = None
    current = libxml2mod.xmlNodeGetNsDefs(node)
    while current is not None:
        if _check_namespace(current, ns, prefix):
            new_ns = current
            break
        current = libxml2mod.next(current)
    if new_ns is None:
        node_ns = libxml2mod.xmlNodeGetNs(node)
        if node_ns is not None and _check_namespace(node_ns, ns, prefix):
            new_ns = node_ns
    return new_ns
コード例 #13
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def Node_attributes(node):
    attributes = {}

    # Include normal attributes.

    current = libxml2mod.properties(node)
    while current is not None:
        ns = libxml2mod.xmlNodeGetNs(current)
        if ns is not None:
            attributes[(get_ns(ns), libxml2mod.name(current))] = current
        else:
            attributes[(None, libxml2mod.name(current))] = current
        current = libxml2mod.next(current)

    # Include xmlns attributes.

    #current = libxml2mod.xmlNodeGetNsDefs(node)
    #while current is not None:
    #    ns = get_ns(current)
    #    prefix = libxml2mod.name(current)
    #    attributes[(xml.dom.XMLNS_NAMESPACE, "xmlns:" + prefix)] = ns # NOTE: Need a real node here.
    #    current = libxml2mod.next(current)

    return attributes
コード例 #14
0
 def get_next(self):
     ret = libxml2mod.next(self._o)
     if ret == None:
         return None
     return nodeWrap(ret)
コード例 #15
0
 def get_next(self):
     ret = libxml2mod.next(self._o)
     if ret == None:
         return None
     return xmlNode(_obj=ret)
コード例 #16
0
 def get_next(self):
     ret = libxml2mod.next(self._o)
     if ret == None:
         return None
     return xmlNode(_obj=ret)
コード例 #17
0
ファイル: macrolib.py プロジェクト: juanchitot/jaimeboot
def Node_nextSibling(node):
    if node is not None and libxml2mod.next(node) is not None:
        return libxml2mod.next(node)
    else:
        return None
コード例 #18
0
ファイル: macrolib.py プロジェクト: fengyue23010/zolspider
def Node_nextSibling(node):
    if node is not None and libxml2mod.next(node) is not None:
        return libxml2mod.next(node)
    else:
        return None
コード例 #19
0
ファイル: libxml.py プロジェクト: Baines1986/Personal-Site
 def get_next(self):
     ret = libxml2mod.next(self._o)
     if ret == None:
         return None
     return nodeWrap(ret)