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/debug.pxi
CHANGED
@@ -1,90 +1,90 @@
|
|
1
|
-
@cython.final
|
2
|
-
@cython.internal
|
3
|
-
cdef class _MemDebug:
|
4
|
-
"""Debugging support for the memory allocation in libxml2.
|
5
|
-
"""
|
6
|
-
def bytes_used(self):
|
7
|
-
"""bytes_used(self)
|
8
|
-
|
9
|
-
Returns the total amount of memory (in bytes) currently used by libxml2.
|
10
|
-
Note that libxml2 constrains this value to a C int, which limits
|
11
|
-
the accuracy on 64 bit systems.
|
12
|
-
"""
|
13
|
-
return tree.xmlMemUsed()
|
14
|
-
|
15
|
-
def blocks_used(self):
|
16
|
-
"""blocks_used(self)
|
17
|
-
|
18
|
-
Returns the total number of memory blocks currently allocated by libxml2.
|
19
|
-
Note that libxml2 constrains this value to a C int, which limits
|
20
|
-
the accuracy on 64 bit systems.
|
21
|
-
"""
|
22
|
-
return tree.xmlMemBlocks()
|
23
|
-
|
24
|
-
def dict_size(self):
|
25
|
-
"""dict_size(self)
|
26
|
-
|
27
|
-
Returns the current size of the global name dictionary used by libxml2
|
28
|
-
for the current thread. Each thread has its own dictionary.
|
29
|
-
"""
|
30
|
-
c_dict = __GLOBAL_PARSER_CONTEXT._getThreadDict(NULL)
|
31
|
-
if c_dict is NULL:
|
32
|
-
raise MemoryError()
|
33
|
-
return tree.xmlDictSize(c_dict)
|
34
|
-
|
35
|
-
def dump(self, output_file=None, byte_count=None):
|
36
|
-
"""dump(self, output_file=None, byte_count=None)
|
37
|
-
|
38
|
-
Dumps the current memory blocks allocated by libxml2 to a file.
|
39
|
-
|
40
|
-
The optional parameter 'output_file' specifies the file path. It defaults
|
41
|
-
to the file ".memorylist" in the current directory.
|
42
|
-
|
43
|
-
The optional parameter 'byte_count' limits the number of bytes in the dump.
|
44
|
-
Note that this parameter is ignored when lxml is compiled against a libxml2
|
45
|
-
version before 2.7.0.
|
46
|
-
"""
|
47
|
-
cdef Py_ssize_t c_count
|
48
|
-
if output_file is None:
|
49
|
-
output_file = b'.memorylist'
|
50
|
-
elif isinstance(output_file, unicode):
|
51
|
-
output_file.encode(sys.getfilesystemencoding())
|
52
|
-
|
53
|
-
f = stdio.fopen(output_file, "w")
|
54
|
-
if f is NULL:
|
55
|
-
raise IOError(f"Failed to create file {output_file.decode(sys.getfilesystemencoding())}")
|
56
|
-
try:
|
57
|
-
if byte_count is None:
|
58
|
-
tree.xmlMemDisplay(f)
|
59
|
-
else:
|
60
|
-
c_count = byte_count
|
61
|
-
tree.xmlMemDisplayLast(f, c_count)
|
62
|
-
finally:
|
63
|
-
stdio.fclose(f)
|
64
|
-
|
65
|
-
def show(self, output_file=None, block_count=None):
|
66
|
-
"""show(self, output_file=None, block_count=None)
|
67
|
-
|
68
|
-
Dumps the current memory blocks allocated by libxml2 to a file.
|
69
|
-
The output file format is suitable for line diffing.
|
70
|
-
|
71
|
-
The optional parameter 'output_file' specifies the file path. It defaults
|
72
|
-
to the file ".memorydump" in the current directory.
|
73
|
-
|
74
|
-
The optional parameter 'block_count' limits the number of blocks
|
75
|
-
in the dump.
|
76
|
-
"""
|
77
|
-
if output_file is None:
|
78
|
-
output_file = b'.memorydump'
|
79
|
-
elif isinstance(output_file, unicode):
|
80
|
-
output_file.encode(sys.getfilesystemencoding())
|
81
|
-
|
82
|
-
f = stdio.fopen(output_file, "w")
|
83
|
-
if f is NULL:
|
84
|
-
raise IOError(f"Failed to create file {output_file.decode(sys.getfilesystemencoding())}")
|
85
|
-
try:
|
86
|
-
tree.xmlMemShow(f, block_count if block_count is not None else tree.xmlMemBlocks())
|
87
|
-
finally:
|
88
|
-
stdio.fclose(f)
|
89
|
-
|
90
|
-
memory_debugger = _MemDebug()
|
1
|
+
@cython.final
|
2
|
+
@cython.internal
|
3
|
+
cdef class _MemDebug:
|
4
|
+
"""Debugging support for the memory allocation in libxml2.
|
5
|
+
"""
|
6
|
+
def bytes_used(self):
|
7
|
+
"""bytes_used(self)
|
8
|
+
|
9
|
+
Returns the total amount of memory (in bytes) currently used by libxml2.
|
10
|
+
Note that libxml2 constrains this value to a C int, which limits
|
11
|
+
the accuracy on 64 bit systems.
|
12
|
+
"""
|
13
|
+
return tree.xmlMemUsed()
|
14
|
+
|
15
|
+
def blocks_used(self):
|
16
|
+
"""blocks_used(self)
|
17
|
+
|
18
|
+
Returns the total number of memory blocks currently allocated by libxml2.
|
19
|
+
Note that libxml2 constrains this value to a C int, which limits
|
20
|
+
the accuracy on 64 bit systems.
|
21
|
+
"""
|
22
|
+
return tree.xmlMemBlocks()
|
23
|
+
|
24
|
+
def dict_size(self):
|
25
|
+
"""dict_size(self)
|
26
|
+
|
27
|
+
Returns the current size of the global name dictionary used by libxml2
|
28
|
+
for the current thread. Each thread has its own dictionary.
|
29
|
+
"""
|
30
|
+
c_dict = __GLOBAL_PARSER_CONTEXT._getThreadDict(NULL)
|
31
|
+
if c_dict is NULL:
|
32
|
+
raise MemoryError()
|
33
|
+
return tree.xmlDictSize(c_dict)
|
34
|
+
|
35
|
+
def dump(self, output_file=None, byte_count=None):
|
36
|
+
"""dump(self, output_file=None, byte_count=None)
|
37
|
+
|
38
|
+
Dumps the current memory blocks allocated by libxml2 to a file.
|
39
|
+
|
40
|
+
The optional parameter 'output_file' specifies the file path. It defaults
|
41
|
+
to the file ".memorylist" in the current directory.
|
42
|
+
|
43
|
+
The optional parameter 'byte_count' limits the number of bytes in the dump.
|
44
|
+
Note that this parameter is ignored when lxml is compiled against a libxml2
|
45
|
+
version before 2.7.0.
|
46
|
+
"""
|
47
|
+
cdef Py_ssize_t c_count
|
48
|
+
if output_file is None:
|
49
|
+
output_file = b'.memorylist'
|
50
|
+
elif isinstance(output_file, unicode):
|
51
|
+
output_file.encode(sys.getfilesystemencoding())
|
52
|
+
|
53
|
+
f = stdio.fopen(output_file, "w")
|
54
|
+
if f is NULL:
|
55
|
+
raise IOError(f"Failed to create file {output_file.decode(sys.getfilesystemencoding())}")
|
56
|
+
try:
|
57
|
+
if byte_count is None:
|
58
|
+
tree.xmlMemDisplay(f)
|
59
|
+
else:
|
60
|
+
c_count = byte_count
|
61
|
+
tree.xmlMemDisplayLast(f, c_count)
|
62
|
+
finally:
|
63
|
+
stdio.fclose(f)
|
64
|
+
|
65
|
+
def show(self, output_file=None, block_count=None):
|
66
|
+
"""show(self, output_file=None, block_count=None)
|
67
|
+
|
68
|
+
Dumps the current memory blocks allocated by libxml2 to a file.
|
69
|
+
The output file format is suitable for line diffing.
|
70
|
+
|
71
|
+
The optional parameter 'output_file' specifies the file path. It defaults
|
72
|
+
to the file ".memorydump" in the current directory.
|
73
|
+
|
74
|
+
The optional parameter 'block_count' limits the number of blocks
|
75
|
+
in the dump.
|
76
|
+
"""
|
77
|
+
if output_file is None:
|
78
|
+
output_file = b'.memorydump'
|
79
|
+
elif isinstance(output_file, unicode):
|
80
|
+
output_file.encode(sys.getfilesystemencoding())
|
81
|
+
|
82
|
+
f = stdio.fopen(output_file, "w")
|
83
|
+
if f is NULL:
|
84
|
+
raise IOError(f"Failed to create file {output_file.decode(sys.getfilesystemencoding())}")
|
85
|
+
try:
|
86
|
+
tree.xmlMemShow(f, block_count if block_count is not None else tree.xmlMemBlocks())
|
87
|
+
finally:
|
88
|
+
stdio.fclose(f)
|
89
|
+
|
90
|
+
memory_debugger = _MemDebug()
|
lxml/docloader.pxi
CHANGED
@@ -1,178 +1,178 @@
|
|
1
|
-
# Custom resolver API
|
2
|
-
|
3
|
-
ctypedef enum _InputDocumentDataType:
|
4
|
-
PARSER_DATA_INVALID
|
5
|
-
PARSER_DATA_EMPTY
|
6
|
-
PARSER_DATA_STRING
|
7
|
-
PARSER_DATA_FILENAME
|
8
|
-
PARSER_DATA_FILE
|
9
|
-
|
10
|
-
@cython.final
|
11
|
-
@cython.internal
|
12
|
-
cdef class _InputDocument:
|
13
|
-
cdef _InputDocumentDataType _type
|
14
|
-
cdef bytes _data_bytes
|
15
|
-
cdef object _filename
|
16
|
-
cdef object _file
|
17
|
-
cdef bint _close_file
|
18
|
-
|
19
|
-
def __cinit__(self):
|
20
|
-
self._type = PARSER_DATA_INVALID
|
21
|
-
|
22
|
-
|
23
|
-
cdef class Resolver:
|
24
|
-
"This is the base class of all resolvers."
|
25
|
-
def resolve(self, system_url, public_id, context):
|
26
|
-
"""resolve(self, system_url, public_id, context)
|
27
|
-
|
28
|
-
Override this method to resolve an external source by
|
29
|
-
``system_url`` and ``public_id``. The third argument is an
|
30
|
-
opaque context object.
|
31
|
-
|
32
|
-
Return the result of one of the ``resolve_*()`` methods.
|
33
|
-
"""
|
34
|
-
return None
|
35
|
-
|
36
|
-
def resolve_empty(self, context):
|
37
|
-
"""resolve_empty(self, context)
|
38
|
-
|
39
|
-
Return an empty input document.
|
40
|
-
|
41
|
-
Pass context as parameter.
|
42
|
-
"""
|
43
|
-
cdef _InputDocument doc_ref
|
44
|
-
doc_ref = _InputDocument()
|
45
|
-
doc_ref._type = PARSER_DATA_EMPTY
|
46
|
-
return doc_ref
|
47
|
-
|
48
|
-
def resolve_string(self, string, context, *, base_url=None):
|
49
|
-
"""resolve_string(self, string, context, base_url=None)
|
50
|
-
|
51
|
-
Return a parsable string as input document.
|
52
|
-
|
53
|
-
Pass data string and context as parameters. You can pass the
|
54
|
-
source URL or filename through the ``base_url`` keyword
|
55
|
-
argument.
|
56
|
-
"""
|
57
|
-
cdef _InputDocument doc_ref
|
58
|
-
if isinstance(string, unicode):
|
59
|
-
string = (<unicode>string).encode('utf8')
|
60
|
-
elif not isinstance(string, bytes):
|
61
|
-
raise TypeError, "argument must be a byte string or unicode string"
|
62
|
-
doc_ref = _InputDocument()
|
63
|
-
doc_ref._type = PARSER_DATA_STRING
|
64
|
-
doc_ref._data_bytes = string
|
65
|
-
if base_url is not None:
|
66
|
-
doc_ref._filename = _encodeFilename(base_url)
|
67
|
-
return doc_ref
|
68
|
-
|
69
|
-
def resolve_filename(self, filename, context):
|
70
|
-
"""resolve_filename(self, filename, context)
|
71
|
-
|
72
|
-
Return the name of a parsable file as input document.
|
73
|
-
|
74
|
-
Pass filename and context as parameters. You can also pass a
|
75
|
-
URL with an HTTP, FTP or file target.
|
76
|
-
"""
|
77
|
-
cdef _InputDocument doc_ref
|
78
|
-
doc_ref = _InputDocument()
|
79
|
-
doc_ref._type = PARSER_DATA_FILENAME
|
80
|
-
doc_ref._filename = _encodeFilename(filename)
|
81
|
-
return doc_ref
|
82
|
-
|
83
|
-
def resolve_file(self, f, context, *, base_url=None, bint close=True):
|
84
|
-
"""resolve_file(self, f, context, base_url=None, close=True)
|
85
|
-
|
86
|
-
Return an open file-like object as input document.
|
87
|
-
|
88
|
-
Pass open file and context as parameters. You can pass the
|
89
|
-
base URL or filename of the file through the ``base_url``
|
90
|
-
keyword argument. If the ``close`` flag is True (the
|
91
|
-
default), the file will be closed after reading.
|
92
|
-
|
93
|
-
Note that using ``.resolve_filename()`` is more efficient,
|
94
|
-
especially in threaded environments.
|
95
|
-
"""
|
96
|
-
cdef _InputDocument doc_ref
|
97
|
-
try:
|
98
|
-
f.read
|
99
|
-
except AttributeError:
|
100
|
-
raise TypeError, "Argument is not a file-like object"
|
101
|
-
doc_ref = _InputDocument()
|
102
|
-
doc_ref._type = PARSER_DATA_FILE
|
103
|
-
if base_url is not None:
|
104
|
-
doc_ref._filename = _encodeFilename(base_url)
|
105
|
-
else:
|
106
|
-
doc_ref._filename = _getFilenameForFile(f)
|
107
|
-
doc_ref._close_file = close
|
108
|
-
doc_ref._file = f
|
109
|
-
return doc_ref
|
110
|
-
|
111
|
-
@cython.final
|
112
|
-
@cython.internal
|
113
|
-
cdef class _ResolverRegistry:
|
114
|
-
cdef object _resolvers
|
115
|
-
cdef Resolver _default_resolver
|
116
|
-
def __cinit__(self, Resolver default_resolver=None):
|
117
|
-
self._resolvers = set()
|
118
|
-
self._default_resolver = default_resolver
|
119
|
-
|
120
|
-
def add(self, Resolver resolver not None):
|
121
|
-
"""add(self, resolver)
|
122
|
-
|
123
|
-
Register a resolver.
|
124
|
-
|
125
|
-
For each requested entity, the 'resolve' method of the resolver will
|
126
|
-
be called and the result will be passed to the parser. If this method
|
127
|
-
returns None, the request will be delegated to other resolvers or the
|
128
|
-
default resolver. The resolvers will be tested in an arbitrary order
|
129
|
-
until the first match is found.
|
130
|
-
"""
|
131
|
-
self._resolvers.add(resolver)
|
132
|
-
|
133
|
-
def remove(self, resolver):
|
134
|
-
"remove(self, resolver)"
|
135
|
-
self._resolvers.discard(resolver)
|
136
|
-
|
137
|
-
cdef _ResolverRegistry _copy(self):
|
138
|
-
cdef _ResolverRegistry registry
|
139
|
-
registry = _ResolverRegistry(self._default_resolver)
|
140
|
-
registry._resolvers = self._resolvers.copy()
|
141
|
-
return registry
|
142
|
-
|
143
|
-
def copy(self):
|
144
|
-
"copy(self)"
|
145
|
-
return self._copy()
|
146
|
-
|
147
|
-
def resolve(self, system_url, public_id, context):
|
148
|
-
"resolve(self, system_url, public_id, context)"
|
149
|
-
for resolver in self._resolvers:
|
150
|
-
result = resolver.resolve(system_url, public_id, context)
|
151
|
-
if result is not None:
|
152
|
-
return result
|
153
|
-
if self._default_resolver is None:
|
154
|
-
return None
|
155
|
-
return self._default_resolver.resolve(system_url, public_id, context)
|
156
|
-
|
157
|
-
def __repr__(self):
|
158
|
-
return repr(self._resolvers)
|
159
|
-
|
160
|
-
|
161
|
-
@cython.internal
|
162
|
-
cdef class _ResolverContext(_ExceptionContext):
|
163
|
-
cdef _ResolverRegistry _resolvers
|
164
|
-
cdef _TempStore _storage
|
165
|
-
|
166
|
-
cdef int clear(self) except -1:
|
167
|
-
_ExceptionContext.clear(self)
|
168
|
-
self._storage.clear()
|
169
|
-
return 0
|
170
|
-
|
171
|
-
|
172
|
-
cdef _initResolverContext(_ResolverContext context,
|
173
|
-
_ResolverRegistry resolvers):
|
174
|
-
if resolvers is None:
|
175
|
-
context._resolvers = _ResolverRegistry()
|
176
|
-
else:
|
177
|
-
context._resolvers = resolvers
|
178
|
-
context._storage = _TempStore()
|
1
|
+
# Custom resolver API
|
2
|
+
|
3
|
+
ctypedef enum _InputDocumentDataType:
|
4
|
+
PARSER_DATA_INVALID
|
5
|
+
PARSER_DATA_EMPTY
|
6
|
+
PARSER_DATA_STRING
|
7
|
+
PARSER_DATA_FILENAME
|
8
|
+
PARSER_DATA_FILE
|
9
|
+
|
10
|
+
@cython.final
|
11
|
+
@cython.internal
|
12
|
+
cdef class _InputDocument:
|
13
|
+
cdef _InputDocumentDataType _type
|
14
|
+
cdef bytes _data_bytes
|
15
|
+
cdef object _filename
|
16
|
+
cdef object _file
|
17
|
+
cdef bint _close_file
|
18
|
+
|
19
|
+
def __cinit__(self):
|
20
|
+
self._type = PARSER_DATA_INVALID
|
21
|
+
|
22
|
+
|
23
|
+
cdef class Resolver:
|
24
|
+
"This is the base class of all resolvers."
|
25
|
+
def resolve(self, system_url, public_id, context):
|
26
|
+
"""resolve(self, system_url, public_id, context)
|
27
|
+
|
28
|
+
Override this method to resolve an external source by
|
29
|
+
``system_url`` and ``public_id``. The third argument is an
|
30
|
+
opaque context object.
|
31
|
+
|
32
|
+
Return the result of one of the ``resolve_*()`` methods.
|
33
|
+
"""
|
34
|
+
return None
|
35
|
+
|
36
|
+
def resolve_empty(self, context):
|
37
|
+
"""resolve_empty(self, context)
|
38
|
+
|
39
|
+
Return an empty input document.
|
40
|
+
|
41
|
+
Pass context as parameter.
|
42
|
+
"""
|
43
|
+
cdef _InputDocument doc_ref
|
44
|
+
doc_ref = _InputDocument()
|
45
|
+
doc_ref._type = PARSER_DATA_EMPTY
|
46
|
+
return doc_ref
|
47
|
+
|
48
|
+
def resolve_string(self, string, context, *, base_url=None):
|
49
|
+
"""resolve_string(self, string, context, base_url=None)
|
50
|
+
|
51
|
+
Return a parsable string as input document.
|
52
|
+
|
53
|
+
Pass data string and context as parameters. You can pass the
|
54
|
+
source URL or filename through the ``base_url`` keyword
|
55
|
+
argument.
|
56
|
+
"""
|
57
|
+
cdef _InputDocument doc_ref
|
58
|
+
if isinstance(string, unicode):
|
59
|
+
string = (<unicode>string).encode('utf8')
|
60
|
+
elif not isinstance(string, bytes):
|
61
|
+
raise TypeError, "argument must be a byte string or unicode string"
|
62
|
+
doc_ref = _InputDocument()
|
63
|
+
doc_ref._type = PARSER_DATA_STRING
|
64
|
+
doc_ref._data_bytes = string
|
65
|
+
if base_url is not None:
|
66
|
+
doc_ref._filename = _encodeFilename(base_url)
|
67
|
+
return doc_ref
|
68
|
+
|
69
|
+
def resolve_filename(self, filename, context):
|
70
|
+
"""resolve_filename(self, filename, context)
|
71
|
+
|
72
|
+
Return the name of a parsable file as input document.
|
73
|
+
|
74
|
+
Pass filename and context as parameters. You can also pass a
|
75
|
+
URL with an HTTP, FTP or file target.
|
76
|
+
"""
|
77
|
+
cdef _InputDocument doc_ref
|
78
|
+
doc_ref = _InputDocument()
|
79
|
+
doc_ref._type = PARSER_DATA_FILENAME
|
80
|
+
doc_ref._filename = _encodeFilename(filename)
|
81
|
+
return doc_ref
|
82
|
+
|
83
|
+
def resolve_file(self, f, context, *, base_url=None, bint close=True):
|
84
|
+
"""resolve_file(self, f, context, base_url=None, close=True)
|
85
|
+
|
86
|
+
Return an open file-like object as input document.
|
87
|
+
|
88
|
+
Pass open file and context as parameters. You can pass the
|
89
|
+
base URL or filename of the file through the ``base_url``
|
90
|
+
keyword argument. If the ``close`` flag is True (the
|
91
|
+
default), the file will be closed after reading.
|
92
|
+
|
93
|
+
Note that using ``.resolve_filename()`` is more efficient,
|
94
|
+
especially in threaded environments.
|
95
|
+
"""
|
96
|
+
cdef _InputDocument doc_ref
|
97
|
+
try:
|
98
|
+
f.read
|
99
|
+
except AttributeError:
|
100
|
+
raise TypeError, "Argument is not a file-like object"
|
101
|
+
doc_ref = _InputDocument()
|
102
|
+
doc_ref._type = PARSER_DATA_FILE
|
103
|
+
if base_url is not None:
|
104
|
+
doc_ref._filename = _encodeFilename(base_url)
|
105
|
+
else:
|
106
|
+
doc_ref._filename = _getFilenameForFile(f)
|
107
|
+
doc_ref._close_file = close
|
108
|
+
doc_ref._file = f
|
109
|
+
return doc_ref
|
110
|
+
|
111
|
+
@cython.final
|
112
|
+
@cython.internal
|
113
|
+
cdef class _ResolverRegistry:
|
114
|
+
cdef object _resolvers
|
115
|
+
cdef Resolver _default_resolver
|
116
|
+
def __cinit__(self, Resolver default_resolver=None):
|
117
|
+
self._resolvers = set()
|
118
|
+
self._default_resolver = default_resolver
|
119
|
+
|
120
|
+
def add(self, Resolver resolver not None):
|
121
|
+
"""add(self, resolver)
|
122
|
+
|
123
|
+
Register a resolver.
|
124
|
+
|
125
|
+
For each requested entity, the 'resolve' method of the resolver will
|
126
|
+
be called and the result will be passed to the parser. If this method
|
127
|
+
returns None, the request will be delegated to other resolvers or the
|
128
|
+
default resolver. The resolvers will be tested in an arbitrary order
|
129
|
+
until the first match is found.
|
130
|
+
"""
|
131
|
+
self._resolvers.add(resolver)
|
132
|
+
|
133
|
+
def remove(self, resolver):
|
134
|
+
"remove(self, resolver)"
|
135
|
+
self._resolvers.discard(resolver)
|
136
|
+
|
137
|
+
cdef _ResolverRegistry _copy(self):
|
138
|
+
cdef _ResolverRegistry registry
|
139
|
+
registry = _ResolverRegistry(self._default_resolver)
|
140
|
+
registry._resolvers = self._resolvers.copy()
|
141
|
+
return registry
|
142
|
+
|
143
|
+
def copy(self):
|
144
|
+
"copy(self)"
|
145
|
+
return self._copy()
|
146
|
+
|
147
|
+
def resolve(self, system_url, public_id, context):
|
148
|
+
"resolve(self, system_url, public_id, context)"
|
149
|
+
for resolver in self._resolvers:
|
150
|
+
result = resolver.resolve(system_url, public_id, context)
|
151
|
+
if result is not None:
|
152
|
+
return result
|
153
|
+
if self._default_resolver is None:
|
154
|
+
return None
|
155
|
+
return self._default_resolver.resolve(system_url, public_id, context)
|
156
|
+
|
157
|
+
def __repr__(self):
|
158
|
+
return repr(self._resolvers)
|
159
|
+
|
160
|
+
|
161
|
+
@cython.internal
|
162
|
+
cdef class _ResolverContext(_ExceptionContext):
|
163
|
+
cdef _ResolverRegistry _resolvers
|
164
|
+
cdef _TempStore _storage
|
165
|
+
|
166
|
+
cdef int clear(self) except -1:
|
167
|
+
_ExceptionContext.clear(self)
|
168
|
+
self._storage.clear()
|
169
|
+
return 0
|
170
|
+
|
171
|
+
|
172
|
+
cdef _initResolverContext(_ResolverContext context,
|
173
|
+
_ResolverRegistry resolvers):
|
174
|
+
if resolvers is None:
|
175
|
+
context._resolvers = _ResolverRegistry()
|
176
|
+
else:
|
177
|
+
context._resolvers = resolvers
|
178
|
+
context._storage = _TempStore()
|