public-api.pxi
1 # Public C API for lxml.etree 2 3 cdef public api _Element deepcopyNodeToDocument(_Document doc, xmlNode* c_root): 4 u"Recursively copy the element into the document. doc is not modified." 5 cdef xmlNode* c_node 6 c_node = _copyNodeToDoc(c_root, doc._c_doc) 7 return _elementFactory(doc, c_node) 8 9 cdef public api _ElementTree elementTreeFactory(_Element context_node): 10 _assertValidNode(context_node) 11 return newElementTree(context_node, _ElementTree) 12 13 cdef public api _ElementTree newElementTree(_Element context_node, 14 object subclass): 15 if <void*>context_node is NULL or context_node is None: 16 raise TypeError 17 _assertValidNode(context_node) 18 return _newElementTree(context_node._doc, context_node, subclass) 19 20 cdef public api _ElementTree adoptExternalDocument(xmlDoc* c_doc, parser, bint is_owned): 21 if c_doc is NULL: 22 raise TypeError 23 doc = _adoptForeignDoc(c_doc, parser, is_owned) 24 return _elementTreeFactory(doc, None) 25 26 cdef public api _Element elementFactory(_Document doc, xmlNode* c_node): 27 if c_node is NULL or doc is None: 28 raise TypeError 29 return _elementFactory(doc, c_node) 30 31 cdef public api _Element makeElement(tag, _Document doc, parser, 32 text, tail, attrib, nsmap): 33 return _makeElement(tag, NULL, doc, parser, text, tail, attrib, nsmap, None) 34 35 cdef public api _Element makeSubElement(_Element parent, tag, text, tail, 36 attrib, nsmap): 37 _assertValidNode(parent) 38 return _makeSubElement(parent, tag, text, tail, attrib, nsmap, None) 39 40 cdef public api void setElementClassLookupFunction( 41 _element_class_lookup_function function, state): 42 _setElementClassLookupFunction(function, state) 43 44 cdef public api object lookupDefaultElementClass(state, doc, xmlNode* c_node): 45 return _lookupDefaultElementClass(state, doc, c_node) 46 47 cdef public api object lookupNamespaceElementClass(state, doc, xmlNode* c_node): 48 return _find_nselement_class(state, doc, c_node) 49 50 cdef public api object callLookupFallback(FallbackElementClassLookup lookup, 51 _Document doc, xmlNode* c_node): 52 return _callLookupFallback(lookup, doc, c_node) 53 54 cdef public api int tagMatches(xmlNode* c_node, const_xmlChar* c_href, const_xmlChar* c_name): 55 if c_node is NULL: 56 return -1 57 return _tagMatches(c_node, c_href, c_name) 58 59 cdef public api _Document documentOrRaise(object input): 60 return _documentOrRaise(input) 61 62 cdef public api _Element rootNodeOrRaise(object input): 63 return _rootNodeOrRaise(input) 64 65 cdef public api bint hasText(xmlNode* c_node): 66 return _hasText(c_node) 67 68 cdef public api bint hasTail(xmlNode* c_node): 69 return _hasTail(c_node) 70 71 cdef public api object textOf(xmlNode* c_node): 72 if c_node is NULL: 73 return None 74 return _collectText(c_node.children) 75 76 cdef public api object tailOf(xmlNode* c_node): 77 if c_node is NULL: 78 return None 79 return _collectText(c_node.next) 80 81 cdef public api int setNodeText(xmlNode* c_node, text) except -1: 82 if c_node is NULL: 83 raise ValueError 84 return _setNodeText(c_node, text) 85 86 cdef public api int setTailText(xmlNode* c_node, text) except -1: 87 if c_node is NULL: 88 raise ValueError 89 return _setTailText(c_node, text) 90 91 cdef public api object attributeValue(xmlNode* c_element, xmlAttr* c_attrib_node): 92 return _attributeValue(c_element, c_attrib_node) 93 94 cdef public api object attributeValueFromNsName(xmlNode* c_element, 95 const_xmlChar* ns, const_xmlChar* name): 96 return _attributeValueFromNsName(c_element, ns, name) 97 98 cdef public api object getAttributeValue(_Element element, key, default): 99 _assertValidNode(element) 100 return _getAttributeValue(element, key, default) 101 102 cdef public api object iterattributes(_Element element, int keysvalues): 103 _assertValidNode(element) 104 return _attributeIteratorFactory(element, keysvalues) 105 106 cdef public api list collectAttributes(xmlNode* c_element, int keysvalues): 107 return _collectAttributes(c_element, keysvalues) 108 109 cdef public api int setAttributeValue(_Element element, key, value) except -1: 110 _assertValidNode(element) 111 return _setAttributeValue(element, key, value) 112 113 cdef public api int delAttribute(_Element element, key) except -1: 114 _assertValidNode(element) 115 return _delAttribute(element, key) 116 117 cdef public api int delAttributeFromNsName(tree.xmlNode* c_element, 118 const_xmlChar* c_href, const_xmlChar* c_name): 119 return _delAttributeFromNsName(c_element, c_href, c_name) 120 121 cdef public api bint hasChild(xmlNode* c_node): 122 return _hasChild(c_node) 123 124 cdef public api xmlNode* findChild(xmlNode* c_node, Py_ssize_t index): 125 return _findChild(c_node, index) 126 127 cdef public api xmlNode* findChildForwards(xmlNode* c_node, Py_ssize_t index): 128 return _findChildForwards(c_node, index) 129 130 cdef public api xmlNode* findChildBackwards(xmlNode* c_node, Py_ssize_t index): 131 return _findChildBackwards(c_node, index) 132 133 cdef public api xmlNode* nextElement(xmlNode* c_node): 134 return _nextElement(c_node) 135 136 cdef public api xmlNode* previousElement(xmlNode* c_node): 137 return _previousElement(c_node) 138 139 cdef public api void appendChild(_Element parent, _Element child): 140 # deprecated, use appendChildToElement() instead! 141 _appendChild(parent, child) 142 143 cdef public api int appendChildToElement(_Element parent, _Element child) except -1: 144 return _appendChild(parent, child) 145 146 cdef public api object pyunicode(const_xmlChar* s): 147 if s is NULL: 148 raise TypeError 149 return funicode(s) 150 151 cdef public api bytes utf8(object s): 152 return _utf8(s) 153 154 cdef public api tuple getNsTag(object tag): 155 return _getNsTag(tag) 156 157 cdef public api tuple getNsTagWithEmptyNs(object tag): 158 return _getNsTagWithEmptyNs(tag) 159 160 cdef public api object namespacedName(xmlNode* c_node): 161 return _namespacedName(c_node) 162 163 cdef public api object namespacedNameFromNsName(const_xmlChar* href, const_xmlChar* name): 164 return _namespacedNameFromNsName(href, name) 165 166 cdef public api void iteratorStoreNext(_ElementIterator iterator, _Element node): 167 # deprecated! 168 iterator._storeNext(node) 169 170 cdef public api void initTagMatch(_ElementTagMatcher matcher, tag): 171 # deprecated! 172 matcher._initTagMatch(tag) 173 174 cdef public api tree.xmlNs* findOrBuildNodeNsPrefix( 175 _Document doc, xmlNode* c_node, const_xmlChar* href, const_xmlChar* prefix) except NULL: 176 if doc is None: 177 raise TypeError 178 return doc._findOrBuildNodeNs(c_node, href, prefix, 0)