lxml 6.0.0__cp39-cp39-win_arm64.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 -0
- lxml/__init__.py +22 -0
- lxml/_elementpath.cp39-win_arm64.pyd +0 -0
- lxml/_elementpath.py +343 -0
- lxml/apihelpers.pxi +1801 -0
- lxml/builder.cp39-win_arm64.pyd +0 -0
- lxml/builder.py +243 -0
- lxml/classlookup.pxi +580 -0
- lxml/cleanup.pxi +215 -0
- lxml/cssselect.py +101 -0
- lxml/debug.pxi +36 -0
- lxml/docloader.pxi +178 -0
- lxml/doctestcompare.py +488 -0
- lxml/dtd.pxi +479 -0
- lxml/etree.cp39-win_arm64.pyd +0 -0
- lxml/etree.h +244 -0
- lxml/etree.pyx +3853 -0
- lxml/etree_api.h +204 -0
- lxml/extensions.pxi +830 -0
- lxml/html/ElementSoup.py +10 -0
- lxml/html/__init__.py +1927 -0
- lxml/html/_diffcommand.py +86 -0
- lxml/html/_difflib.cp39-win_arm64.pyd +0 -0
- lxml/html/_difflib.py +2106 -0
- lxml/html/_html5builder.py +100 -0
- lxml/html/_setmixin.py +56 -0
- lxml/html/builder.py +173 -0
- lxml/html/clean.py +21 -0
- lxml/html/defs.py +135 -0
- lxml/html/diff.cp39-win_arm64.pyd +0 -0
- lxml/html/diff.py +972 -0
- lxml/html/formfill.py +299 -0
- lxml/html/html5parser.py +260 -0
- lxml/html/soupparser.py +314 -0
- lxml/html/usedoctest.py +13 -0
- lxml/includes/__init__.pxd +0 -0
- lxml/includes/__init__.py +0 -0
- lxml/includes/c14n.pxd +25 -0
- lxml/includes/config.pxd +3 -0
- lxml/includes/dtdvalid.pxd +18 -0
- lxml/includes/etree_defs.h +379 -0
- lxml/includes/etreepublic.pxd +237 -0
- lxml/includes/extlibs/__init__.py +0 -0
- lxml/includes/extlibs/zconf.h +543 -0
- lxml/includes/extlibs/zlib.h +1938 -0
- lxml/includes/htmlparser.pxd +56 -0
- lxml/includes/libexslt/__init__.py +0 -0
- lxml/includes/libexslt/exslt.h +108 -0
- lxml/includes/libexslt/exsltconfig.h +70 -0
- lxml/includes/libexslt/exsltexports.h +63 -0
- lxml/includes/libexslt/libexslt.h +29 -0
- lxml/includes/libxml/HTMLparser.h +320 -0
- lxml/includes/libxml/HTMLtree.h +147 -0
- lxml/includes/libxml/SAX.h +204 -0
- lxml/includes/libxml/SAX2.h +173 -0
- lxml/includes/libxml/__init__.py +0 -0
- lxml/includes/libxml/c14n.h +128 -0
- lxml/includes/libxml/catalog.h +182 -0
- lxml/includes/libxml/chvalid.h +230 -0
- lxml/includes/libxml/debugXML.h +217 -0
- lxml/includes/libxml/dict.h +81 -0
- lxml/includes/libxml/encoding.h +233 -0
- lxml/includes/libxml/entities.h +151 -0
- lxml/includes/libxml/globals.h +529 -0
- lxml/includes/libxml/hash.h +236 -0
- lxml/includes/libxml/list.h +137 -0
- lxml/includes/libxml/nanoftp.h +186 -0
- lxml/includes/libxml/nanohttp.h +81 -0
- lxml/includes/libxml/parser.h +1265 -0
- lxml/includes/libxml/parserInternals.h +662 -0
- lxml/includes/libxml/pattern.h +100 -0
- lxml/includes/libxml/relaxng.h +218 -0
- lxml/includes/libxml/schemasInternals.h +958 -0
- lxml/includes/libxml/schematron.h +142 -0
- lxml/includes/libxml/threads.h +94 -0
- lxml/includes/libxml/tree.h +1314 -0
- lxml/includes/libxml/uri.h +94 -0
- lxml/includes/libxml/valid.h +448 -0
- lxml/includes/libxml/xinclude.h +129 -0
- lxml/includes/libxml/xlink.h +189 -0
- lxml/includes/libxml/xmlIO.h +369 -0
- lxml/includes/libxml/xmlautomata.h +146 -0
- lxml/includes/libxml/xmlerror.h +919 -0
- lxml/includes/libxml/xmlexports.h +50 -0
- lxml/includes/libxml/xmlmemory.h +228 -0
- lxml/includes/libxml/xmlmodule.h +57 -0
- lxml/includes/libxml/xmlreader.h +428 -0
- lxml/includes/libxml/xmlregexp.h +222 -0
- lxml/includes/libxml/xmlsave.h +88 -0
- lxml/includes/libxml/xmlschemas.h +246 -0
- lxml/includes/libxml/xmlschemastypes.h +152 -0
- lxml/includes/libxml/xmlstring.h +140 -0
- lxml/includes/libxml/xmlunicode.h +202 -0
- lxml/includes/libxml/xmlversion.h +526 -0
- lxml/includes/libxml/xmlwriter.h +488 -0
- lxml/includes/libxml/xpath.h +575 -0
- lxml/includes/libxml/xpathInternals.h +632 -0
- lxml/includes/libxml/xpointer.h +137 -0
- lxml/includes/libxslt/__init__.py +0 -0
- lxml/includes/libxslt/attributes.h +39 -0
- lxml/includes/libxslt/documents.h +93 -0
- lxml/includes/libxslt/extensions.h +262 -0
- lxml/includes/libxslt/extra.h +72 -0
- lxml/includes/libxslt/functions.h +78 -0
- lxml/includes/libxslt/imports.h +75 -0
- lxml/includes/libxslt/keys.h +53 -0
- lxml/includes/libxslt/libxslt.h +36 -0
- lxml/includes/libxslt/namespaces.h +68 -0
- lxml/includes/libxslt/numbersInternals.h +73 -0
- lxml/includes/libxslt/preproc.h +43 -0
- lxml/includes/libxslt/security.h +104 -0
- lxml/includes/libxslt/templates.h +77 -0
- lxml/includes/libxslt/transform.h +207 -0
- lxml/includes/libxslt/trio.h +216 -0
- lxml/includes/libxslt/triodef.h +220 -0
- lxml/includes/libxslt/variables.h +118 -0
- lxml/includes/libxslt/win32config.h +51 -0
- lxml/includes/libxslt/xslt.h +110 -0
- lxml/includes/libxslt/xsltInternals.h +1992 -0
- lxml/includes/libxslt/xsltconfig.h +179 -0
- lxml/includes/libxslt/xsltexports.h +64 -0
- lxml/includes/libxslt/xsltlocale.h +44 -0
- lxml/includes/libxslt/xsltutils.h +343 -0
- lxml/includes/lxml-version.h +3 -0
- lxml/includes/relaxng.pxd +64 -0
- lxml/includes/schematron.pxd +34 -0
- lxml/includes/tree.pxd +492 -0
- lxml/includes/uri.pxd +5 -0
- lxml/includes/xinclude.pxd +22 -0
- lxml/includes/xmlerror.pxd +852 -0
- lxml/includes/xmlparser.pxd +303 -0
- lxml/includes/xmlschema.pxd +35 -0
- lxml/includes/xpath.pxd +136 -0
- lxml/includes/xslt.pxd +190 -0
- lxml/isoschematron/__init__.py +348 -0
- lxml/isoschematron/resources/rng/iso-schematron.rng +709 -0
- lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl +75 -0
- lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl +77 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl +313 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl +1160 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl +55 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl +1796 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl +588 -0
- lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt +84 -0
- lxml/iterparse.pxi +438 -0
- lxml/lxml.etree.h +244 -0
- lxml/lxml.etree_api.h +204 -0
- lxml/nsclasses.pxi +281 -0
- lxml/objectify.cp39-win_arm64.pyd +0 -0
- lxml/objectify.pyx +2149 -0
- lxml/objectpath.pxi +332 -0
- lxml/parser.pxi +2059 -0
- lxml/parsertarget.pxi +180 -0
- lxml/proxy.pxi +619 -0
- lxml/public-api.pxi +178 -0
- lxml/pyclasslookup.py +3 -0
- lxml/readonlytree.pxi +565 -0
- lxml/relaxng.pxi +165 -0
- lxml/sax.cp39-win_arm64.pyd +0 -0
- lxml/sax.py +286 -0
- lxml/saxparser.pxi +875 -0
- lxml/schematron.pxi +173 -0
- lxml/serializer.pxi +1849 -0
- lxml/usedoctest.py +13 -0
- lxml/xinclude.pxi +67 -0
- lxml/xmlerror.pxi +1654 -0
- lxml/xmlid.pxi +179 -0
- lxml/xmlschema.pxi +215 -0
- lxml/xpath.pxi +487 -0
- lxml/xslt.pxi +957 -0
- lxml/xsltext.pxi +242 -0
- lxml-6.0.0.dist-info/METADATA +163 -0
- lxml-6.0.0.dist-info/RECORD +177 -0
- lxml-6.0.0.dist-info/WHEEL +5 -0
- lxml-6.0.0.dist-info/licenses/LICENSE.txt +31 -0
- lxml-6.0.0.dist-info/licenses/LICENSES.txt +29 -0
- lxml-6.0.0.dist-info/top_level.txt +1 -0
lxml/schematron.pxi
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
# support for Schematron validation
|
2
|
+
from lxml.includes cimport schematron
|
3
|
+
|
4
|
+
|
5
|
+
cdef class SchematronError(LxmlError):
|
6
|
+
"""Base class of all Schematron errors.
|
7
|
+
"""
|
8
|
+
|
9
|
+
cdef class SchematronParseError(SchematronError):
|
10
|
+
"""Error while parsing an XML document as Schematron schema.
|
11
|
+
"""
|
12
|
+
|
13
|
+
cdef class SchematronValidateError(SchematronError):
|
14
|
+
"""Error while validating an XML document with a Schematron schema.
|
15
|
+
"""
|
16
|
+
|
17
|
+
|
18
|
+
################################################################################
|
19
|
+
# Schematron
|
20
|
+
|
21
|
+
cdef class Schematron(_Validator):
|
22
|
+
"""Schematron(self, etree=None, file=None)
|
23
|
+
A Schematron validator.
|
24
|
+
|
25
|
+
Pass a root Element or an ElementTree to turn it into a validator.
|
26
|
+
Alternatively, pass a filename as keyword argument 'file' to parse from
|
27
|
+
the file system.
|
28
|
+
|
29
|
+
Schematron is a less well known, but very powerful schema language. The main
|
30
|
+
idea is to use the capabilities of XPath to put restrictions on the structure
|
31
|
+
and the content of XML documents. Here is a simple example::
|
32
|
+
|
33
|
+
>>> schematron = Schematron(XML('''
|
34
|
+
... <schema xmlns="http://www.ascc.net/xml/schematron" >
|
35
|
+
... <pattern name="id is the only permitted attribute name">
|
36
|
+
... <rule context="*">
|
37
|
+
... <report test="@*[not(name()='id')]">Attribute
|
38
|
+
... <name path="@*[not(name()='id')]"/> is forbidden<name/>
|
39
|
+
... </report>
|
40
|
+
... </rule>
|
41
|
+
... </pattern>
|
42
|
+
... </schema>
|
43
|
+
... '''))
|
44
|
+
|
45
|
+
>>> xml = XML('''
|
46
|
+
... <AAA name="aaa">
|
47
|
+
... <BBB id="bbb"/>
|
48
|
+
... <CCC color="ccc"/>
|
49
|
+
... </AAA>
|
50
|
+
... ''')
|
51
|
+
|
52
|
+
>>> schematron.validate(xml)
|
53
|
+
0
|
54
|
+
|
55
|
+
>>> xml = XML('''
|
56
|
+
... <AAA id="aaa">
|
57
|
+
... <BBB id="bbb"/>
|
58
|
+
... <CCC/>
|
59
|
+
... </AAA>
|
60
|
+
... ''')
|
61
|
+
|
62
|
+
>>> schematron.validate(xml)
|
63
|
+
1
|
64
|
+
|
65
|
+
Schematron was added to libxml2 in version 2.6.21. Before version 2.6.32,
|
66
|
+
however, Schematron lacked support for error reporting other than to stderr.
|
67
|
+
This version is therefore required to retrieve validation warnings and
|
68
|
+
errors in lxml.
|
69
|
+
"""
|
70
|
+
cdef schematron.xmlSchematron* _c_schema
|
71
|
+
cdef xmlDoc* _c_schema_doc
|
72
|
+
|
73
|
+
def __init__(self, etree=None, *, file=None):
|
74
|
+
cdef _Document doc
|
75
|
+
cdef _Element root_node
|
76
|
+
cdef xmlNode* c_node
|
77
|
+
cdef char* c_href
|
78
|
+
cdef schematron.xmlSchematronParserCtxt* parser_ctxt = NULL
|
79
|
+
_Validator.__init__(self)
|
80
|
+
if not config.ENABLE_SCHEMATRON:
|
81
|
+
raise SchematronError, \
|
82
|
+
"lxml.etree was compiled without Schematron support."
|
83
|
+
|
84
|
+
import warnings
|
85
|
+
warnings.warn(
|
86
|
+
"The (non-ISO) Schematron feature is deprecated and will be removed from libxml2 and lxml. "
|
87
|
+
"Use 'lxml.isoschematron' instead.",
|
88
|
+
DeprecationWarning,
|
89
|
+
)
|
90
|
+
|
91
|
+
if etree is not None:
|
92
|
+
doc = _documentOrRaise(etree)
|
93
|
+
root_node = _rootNodeOrRaise(etree)
|
94
|
+
self._c_schema_doc = _copyDocRoot(doc._c_doc, root_node._c_node)
|
95
|
+
parser_ctxt = schematron.xmlSchematronNewDocParserCtxt(self._c_schema_doc)
|
96
|
+
elif file is not None:
|
97
|
+
filename = _getFilenameForFile(file)
|
98
|
+
if filename is None:
|
99
|
+
# XXX assume a string object
|
100
|
+
filename = file
|
101
|
+
filename = _encodeFilename(filename)
|
102
|
+
with self._error_log:
|
103
|
+
orig_loader = _register_document_loader()
|
104
|
+
parser_ctxt = schematron.xmlSchematronNewParserCtxt(_cstr(filename))
|
105
|
+
_reset_document_loader(orig_loader)
|
106
|
+
else:
|
107
|
+
raise SchematronParseError, "No tree or file given"
|
108
|
+
|
109
|
+
if parser_ctxt is NULL:
|
110
|
+
if self._c_schema_doc is not NULL:
|
111
|
+
tree.xmlFreeDoc(self._c_schema_doc)
|
112
|
+
self._c_schema_doc = NULL
|
113
|
+
raise MemoryError()
|
114
|
+
|
115
|
+
try:
|
116
|
+
with self._error_log:
|
117
|
+
orig_loader = _register_document_loader()
|
118
|
+
self._c_schema = schematron.xmlSchematronParse(parser_ctxt)
|
119
|
+
_reset_document_loader(orig_loader)
|
120
|
+
finally:
|
121
|
+
schematron.xmlSchematronFreeParserCtxt(parser_ctxt)
|
122
|
+
|
123
|
+
if self._c_schema is NULL:
|
124
|
+
raise SchematronParseError(
|
125
|
+
"Document is not a valid Schematron schema",
|
126
|
+
self._error_log)
|
127
|
+
|
128
|
+
def __dealloc__(self):
|
129
|
+
schematron.xmlSchematronFree(self._c_schema)
|
130
|
+
if self._c_schema_doc is not NULL:
|
131
|
+
tree.xmlFreeDoc(self._c_schema_doc)
|
132
|
+
|
133
|
+
def __call__(self, etree):
|
134
|
+
"""__call__(self, etree)
|
135
|
+
|
136
|
+
Validate doc using Schematron.
|
137
|
+
|
138
|
+
Returns true if document is valid, false if not."""
|
139
|
+
cdef _Document doc
|
140
|
+
cdef _Element root_node
|
141
|
+
cdef xmlDoc* c_doc
|
142
|
+
cdef schematron.xmlSchematronValidCtxt* valid_ctxt
|
143
|
+
cdef int ret
|
144
|
+
|
145
|
+
assert self._c_schema is not NULL, "Schematron instance not initialised"
|
146
|
+
doc = _documentOrRaise(etree)
|
147
|
+
root_node = _rootNodeOrRaise(etree)
|
148
|
+
|
149
|
+
valid_ctxt = schematron.xmlSchematronNewValidCtxt(
|
150
|
+
self._c_schema, schematron.XML_SCHEMATRON_OUT_ERROR)
|
151
|
+
if valid_ctxt is NULL:
|
152
|
+
raise MemoryError()
|
153
|
+
|
154
|
+
try:
|
155
|
+
self._error_log.clear()
|
156
|
+
# Need a cast here because older libxml2 releases do not use 'const' in the functype.
|
157
|
+
schematron.xmlSchematronSetValidStructuredErrors(
|
158
|
+
valid_ctxt, <xmlerror.xmlStructuredErrorFunc> _receiveError, <void*>self._error_log)
|
159
|
+
c_doc = _fakeRootDoc(doc._c_doc, root_node._c_node)
|
160
|
+
with nogil:
|
161
|
+
ret = schematron.xmlSchematronValidateDoc(valid_ctxt, c_doc)
|
162
|
+
_destroyFakeDoc(doc._c_doc, c_doc)
|
163
|
+
finally:
|
164
|
+
schematron.xmlSchematronFreeValidCtxt(valid_ctxt)
|
165
|
+
|
166
|
+
if ret == -1:
|
167
|
+
raise SchematronValidateError(
|
168
|
+
"Internal error in Schematron validation",
|
169
|
+
self._error_log)
|
170
|
+
if ret == 0:
|
171
|
+
return True
|
172
|
+
else:
|
173
|
+
return False
|