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.

135 lines
5.7 KiB

4 years ago
  1. from lxml.includes cimport tree
  2. from lxml.includes cimport xmlerror
  3. from libc.string cimport const_char
  4. from lxml.includes.tree cimport xmlChar, const_xmlChar
  5. cdef extern from "libxml/xpath.h":
  6. ctypedef enum xmlXPathObjectType:
  7. XPATH_UNDEFINED = 0
  8. XPATH_NODESET = 1
  9. XPATH_BOOLEAN = 2
  10. XPATH_NUMBER = 3
  11. XPATH_STRING = 4
  12. XPATH_POINT = 5
  13. XPATH_RANGE = 6
  14. XPATH_LOCATIONSET = 7
  15. XPATH_USERS = 8
  16. XPATH_XSLT_TREE = 9
  17. ctypedef enum xmlXPathError:
  18. XPATH_EXPRESSION_OK = 0
  19. XPATH_NUMBER_ERROR = 1
  20. XPATH_UNFINISHED_LITERAL_ERROR = 2
  21. XPATH_START_LITERAL_ERROR = 3
  22. XPATH_VARIABLE_REF_ERROR = 4
  23. XPATH_UNDEF_VARIABLE_ERROR = 5
  24. XPATH_INVALID_PREDICATE_ERROR = 6
  25. XPATH_EXPR_ERROR = 7
  26. XPATH_UNCLOSED_ERROR = 8
  27. XPATH_UNKNOWN_FUNC_ERROR = 9
  28. XPATH_INVALID_OPERAND = 10
  29. XPATH_INVALID_TYPE = 11
  30. XPATH_INVALID_ARITY = 12
  31. XPATH_INVALID_CTXT_SIZE = 13
  32. XPATH_INVALID_CTXT_POSITION = 14
  33. XPATH_MEMORY_ERROR = 15
  34. XPTR_SYNTAX_ERROR = 16
  35. XPTR_RESOURCE_ERROR = 17
  36. XPTR_SUB_RESOURCE_ERROR = 18
  37. XPATH_UNDEF_PREFIX_ERROR = 19
  38. XPATH_ENCODING_ERROR = 20
  39. XPATH_INVALID_CHAR_ERROR = 21
  40. XPATH_INVALID_CTXT = 22
  41. ctypedef struct xmlNodeSet:
  42. int nodeNr
  43. int nodeMax
  44. tree.xmlNode** nodeTab
  45. ctypedef struct xmlXPathObject:
  46. xmlXPathObjectType type
  47. xmlNodeSet* nodesetval
  48. bint boolval
  49. double floatval
  50. xmlChar* stringval
  51. ctypedef struct xmlXPathContext:
  52. tree.xmlDoc* doc
  53. tree.xmlNode* node
  54. tree.xmlDict* dict
  55. tree.xmlHashTable* nsHash
  56. const_xmlChar* function
  57. const_xmlChar* functionURI
  58. xmlerror.xmlStructuredErrorFunc error
  59. xmlerror.xmlError lastError
  60. void* userData
  61. ctypedef struct xmlXPathParserContext:
  62. xmlXPathContext* context
  63. xmlXPathObject* value
  64. tree.xmlNode* ancestor
  65. int error
  66. ctypedef struct xmlXPathCompExpr
  67. ctypedef void (*xmlXPathFunction)(xmlXPathParserContext* ctxt, int nargs) nogil
  68. ctypedef xmlXPathFunction (*xmlXPathFuncLookupFunc)(void* ctxt,
  69. const_xmlChar* name,
  70. const_xmlChar* ns_uri) nogil
  71. cdef xmlXPathContext* xmlXPathNewContext(tree.xmlDoc* doc) nogil
  72. cdef xmlXPathObject* xmlXPathEvalExpression(const_xmlChar* str,
  73. xmlXPathContext* ctxt) nogil
  74. cdef xmlXPathObject* xmlXPathCompiledEval(xmlXPathCompExpr* comp,
  75. xmlXPathContext* ctxt) nogil
  76. cdef xmlXPathCompExpr* xmlXPathCompile(const_xmlChar* str) nogil
  77. cdef xmlXPathCompExpr* xmlXPathCtxtCompile(xmlXPathContext* ctxt,
  78. const_xmlChar* str) nogil
  79. cdef void xmlXPathFreeContext(xmlXPathContext* ctxt) nogil
  80. cdef void xmlXPathFreeCompExpr(xmlXPathCompExpr* comp) nogil
  81. cdef void xmlXPathFreeObject(xmlXPathObject* obj) nogil
  82. cdef int xmlXPathRegisterNs(xmlXPathContext* ctxt,
  83. const_xmlChar* prefix, const_xmlChar* ns_uri) nogil
  84. cdef xmlNodeSet* xmlXPathNodeSetCreate(tree.xmlNode* val) nogil
  85. cdef void xmlXPathFreeNodeSet(xmlNodeSet* val) nogil
  86. cdef extern from "libxml/xpathInternals.h":
  87. cdef int xmlXPathRegisterFunc(xmlXPathContext* ctxt,
  88. const_xmlChar* name,
  89. xmlXPathFunction f) nogil
  90. cdef int xmlXPathRegisterFuncNS(xmlXPathContext* ctxt,
  91. const_xmlChar* name,
  92. const_xmlChar* ns_uri,
  93. xmlXPathFunction f) nogil
  94. cdef void xmlXPathRegisterFuncLookup(xmlXPathContext *ctxt,
  95. xmlXPathFuncLookupFunc f,
  96. void *funcCtxt) nogil
  97. cdef int xmlXPathRegisterVariable(xmlXPathContext *ctxt,
  98. const_xmlChar* name,
  99. xmlXPathObject* value) nogil
  100. cdef int xmlXPathRegisterVariableNS(xmlXPathContext *ctxt,
  101. const_xmlChar* name,
  102. const_xmlChar* ns_uri,
  103. xmlXPathObject* value) nogil
  104. cdef void xmlXPathRegisteredVariablesCleanup(xmlXPathContext *ctxt) nogil
  105. cdef void xmlXPathRegisteredNsCleanup(xmlXPathContext *ctxt) nogil
  106. cdef xmlXPathObject* valuePop (xmlXPathParserContext *ctxt) nogil
  107. cdef int valuePush(xmlXPathParserContext* ctxt, xmlXPathObject *value) nogil
  108. cdef xmlXPathObject* xmlXPathNewCString(const_char *val) nogil
  109. cdef xmlXPathObject* xmlXPathWrapCString(const_char * val) nogil
  110. cdef xmlXPathObject* xmlXPathNewString(const_xmlChar *val) nogil
  111. cdef xmlXPathObject* xmlXPathWrapString(const_xmlChar * val) nogil
  112. cdef xmlXPathObject* xmlXPathNewFloat(double val) nogil
  113. cdef xmlXPathObject* xmlXPathNewBoolean(int val) nogil
  114. cdef xmlXPathObject* xmlXPathNewNodeSet(tree.xmlNode* val) nogil
  115. cdef xmlXPathObject* xmlXPathNewValueTree(tree.xmlNode* val) nogil
  116. cdef void xmlXPathNodeSetAdd(xmlNodeSet* cur,
  117. tree.xmlNode* val) nogil
  118. cdef void xmlXPathNodeSetAddUnique(xmlNodeSet* cur,
  119. tree.xmlNode* val) nogil
  120. cdef xmlXPathObject* xmlXPathWrapNodeSet(xmlNodeSet* val) nogil
  121. cdef void xmlXPathErr(xmlXPathParserContext* ctxt, int error) nogil