You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

179 lines
6.5 KiB

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