lxml 5.2.0__cp310-cp310-win32.whl → 5.2.2__cp310-cp310-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lxml/ElementInclude.py +244 -244
- lxml/__init__.py +22 -22
- lxml/_elementpath.cp310-win32.pyd +0 -0
- lxml/_elementpath.py +341 -341
- lxml/apihelpers.pxi +1793 -1793
- lxml/builder.cp310-win32.pyd +0 -0
- lxml/builder.py +232 -232
- lxml/classlookup.pxi +580 -580
- lxml/cleanup.pxi +215 -215
- lxml/cssselect.py +101 -101
- lxml/debug.pxi +90 -90
- lxml/docloader.pxi +178 -178
- lxml/doctestcompare.py +488 -488
- lxml/dtd.pxi +478 -478
- lxml/etree.cp310-win32.pyd +0 -0
- lxml/etree.h +6 -6
- lxml/etree.pyx +3732 -3711
- lxml/extensions.pxi +833 -833
- lxml/html/ElementSoup.py +10 -10
- lxml/html/__init__.py +1923 -1923
- lxml/html/_diffcommand.py +86 -86
- lxml/html/_html5builder.py +100 -100
- lxml/html/_setmixin.py +56 -56
- lxml/html/builder.py +133 -133
- lxml/html/clean.py +21 -21
- lxml/html/defs.py +135 -135
- lxml/html/diff.cp310-win32.pyd +0 -0
- lxml/html/diff.py +878 -878
- lxml/html/formfill.py +299 -299
- lxml/html/html5parser.py +260 -260
- lxml/html/soupparser.py +314 -314
- lxml/html/usedoctest.py +13 -13
- lxml/includes/c14n.pxd +25 -25
- lxml/includes/config.pxd +3 -3
- lxml/includes/dtdvalid.pxd +18 -18
- lxml/includes/etree_defs.h +379 -379
- lxml/includes/etreepublic.pxd +237 -237
- lxml/includes/htmlparser.pxd +56 -56
- lxml/includes/lxml-version.h +1 -1
- lxml/includes/relaxng.pxd +64 -64
- lxml/includes/schematron.pxd +34 -34
- lxml/includes/tree.pxd +494 -494
- lxml/includes/uri.pxd +5 -5
- lxml/includes/xinclude.pxd +22 -22
- lxml/includes/xmlerror.pxd +852 -852
- lxml/includes/xmlparser.pxd +265 -265
- lxml/includes/xmlschema.pxd +35 -35
- lxml/includes/xpath.pxd +136 -136
- lxml/includes/xslt.pxd +190 -190
- lxml/isoschematron/__init__.py +348 -348
- lxml/isoschematron/resources/rng/iso-schematron.rng +709 -709
- lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl +75 -75
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +312 -312
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl +1159 -1159
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl +54 -54
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1796 -1796
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -588
- lxml/iterparse.pxi +438 -438
- lxml/lxml.etree.h +6 -6
- lxml/nsclasses.pxi +281 -281
- lxml/objectify.cp310-win32.pyd +0 -0
- lxml/objectify.pyx +2145 -2145
- lxml/objectpath.pxi +332 -332
- lxml/parser.pxi +1994 -1994
- lxml/parsertarget.pxi +180 -180
- lxml/proxy.pxi +619 -619
- lxml/public-api.pxi +178 -178
- lxml/pyclasslookup.py +3 -3
- lxml/readonlytree.pxi +565 -565
- lxml/relaxng.pxi +165 -165
- lxml/sax.cp310-win32.pyd +0 -0
- lxml/sax.py +275 -275
- lxml/saxparser.pxi +875 -875
- lxml/schematron.pxi +168 -168
- lxml/serializer.pxi +1871 -1871
- lxml/usedoctest.py +13 -13
- lxml/xinclude.pxi +67 -67
- lxml/xmlerror.pxi +1654 -1654
- lxml/xmlid.pxi +179 -179
- lxml/xmlschema.pxi +215 -215
- lxml/xpath.pxi +487 -487
- lxml/xslt.pxi +950 -950
- lxml/xsltext.pxi +242 -242
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/LICENSE.txt +29 -29
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/LICENSES.txt +29 -29
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/METADATA +9 -17
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/RECORD +89 -89
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/WHEEL +0 -0
- {lxml-5.2.0.dist-info → lxml-5.2.2.dist-info}/top_level.txt +0 -0
lxml/relaxng.pxi
CHANGED
@@ -1,165 +1,165 @@
|
|
1
|
-
# support for RelaxNG validation
|
2
|
-
from lxml.includes cimport relaxng
|
3
|
-
|
4
|
-
cdef object _rnc2rng
|
5
|
-
try:
|
6
|
-
import rnc2rng as _rnc2rng
|
7
|
-
except ImportError:
|
8
|
-
_rnc2rng = None
|
9
|
-
|
10
|
-
|
11
|
-
cdef int _require_rnc2rng() except -1:
|
12
|
-
if _rnc2rng is None:
|
13
|
-
raise RelaxNGParseError(
|
14
|
-
'compact syntax not supported (please install rnc2rng)')
|
15
|
-
return 0
|
16
|
-
|
17
|
-
|
18
|
-
cdef class RelaxNGError(LxmlError):
|
19
|
-
"""Base class for RelaxNG errors.
|
20
|
-
"""
|
21
|
-
|
22
|
-
cdef class RelaxNGParseError(RelaxNGError):
|
23
|
-
"""Error while parsing an XML document as RelaxNG.
|
24
|
-
"""
|
25
|
-
|
26
|
-
cdef class RelaxNGValidateError(RelaxNGError):
|
27
|
-
"""Error while validating an XML document with a RelaxNG schema.
|
28
|
-
"""
|
29
|
-
|
30
|
-
|
31
|
-
################################################################################
|
32
|
-
# RelaxNG
|
33
|
-
|
34
|
-
cdef class RelaxNG(_Validator):
|
35
|
-
"""RelaxNG(self, etree=None, file=None)
|
36
|
-
Turn a document into a Relax NG validator.
|
37
|
-
|
38
|
-
Either pass a schema as Element or ElementTree, or pass a file or
|
39
|
-
filename through the ``file`` keyword argument.
|
40
|
-
"""
|
41
|
-
cdef relaxng.xmlRelaxNG* _c_schema
|
42
|
-
def __cinit__(self):
|
43
|
-
self._c_schema = NULL
|
44
|
-
|
45
|
-
def __init__(self, etree=None, *, file=None):
|
46
|
-
cdef _Document doc
|
47
|
-
cdef _Element root_node
|
48
|
-
cdef xmlDoc* fake_c_doc = NULL
|
49
|
-
cdef relaxng.xmlRelaxNGParserCtxt* parser_ctxt = NULL
|
50
|
-
_Validator.__init__(self)
|
51
|
-
if etree is not None:
|
52
|
-
doc = _documentOrRaise(etree)
|
53
|
-
root_node = _rootNodeOrRaise(etree)
|
54
|
-
fake_c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
|
55
|
-
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(fake_c_doc)
|
56
|
-
elif file is not None:
|
57
|
-
if _isString(file):
|
58
|
-
if file[-4:].lower() == '.rnc':
|
59
|
-
_require_rnc2rng()
|
60
|
-
rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
|
61
|
-
doc = _parseMemoryDocument(rng_data_utf8, parser=None, url=file)
|
62
|
-
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
63
|
-
else:
|
64
|
-
doc = None
|
65
|
-
filename = _encodeFilename(file)
|
66
|
-
with self._error_log:
|
67
|
-
orig_loader = _register_document_loader()
|
68
|
-
parser_ctxt = relaxng.xmlRelaxNGNewParserCtxt(_cstr(filename))
|
69
|
-
_reset_document_loader(orig_loader)
|
70
|
-
elif (_getFilenameForFile(file) or '')[-4:].lower() == '.rnc':
|
71
|
-
_require_rnc2rng()
|
72
|
-
rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
|
73
|
-
doc = _parseMemoryDocument(
|
74
|
-
rng_data_utf8, parser=None, url=_getFilenameForFile(file))
|
75
|
-
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
76
|
-
else:
|
77
|
-
doc = _parseDocument(file, parser=None, base_url=None)
|
78
|
-
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
79
|
-
else:
|
80
|
-
raise RelaxNGParseError, "No tree or file given"
|
81
|
-
|
82
|
-
if parser_ctxt is NULL:
|
83
|
-
if fake_c_doc is not NULL:
|
84
|
-
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
85
|
-
raise RelaxNGParseError(
|
86
|
-
self._error_log._buildExceptionMessage(
|
87
|
-
"Document is not parsable as Relax NG"),
|
88
|
-
self._error_log)
|
89
|
-
|
90
|
-
# Need a cast here because older libxml2 releases do not use 'const' in the functype.
|
91
|
-
relaxng.xmlRelaxNGSetParserStructuredErrors(
|
92
|
-
parser_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
|
93
|
-
_connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGP)
|
94
|
-
self._c_schema = relaxng.xmlRelaxNGParse(parser_ctxt)
|
95
|
-
_connectGenericErrorLog(None)
|
96
|
-
|
97
|
-
relaxng.xmlRelaxNGFreeParserCtxt(parser_ctxt)
|
98
|
-
if self._c_schema is NULL:
|
99
|
-
if fake_c_doc is not NULL:
|
100
|
-
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
101
|
-
raise RelaxNGParseError(
|
102
|
-
self._error_log._buildExceptionMessage(
|
103
|
-
"Document is not valid Relax NG"),
|
104
|
-
self._error_log)
|
105
|
-
if fake_c_doc is not NULL:
|
106
|
-
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
107
|
-
|
108
|
-
def __dealloc__(self):
|
109
|
-
relaxng.xmlRelaxNGFree(self._c_schema)
|
110
|
-
|
111
|
-
def __call__(self, etree):
|
112
|
-
"""__call__(self, etree)
|
113
|
-
|
114
|
-
Validate doc using Relax NG.
|
115
|
-
|
116
|
-
Returns true if document is valid, false if not."""
|
117
|
-
cdef _Document doc
|
118
|
-
cdef _Element root_node
|
119
|
-
cdef xmlDoc* c_doc
|
120
|
-
cdef relaxng.xmlRelaxNGValidCtxt* valid_ctxt
|
121
|
-
cdef int ret
|
122
|
-
|
123
|
-
assert self._c_schema is not NULL, "RelaxNG instance not initialised"
|
124
|
-
doc = _documentOrRaise(etree)
|
125
|
-
root_node = _rootNodeOrRaise(etree)
|
126
|
-
|
127
|
-
valid_ctxt = relaxng.xmlRelaxNGNewValidCtxt(self._c_schema)
|
128
|
-
if valid_ctxt is NULL:
|
129
|
-
raise MemoryError()
|
130
|
-
|
131
|
-
try:
|
132
|
-
self._error_log.clear()
|
133
|
-
# Need a cast here because older libxml2 releases do not use 'const' in the functype.
|
134
|
-
relaxng.xmlRelaxNGSetValidStructuredErrors(
|
135
|
-
valid_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
|
136
|
-
_connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGV)
|
137
|
-
c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
|
138
|
-
with nogil:
|
139
|
-
ret = relaxng.xmlRelaxNGValidateDoc(valid_ctxt, c_doc)
|
140
|
-
_destroyFakeDoc(doc._c_doc, c_doc)
|
141
|
-
finally:
|
142
|
-
_connectGenericErrorLog(None)
|
143
|
-
relaxng.xmlRelaxNGFreeValidCtxt(valid_ctxt)
|
144
|
-
|
145
|
-
if ret == -1:
|
146
|
-
raise RelaxNGValidateError(
|
147
|
-
"Internal error in Relax NG validation",
|
148
|
-
self._error_log)
|
149
|
-
if ret == 0:
|
150
|
-
return True
|
151
|
-
else:
|
152
|
-
return False
|
153
|
-
|
154
|
-
@classmethod
|
155
|
-
def from_rnc_string(cls, src, base_url=None):
|
156
|
-
"""Parse a RelaxNG schema in compact syntax from a text string
|
157
|
-
|
158
|
-
Requires the rnc2rng package to be installed.
|
159
|
-
|
160
|
-
Passing the source URL or file path of the source as 'base_url'
|
161
|
-
will enable resolving resource references relative to the source.
|
162
|
-
"""
|
163
|
-
_require_rnc2rng()
|
164
|
-
rng_str = utf8(_rnc2rng.dumps(_rnc2rng.loads(src)))
|
165
|
-
return cls(_parseMemoryDocument(rng_str, parser=None, url=base_url))
|
1
|
+
# support for RelaxNG validation
|
2
|
+
from lxml.includes cimport relaxng
|
3
|
+
|
4
|
+
cdef object _rnc2rng
|
5
|
+
try:
|
6
|
+
import rnc2rng as _rnc2rng
|
7
|
+
except ImportError:
|
8
|
+
_rnc2rng = None
|
9
|
+
|
10
|
+
|
11
|
+
cdef int _require_rnc2rng() except -1:
|
12
|
+
if _rnc2rng is None:
|
13
|
+
raise RelaxNGParseError(
|
14
|
+
'compact syntax not supported (please install rnc2rng)')
|
15
|
+
return 0
|
16
|
+
|
17
|
+
|
18
|
+
cdef class RelaxNGError(LxmlError):
|
19
|
+
"""Base class for RelaxNG errors.
|
20
|
+
"""
|
21
|
+
|
22
|
+
cdef class RelaxNGParseError(RelaxNGError):
|
23
|
+
"""Error while parsing an XML document as RelaxNG.
|
24
|
+
"""
|
25
|
+
|
26
|
+
cdef class RelaxNGValidateError(RelaxNGError):
|
27
|
+
"""Error while validating an XML document with a RelaxNG schema.
|
28
|
+
"""
|
29
|
+
|
30
|
+
|
31
|
+
################################################################################
|
32
|
+
# RelaxNG
|
33
|
+
|
34
|
+
cdef class RelaxNG(_Validator):
|
35
|
+
"""RelaxNG(self, etree=None, file=None)
|
36
|
+
Turn a document into a Relax NG validator.
|
37
|
+
|
38
|
+
Either pass a schema as Element or ElementTree, or pass a file or
|
39
|
+
filename through the ``file`` keyword argument.
|
40
|
+
"""
|
41
|
+
cdef relaxng.xmlRelaxNG* _c_schema
|
42
|
+
def __cinit__(self):
|
43
|
+
self._c_schema = NULL
|
44
|
+
|
45
|
+
def __init__(self, etree=None, *, file=None):
|
46
|
+
cdef _Document doc
|
47
|
+
cdef _Element root_node
|
48
|
+
cdef xmlDoc* fake_c_doc = NULL
|
49
|
+
cdef relaxng.xmlRelaxNGParserCtxt* parser_ctxt = NULL
|
50
|
+
_Validator.__init__(self)
|
51
|
+
if etree is not None:
|
52
|
+
doc = _documentOrRaise(etree)
|
53
|
+
root_node = _rootNodeOrRaise(etree)
|
54
|
+
fake_c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
|
55
|
+
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(fake_c_doc)
|
56
|
+
elif file is not None:
|
57
|
+
if _isString(file):
|
58
|
+
if file[-4:].lower() == '.rnc':
|
59
|
+
_require_rnc2rng()
|
60
|
+
rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
|
61
|
+
doc = _parseMemoryDocument(rng_data_utf8, parser=None, url=file)
|
62
|
+
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
63
|
+
else:
|
64
|
+
doc = None
|
65
|
+
filename = _encodeFilename(file)
|
66
|
+
with self._error_log:
|
67
|
+
orig_loader = _register_document_loader()
|
68
|
+
parser_ctxt = relaxng.xmlRelaxNGNewParserCtxt(_cstr(filename))
|
69
|
+
_reset_document_loader(orig_loader)
|
70
|
+
elif (_getFilenameForFile(file) or '')[-4:].lower() == '.rnc':
|
71
|
+
_require_rnc2rng()
|
72
|
+
rng_data_utf8 = _utf8(_rnc2rng.dumps(_rnc2rng.load(file)))
|
73
|
+
doc = _parseMemoryDocument(
|
74
|
+
rng_data_utf8, parser=None, url=_getFilenameForFile(file))
|
75
|
+
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
76
|
+
else:
|
77
|
+
doc = _parseDocument(file, parser=None, base_url=None)
|
78
|
+
parser_ctxt = relaxng.xmlRelaxNGNewDocParserCtxt(doc._c_doc)
|
79
|
+
else:
|
80
|
+
raise RelaxNGParseError, "No tree or file given"
|
81
|
+
|
82
|
+
if parser_ctxt is NULL:
|
83
|
+
if fake_c_doc is not NULL:
|
84
|
+
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
85
|
+
raise RelaxNGParseError(
|
86
|
+
self._error_log._buildExceptionMessage(
|
87
|
+
"Document is not parsable as Relax NG"),
|
88
|
+
self._error_log)
|
89
|
+
|
90
|
+
# Need a cast here because older libxml2 releases do not use 'const' in the functype.
|
91
|
+
relaxng.xmlRelaxNGSetParserStructuredErrors(
|
92
|
+
parser_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
|
93
|
+
_connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGP)
|
94
|
+
self._c_schema = relaxng.xmlRelaxNGParse(parser_ctxt)
|
95
|
+
_connectGenericErrorLog(None)
|
96
|
+
|
97
|
+
relaxng.xmlRelaxNGFreeParserCtxt(parser_ctxt)
|
98
|
+
if self._c_schema is NULL:
|
99
|
+
if fake_c_doc is not NULL:
|
100
|
+
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
101
|
+
raise RelaxNGParseError(
|
102
|
+
self._error_log._buildExceptionMessage(
|
103
|
+
"Document is not valid Relax NG"),
|
104
|
+
self._error_log)
|
105
|
+
if fake_c_doc is not NULL:
|
106
|
+
_destroyFakeDoc(doc._c_doc, fake_c_doc)
|
107
|
+
|
108
|
+
def __dealloc__(self):
|
109
|
+
relaxng.xmlRelaxNGFree(self._c_schema)
|
110
|
+
|
111
|
+
def __call__(self, etree):
|
112
|
+
"""__call__(self, etree)
|
113
|
+
|
114
|
+
Validate doc using Relax NG.
|
115
|
+
|
116
|
+
Returns true if document is valid, false if not."""
|
117
|
+
cdef _Document doc
|
118
|
+
cdef _Element root_node
|
119
|
+
cdef xmlDoc* c_doc
|
120
|
+
cdef relaxng.xmlRelaxNGValidCtxt* valid_ctxt
|
121
|
+
cdef int ret
|
122
|
+
|
123
|
+
assert self._c_schema is not NULL, "RelaxNG instance not initialised"
|
124
|
+
doc = _documentOrRaise(etree)
|
125
|
+
root_node = _rootNodeOrRaise(etree)
|
126
|
+
|
127
|
+
valid_ctxt = relaxng.xmlRelaxNGNewValidCtxt(self._c_schema)
|
128
|
+
if valid_ctxt is NULL:
|
129
|
+
raise MemoryError()
|
130
|
+
|
131
|
+
try:
|
132
|
+
self._error_log.clear()
|
133
|
+
# Need a cast here because older libxml2 releases do not use 'const' in the functype.
|
134
|
+
relaxng.xmlRelaxNGSetValidStructuredErrors(
|
135
|
+
valid_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
|
136
|
+
_connectGenericErrorLog(self._error_log, xmlerror.XML_FROM_RELAXNGV)
|
137
|
+
c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
|
138
|
+
with nogil:
|
139
|
+
ret = relaxng.xmlRelaxNGValidateDoc(valid_ctxt, c_doc)
|
140
|
+
_destroyFakeDoc(doc._c_doc, c_doc)
|
141
|
+
finally:
|
142
|
+
_connectGenericErrorLog(None)
|
143
|
+
relaxng.xmlRelaxNGFreeValidCtxt(valid_ctxt)
|
144
|
+
|
145
|
+
if ret == -1:
|
146
|
+
raise RelaxNGValidateError(
|
147
|
+
"Internal error in Relax NG validation",
|
148
|
+
self._error_log)
|
149
|
+
if ret == 0:
|
150
|
+
return True
|
151
|
+
else:
|
152
|
+
return False
|
153
|
+
|
154
|
+
@classmethod
|
155
|
+
def from_rnc_string(cls, src, base_url=None):
|
156
|
+
"""Parse a RelaxNG schema in compact syntax from a text string
|
157
|
+
|
158
|
+
Requires the rnc2rng package to be installed.
|
159
|
+
|
160
|
+
Passing the source URL or file path of the source as 'base_url'
|
161
|
+
will enable resolving resource references relative to the source.
|
162
|
+
"""
|
163
|
+
_require_rnc2rng()
|
164
|
+
rng_str = utf8(_rnc2rng.dumps(_rnc2rng.loads(src)))
|
165
|
+
return cls(_parseMemoryDocument(rng_str, parser=None, url=base_url))
|
lxml/sax.cp310-win32.pyd
CHANGED
Binary file
|