Datasets:
Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +4 -0
- material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908250/1908251.tif +3 -0
- material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908272/1908273.tif +3 -0
- material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908302/1908303.tif +3 -0
- material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908324/1908325.tif +3 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/__init__.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_ihatexml.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_inputstream.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_tokenizer.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_utils.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/html5parser.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/serializer.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/filters/alphabeticalattributes.py +29 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/filters/inject_meta_charset.py +73 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__init__.py +88 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/__init__.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/base.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/dom.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/etree.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/etree_lxml.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/base.py +417 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/dom.py +239 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/etree.py +343 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.py +392 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__init__.py +154 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/__init__.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/base.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/dom.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/etree.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/etree_lxml.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/genshi.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/base.py +252 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/dom.py +43 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/etree.py +131 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/etree_lxml.py +215 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/genshi.py +69 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__init__.py +331 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__main__.py +46 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/__main__.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/api.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/version.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/windows.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/android.py +119 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/api.py +156 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/macos.py +64 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/version.py +4 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__init__.py +154 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/api.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/auth.cpython-310.pyc +0 -0
- material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/certs.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -350,3 +350,7 @@ material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:
|
|
| 350 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908258/1908258.tif filter=lfs diff=lfs merge=lfs -text
|
| 351 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908270/1908270.tif filter=lfs diff=lfs merge=lfs -text
|
| 352 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Images/TSEM/1908289.tif filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908258/1908258.tif filter=lfs diff=lfs merge=lfs -text
|
| 351 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908270/1908270.tif filter=lfs diff=lfs merge=lfs -text
|
| 352 |
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Images/TSEM/1908289.tif filter=lfs diff=lfs merge=lfs -text
|
| 353 |
+
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908250/1908251.tif filter=lfs diff=lfs merge=lfs -text
|
| 354 |
+
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908324/1908325.tif filter=lfs diff=lfs merge=lfs -text
|
| 355 |
+
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908302/1908303.tif filter=lfs diff=lfs merge=lfs -text
|
| 356 |
+
material/dataset/Datasets/Electron[[:space:]]Microscopy[[:space:]]Image[[:space:]]Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908272/1908273.tif filter=lfs diff=lfs merge=lfs -text
|
material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908250/1908251.tif
ADDED
|
|
Git LFS Details
|
material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908272/1908273.tif
ADDED
|
|
Git LFS Details
|
material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908302/1908303.tif
ADDED
|
|
Git LFS Details
|
material/dataset/Datasets/Electron Microscopy Image Masks/TiO2_Masks_TSEM/Image_Registration/Input/1908324/1908325.tif
ADDED
|
|
Git LFS Details
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (1.35 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_ihatexml.cpython-310.pyc
ADDED
|
Binary file (13.9 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_inputstream.cpython-310.pyc
ADDED
|
Binary file (21.7 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_tokenizer.cpython-310.pyc
ADDED
|
Binary file (37.4 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/_utils.cpython-310.pyc
ADDED
|
Binary file (4.85 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/html5parser.cpython-310.pyc
ADDED
|
Binary file (88.5 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/__pycache__/serializer.cpython-310.pyc
ADDED
|
Binary file (10.8 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/filters/alphabeticalattributes.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from . import base
|
| 4 |
+
|
| 5 |
+
from collections import OrderedDict
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _attr_key(attr):
|
| 9 |
+
"""Return an appropriate key for an attribute for sorting
|
| 10 |
+
|
| 11 |
+
Attributes have a namespace that can be either ``None`` or a string. We
|
| 12 |
+
can't compare the two because they're different types, so we convert
|
| 13 |
+
``None`` to an empty string first.
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
return (attr[0][0] or ''), attr[0][1]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class Filter(base.Filter):
|
| 20 |
+
"""Alphabetizes attributes for elements"""
|
| 21 |
+
def __iter__(self):
|
| 22 |
+
for token in base.Filter.__iter__(self):
|
| 23 |
+
if token["type"] in ("StartTag", "EmptyTag"):
|
| 24 |
+
attrs = OrderedDict()
|
| 25 |
+
for name, value in sorted(token["data"].items(),
|
| 26 |
+
key=_attr_key):
|
| 27 |
+
attrs[name] = value
|
| 28 |
+
token["data"] = attrs
|
| 29 |
+
yield token
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/filters/inject_meta_charset.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from . import base
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Filter(base.Filter):
|
| 7 |
+
"""Injects ``<meta charset=ENCODING>`` tag into head of document"""
|
| 8 |
+
def __init__(self, source, encoding):
|
| 9 |
+
"""Creates a Filter
|
| 10 |
+
|
| 11 |
+
:arg source: the source token stream
|
| 12 |
+
|
| 13 |
+
:arg encoding: the encoding to set
|
| 14 |
+
|
| 15 |
+
"""
|
| 16 |
+
base.Filter.__init__(self, source)
|
| 17 |
+
self.encoding = encoding
|
| 18 |
+
|
| 19 |
+
def __iter__(self):
|
| 20 |
+
state = "pre_head"
|
| 21 |
+
meta_found = (self.encoding is None)
|
| 22 |
+
pending = []
|
| 23 |
+
|
| 24 |
+
for token in base.Filter.__iter__(self):
|
| 25 |
+
type = token["type"]
|
| 26 |
+
if type == "StartTag":
|
| 27 |
+
if token["name"].lower() == "head":
|
| 28 |
+
state = "in_head"
|
| 29 |
+
|
| 30 |
+
elif type == "EmptyTag":
|
| 31 |
+
if token["name"].lower() == "meta":
|
| 32 |
+
# replace charset with actual encoding
|
| 33 |
+
has_http_equiv_content_type = False
|
| 34 |
+
for (namespace, name), value in token["data"].items():
|
| 35 |
+
if namespace is not None:
|
| 36 |
+
continue
|
| 37 |
+
elif name.lower() == 'charset':
|
| 38 |
+
token["data"][(namespace, name)] = self.encoding
|
| 39 |
+
meta_found = True
|
| 40 |
+
break
|
| 41 |
+
elif name == 'http-equiv' and value.lower() == 'content-type':
|
| 42 |
+
has_http_equiv_content_type = True
|
| 43 |
+
else:
|
| 44 |
+
if has_http_equiv_content_type and (None, "content") in token["data"]:
|
| 45 |
+
token["data"][(None, "content")] = 'text/html; charset=%s' % self.encoding
|
| 46 |
+
meta_found = True
|
| 47 |
+
|
| 48 |
+
elif token["name"].lower() == "head" and not meta_found:
|
| 49 |
+
# insert meta into empty head
|
| 50 |
+
yield {"type": "StartTag", "name": "head",
|
| 51 |
+
"data": token["data"]}
|
| 52 |
+
yield {"type": "EmptyTag", "name": "meta",
|
| 53 |
+
"data": {(None, "charset"): self.encoding}}
|
| 54 |
+
yield {"type": "EndTag", "name": "head"}
|
| 55 |
+
meta_found = True
|
| 56 |
+
continue
|
| 57 |
+
|
| 58 |
+
elif type == "EndTag":
|
| 59 |
+
if token["name"].lower() == "head" and pending:
|
| 60 |
+
# insert meta into head (if necessary) and flush pending queue
|
| 61 |
+
yield pending.pop(0)
|
| 62 |
+
if not meta_found:
|
| 63 |
+
yield {"type": "EmptyTag", "name": "meta",
|
| 64 |
+
"data": {(None, "charset"): self.encoding}}
|
| 65 |
+
while pending:
|
| 66 |
+
yield pending.pop(0)
|
| 67 |
+
meta_found = True
|
| 68 |
+
state = "post_head"
|
| 69 |
+
|
| 70 |
+
if state == "in_head":
|
| 71 |
+
pending.append(token)
|
| 72 |
+
else:
|
| 73 |
+
yield token
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__init__.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A collection of modules for building different kinds of trees from HTML
|
| 2 |
+
documents.
|
| 3 |
+
|
| 4 |
+
To create a treebuilder for a new type of tree, you need to do
|
| 5 |
+
implement several things:
|
| 6 |
+
|
| 7 |
+
1. A set of classes for various types of elements: Document, Doctype, Comment,
|
| 8 |
+
Element. These must implement the interface of ``base.treebuilders.Node``
|
| 9 |
+
(although comment nodes have a different signature for their constructor,
|
| 10 |
+
see ``treebuilders.etree.Comment``) Textual content may also be implemented
|
| 11 |
+
as another node type, or not, as your tree implementation requires.
|
| 12 |
+
|
| 13 |
+
2. A treebuilder object (called ``TreeBuilder`` by convention) that inherits
|
| 14 |
+
from ``treebuilders.base.TreeBuilder``. This has 4 required attributes:
|
| 15 |
+
|
| 16 |
+
* ``documentClass`` - the class to use for the bottommost node of a document
|
| 17 |
+
* ``elementClass`` - the class to use for HTML Elements
|
| 18 |
+
* ``commentClass`` - the class to use for comments
|
| 19 |
+
* ``doctypeClass`` - the class to use for doctypes
|
| 20 |
+
|
| 21 |
+
It also has one required method:
|
| 22 |
+
|
| 23 |
+
* ``getDocument`` - Returns the root node of the complete document tree
|
| 24 |
+
|
| 25 |
+
3. If you wish to run the unit tests, you must also create a ``testSerializer``
|
| 26 |
+
method on your treebuilder which accepts a node and returns a string
|
| 27 |
+
containing Node and its children serialized according to the format used in
|
| 28 |
+
the unittests
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 33 |
+
|
| 34 |
+
from .._utils import default_etree
|
| 35 |
+
|
| 36 |
+
treeBuilderCache = {}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def getTreeBuilder(treeType, implementation=None, **kwargs):
|
| 40 |
+
"""Get a TreeBuilder class for various types of trees with built-in support
|
| 41 |
+
|
| 42 |
+
:arg treeType: the name of the tree type required (case-insensitive). Supported
|
| 43 |
+
values are:
|
| 44 |
+
|
| 45 |
+
* "dom" - A generic builder for DOM implementations, defaulting to a
|
| 46 |
+
xml.dom.minidom based implementation.
|
| 47 |
+
* "etree" - A generic builder for tree implementations exposing an
|
| 48 |
+
ElementTree-like interface, defaulting to xml.etree.cElementTree if
|
| 49 |
+
available and xml.etree.ElementTree if not.
|
| 50 |
+
* "lxml" - A etree-based builder for lxml.etree, handling limitations
|
| 51 |
+
of lxml's implementation.
|
| 52 |
+
|
| 53 |
+
:arg implementation: (Currently applies to the "etree" and "dom" tree
|
| 54 |
+
types). A module implementing the tree type e.g. xml.etree.ElementTree
|
| 55 |
+
or xml.etree.cElementTree.
|
| 56 |
+
|
| 57 |
+
:arg kwargs: Any additional options to pass to the TreeBuilder when
|
| 58 |
+
creating it.
|
| 59 |
+
|
| 60 |
+
Example:
|
| 61 |
+
|
| 62 |
+
>>> from html5lib.treebuilders import getTreeBuilder
|
| 63 |
+
>>> builder = getTreeBuilder('etree')
|
| 64 |
+
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
treeType = treeType.lower()
|
| 68 |
+
if treeType not in treeBuilderCache:
|
| 69 |
+
if treeType == "dom":
|
| 70 |
+
from . import dom
|
| 71 |
+
# Come up with a sane default (pref. from the stdlib)
|
| 72 |
+
if implementation is None:
|
| 73 |
+
from xml.dom import minidom
|
| 74 |
+
implementation = minidom
|
| 75 |
+
# NEVER cache here, caching is done in the dom submodule
|
| 76 |
+
return dom.getDomModule(implementation, **kwargs).TreeBuilder
|
| 77 |
+
elif treeType == "lxml":
|
| 78 |
+
from . import etree_lxml
|
| 79 |
+
treeBuilderCache[treeType] = etree_lxml.TreeBuilder
|
| 80 |
+
elif treeType == "etree":
|
| 81 |
+
from . import etree
|
| 82 |
+
if implementation is None:
|
| 83 |
+
implementation = default_etree
|
| 84 |
+
# NEVER cache here, caching is done in the etree submodule
|
| 85 |
+
return etree.getETreeModule(implementation, **kwargs).TreeBuilder
|
| 86 |
+
else:
|
| 87 |
+
raise ValueError("""Unrecognised treebuilder "%s" """ % treeType)
|
| 88 |
+
return treeBuilderCache.get(treeType)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (3.38 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/dom.cpython-310.pyc
ADDED
|
Binary file (9.46 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/etree.cpython-310.pyc
ADDED
|
Binary file (11.8 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/__pycache__/etree_lxml.cpython-310.pyc
ADDED
|
Binary file (13.1 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/base.py
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
from pip._vendor.six import text_type
|
| 3 |
+
|
| 4 |
+
from ..constants import scopingElements, tableInsertModeElements, namespaces
|
| 5 |
+
|
| 6 |
+
# The scope markers are inserted when entering object elements,
|
| 7 |
+
# marquees, table cells, and table captions, and are used to prevent formatting
|
| 8 |
+
# from "leaking" into tables, object elements, and marquees.
|
| 9 |
+
Marker = None
|
| 10 |
+
|
| 11 |
+
listElementsMap = {
|
| 12 |
+
None: (frozenset(scopingElements), False),
|
| 13 |
+
"button": (frozenset(scopingElements | {(namespaces["html"], "button")}), False),
|
| 14 |
+
"list": (frozenset(scopingElements | {(namespaces["html"], "ol"),
|
| 15 |
+
(namespaces["html"], "ul")}), False),
|
| 16 |
+
"table": (frozenset([(namespaces["html"], "html"),
|
| 17 |
+
(namespaces["html"], "table")]), False),
|
| 18 |
+
"select": (frozenset([(namespaces["html"], "optgroup"),
|
| 19 |
+
(namespaces["html"], "option")]), True)
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Node(object):
|
| 24 |
+
"""Represents an item in the tree"""
|
| 25 |
+
def __init__(self, name):
|
| 26 |
+
"""Creates a Node
|
| 27 |
+
|
| 28 |
+
:arg name: The tag name associated with the node
|
| 29 |
+
|
| 30 |
+
"""
|
| 31 |
+
# The tag name associated with the node
|
| 32 |
+
self.name = name
|
| 33 |
+
# The parent of the current node (or None for the document node)
|
| 34 |
+
self.parent = None
|
| 35 |
+
# The value of the current node (applies to text nodes and comments)
|
| 36 |
+
self.value = None
|
| 37 |
+
# A dict holding name -> value pairs for attributes of the node
|
| 38 |
+
self.attributes = {}
|
| 39 |
+
# A list of child nodes of the current node. This must include all
|
| 40 |
+
# elements but not necessarily other node types.
|
| 41 |
+
self.childNodes = []
|
| 42 |
+
# A list of miscellaneous flags that can be set on the node.
|
| 43 |
+
self._flags = []
|
| 44 |
+
|
| 45 |
+
def __str__(self):
|
| 46 |
+
attributesStr = " ".join(["%s=\"%s\"" % (name, value)
|
| 47 |
+
for name, value in
|
| 48 |
+
self.attributes.items()])
|
| 49 |
+
if attributesStr:
|
| 50 |
+
return "<%s %s>" % (self.name, attributesStr)
|
| 51 |
+
else:
|
| 52 |
+
return "<%s>" % (self.name)
|
| 53 |
+
|
| 54 |
+
def __repr__(self):
|
| 55 |
+
return "<%s>" % (self.name)
|
| 56 |
+
|
| 57 |
+
def appendChild(self, node):
|
| 58 |
+
"""Insert node as a child of the current node
|
| 59 |
+
|
| 60 |
+
:arg node: the node to insert
|
| 61 |
+
|
| 62 |
+
"""
|
| 63 |
+
raise NotImplementedError
|
| 64 |
+
|
| 65 |
+
def insertText(self, data, insertBefore=None):
|
| 66 |
+
"""Insert data as text in the current node, positioned before the
|
| 67 |
+
start of node insertBefore or to the end of the node's text.
|
| 68 |
+
|
| 69 |
+
:arg data: the data to insert
|
| 70 |
+
|
| 71 |
+
:arg insertBefore: True if you want to insert the text before the node
|
| 72 |
+
and False if you want to insert it after the node
|
| 73 |
+
|
| 74 |
+
"""
|
| 75 |
+
raise NotImplementedError
|
| 76 |
+
|
| 77 |
+
def insertBefore(self, node, refNode):
|
| 78 |
+
"""Insert node as a child of the current node, before refNode in the
|
| 79 |
+
list of child nodes. Raises ValueError if refNode is not a child of
|
| 80 |
+
the current node
|
| 81 |
+
|
| 82 |
+
:arg node: the node to insert
|
| 83 |
+
|
| 84 |
+
:arg refNode: the child node to insert the node before
|
| 85 |
+
|
| 86 |
+
"""
|
| 87 |
+
raise NotImplementedError
|
| 88 |
+
|
| 89 |
+
def removeChild(self, node):
|
| 90 |
+
"""Remove node from the children of the current node
|
| 91 |
+
|
| 92 |
+
:arg node: the child node to remove
|
| 93 |
+
|
| 94 |
+
"""
|
| 95 |
+
raise NotImplementedError
|
| 96 |
+
|
| 97 |
+
def reparentChildren(self, newParent):
|
| 98 |
+
"""Move all the children of the current node to newParent.
|
| 99 |
+
This is needed so that trees that don't store text as nodes move the
|
| 100 |
+
text in the correct way
|
| 101 |
+
|
| 102 |
+
:arg newParent: the node to move all this node's children to
|
| 103 |
+
|
| 104 |
+
"""
|
| 105 |
+
# XXX - should this method be made more general?
|
| 106 |
+
for child in self.childNodes:
|
| 107 |
+
newParent.appendChild(child)
|
| 108 |
+
self.childNodes = []
|
| 109 |
+
|
| 110 |
+
def cloneNode(self):
|
| 111 |
+
"""Return a shallow copy of the current node i.e. a node with the same
|
| 112 |
+
name and attributes but with no parent or child nodes
|
| 113 |
+
"""
|
| 114 |
+
raise NotImplementedError
|
| 115 |
+
|
| 116 |
+
def hasContent(self):
|
| 117 |
+
"""Return true if the node has children or text, false otherwise
|
| 118 |
+
"""
|
| 119 |
+
raise NotImplementedError
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
class ActiveFormattingElements(list):
|
| 123 |
+
def append(self, node):
|
| 124 |
+
equalCount = 0
|
| 125 |
+
if node != Marker:
|
| 126 |
+
for element in self[::-1]:
|
| 127 |
+
if element == Marker:
|
| 128 |
+
break
|
| 129 |
+
if self.nodesEqual(element, node):
|
| 130 |
+
equalCount += 1
|
| 131 |
+
if equalCount == 3:
|
| 132 |
+
self.remove(element)
|
| 133 |
+
break
|
| 134 |
+
list.append(self, node)
|
| 135 |
+
|
| 136 |
+
def nodesEqual(self, node1, node2):
|
| 137 |
+
if not node1.nameTuple == node2.nameTuple:
|
| 138 |
+
return False
|
| 139 |
+
|
| 140 |
+
if not node1.attributes == node2.attributes:
|
| 141 |
+
return False
|
| 142 |
+
|
| 143 |
+
return True
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class TreeBuilder(object):
|
| 147 |
+
"""Base treebuilder implementation
|
| 148 |
+
|
| 149 |
+
* documentClass - the class to use for the bottommost node of a document
|
| 150 |
+
* elementClass - the class to use for HTML Elements
|
| 151 |
+
* commentClass - the class to use for comments
|
| 152 |
+
* doctypeClass - the class to use for doctypes
|
| 153 |
+
|
| 154 |
+
"""
|
| 155 |
+
# pylint:disable=not-callable
|
| 156 |
+
|
| 157 |
+
# Document class
|
| 158 |
+
documentClass = None
|
| 159 |
+
|
| 160 |
+
# The class to use for creating a node
|
| 161 |
+
elementClass = None
|
| 162 |
+
|
| 163 |
+
# The class to use for creating comments
|
| 164 |
+
commentClass = None
|
| 165 |
+
|
| 166 |
+
# The class to use for creating doctypes
|
| 167 |
+
doctypeClass = None
|
| 168 |
+
|
| 169 |
+
# Fragment class
|
| 170 |
+
fragmentClass = None
|
| 171 |
+
|
| 172 |
+
def __init__(self, namespaceHTMLElements):
|
| 173 |
+
"""Create a TreeBuilder
|
| 174 |
+
|
| 175 |
+
:arg namespaceHTMLElements: whether or not to namespace HTML elements
|
| 176 |
+
|
| 177 |
+
"""
|
| 178 |
+
if namespaceHTMLElements:
|
| 179 |
+
self.defaultNamespace = "http://www.w3.org/1999/xhtml"
|
| 180 |
+
else:
|
| 181 |
+
self.defaultNamespace = None
|
| 182 |
+
self.reset()
|
| 183 |
+
|
| 184 |
+
def reset(self):
|
| 185 |
+
self.openElements = []
|
| 186 |
+
self.activeFormattingElements = ActiveFormattingElements()
|
| 187 |
+
|
| 188 |
+
# XXX - rename these to headElement, formElement
|
| 189 |
+
self.headPointer = None
|
| 190 |
+
self.formPointer = None
|
| 191 |
+
|
| 192 |
+
self.insertFromTable = False
|
| 193 |
+
|
| 194 |
+
self.document = self.documentClass()
|
| 195 |
+
|
| 196 |
+
def elementInScope(self, target, variant=None):
|
| 197 |
+
|
| 198 |
+
# If we pass a node in we match that. if we pass a string
|
| 199 |
+
# match any node with that name
|
| 200 |
+
exactNode = hasattr(target, "nameTuple")
|
| 201 |
+
if not exactNode:
|
| 202 |
+
if isinstance(target, text_type):
|
| 203 |
+
target = (namespaces["html"], target)
|
| 204 |
+
assert isinstance(target, tuple)
|
| 205 |
+
|
| 206 |
+
listElements, invert = listElementsMap[variant]
|
| 207 |
+
|
| 208 |
+
for node in reversed(self.openElements):
|
| 209 |
+
if exactNode and node == target:
|
| 210 |
+
return True
|
| 211 |
+
elif not exactNode and node.nameTuple == target:
|
| 212 |
+
return True
|
| 213 |
+
elif (invert ^ (node.nameTuple in listElements)):
|
| 214 |
+
return False
|
| 215 |
+
|
| 216 |
+
assert False # We should never reach this point
|
| 217 |
+
|
| 218 |
+
def reconstructActiveFormattingElements(self):
|
| 219 |
+
# Within this algorithm the order of steps described in the
|
| 220 |
+
# specification is not quite the same as the order of steps in the
|
| 221 |
+
# code. It should still do the same though.
|
| 222 |
+
|
| 223 |
+
# Step 1: stop the algorithm when there's nothing to do.
|
| 224 |
+
if not self.activeFormattingElements:
|
| 225 |
+
return
|
| 226 |
+
|
| 227 |
+
# Step 2 and step 3: we start with the last element. So i is -1.
|
| 228 |
+
i = len(self.activeFormattingElements) - 1
|
| 229 |
+
entry = self.activeFormattingElements[i]
|
| 230 |
+
if entry == Marker or entry in self.openElements:
|
| 231 |
+
return
|
| 232 |
+
|
| 233 |
+
# Step 6
|
| 234 |
+
while entry != Marker and entry not in self.openElements:
|
| 235 |
+
if i == 0:
|
| 236 |
+
# This will be reset to 0 below
|
| 237 |
+
i = -1
|
| 238 |
+
break
|
| 239 |
+
i -= 1
|
| 240 |
+
# Step 5: let entry be one earlier in the list.
|
| 241 |
+
entry = self.activeFormattingElements[i]
|
| 242 |
+
|
| 243 |
+
while True:
|
| 244 |
+
# Step 7
|
| 245 |
+
i += 1
|
| 246 |
+
|
| 247 |
+
# Step 8
|
| 248 |
+
entry = self.activeFormattingElements[i]
|
| 249 |
+
clone = entry.cloneNode() # Mainly to get a new copy of the attributes
|
| 250 |
+
|
| 251 |
+
# Step 9
|
| 252 |
+
element = self.insertElement({"type": "StartTag",
|
| 253 |
+
"name": clone.name,
|
| 254 |
+
"namespace": clone.namespace,
|
| 255 |
+
"data": clone.attributes})
|
| 256 |
+
|
| 257 |
+
# Step 10
|
| 258 |
+
self.activeFormattingElements[i] = element
|
| 259 |
+
|
| 260 |
+
# Step 11
|
| 261 |
+
if element == self.activeFormattingElements[-1]:
|
| 262 |
+
break
|
| 263 |
+
|
| 264 |
+
def clearActiveFormattingElements(self):
|
| 265 |
+
entry = self.activeFormattingElements.pop()
|
| 266 |
+
while self.activeFormattingElements and entry != Marker:
|
| 267 |
+
entry = self.activeFormattingElements.pop()
|
| 268 |
+
|
| 269 |
+
def elementInActiveFormattingElements(self, name):
|
| 270 |
+
"""Check if an element exists between the end of the active
|
| 271 |
+
formatting elements and the last marker. If it does, return it, else
|
| 272 |
+
return false"""
|
| 273 |
+
|
| 274 |
+
for item in self.activeFormattingElements[::-1]:
|
| 275 |
+
# Check for Marker first because if it's a Marker it doesn't have a
|
| 276 |
+
# name attribute.
|
| 277 |
+
if item == Marker:
|
| 278 |
+
break
|
| 279 |
+
elif item.name == name:
|
| 280 |
+
return item
|
| 281 |
+
return False
|
| 282 |
+
|
| 283 |
+
def insertRoot(self, token):
|
| 284 |
+
element = self.createElement(token)
|
| 285 |
+
self.openElements.append(element)
|
| 286 |
+
self.document.appendChild(element)
|
| 287 |
+
|
| 288 |
+
def insertDoctype(self, token):
|
| 289 |
+
name = token["name"]
|
| 290 |
+
publicId = token["publicId"]
|
| 291 |
+
systemId = token["systemId"]
|
| 292 |
+
|
| 293 |
+
doctype = self.doctypeClass(name, publicId, systemId)
|
| 294 |
+
self.document.appendChild(doctype)
|
| 295 |
+
|
| 296 |
+
def insertComment(self, token, parent=None):
|
| 297 |
+
if parent is None:
|
| 298 |
+
parent = self.openElements[-1]
|
| 299 |
+
parent.appendChild(self.commentClass(token["data"]))
|
| 300 |
+
|
| 301 |
+
def createElement(self, token):
|
| 302 |
+
"""Create an element but don't insert it anywhere"""
|
| 303 |
+
name = token["name"]
|
| 304 |
+
namespace = token.get("namespace", self.defaultNamespace)
|
| 305 |
+
element = self.elementClass(name, namespace)
|
| 306 |
+
element.attributes = token["data"]
|
| 307 |
+
return element
|
| 308 |
+
|
| 309 |
+
def _getInsertFromTable(self):
|
| 310 |
+
return self._insertFromTable
|
| 311 |
+
|
| 312 |
+
def _setInsertFromTable(self, value):
|
| 313 |
+
"""Switch the function used to insert an element from the
|
| 314 |
+
normal one to the misnested table one and back again"""
|
| 315 |
+
self._insertFromTable = value
|
| 316 |
+
if value:
|
| 317 |
+
self.insertElement = self.insertElementTable
|
| 318 |
+
else:
|
| 319 |
+
self.insertElement = self.insertElementNormal
|
| 320 |
+
|
| 321 |
+
insertFromTable = property(_getInsertFromTable, _setInsertFromTable)
|
| 322 |
+
|
| 323 |
+
def insertElementNormal(self, token):
|
| 324 |
+
name = token["name"]
|
| 325 |
+
assert isinstance(name, text_type), "Element %s not unicode" % name
|
| 326 |
+
namespace = token.get("namespace", self.defaultNamespace)
|
| 327 |
+
element = self.elementClass(name, namespace)
|
| 328 |
+
element.attributes = token["data"]
|
| 329 |
+
self.openElements[-1].appendChild(element)
|
| 330 |
+
self.openElements.append(element)
|
| 331 |
+
return element
|
| 332 |
+
|
| 333 |
+
def insertElementTable(self, token):
|
| 334 |
+
"""Create an element and insert it into the tree"""
|
| 335 |
+
element = self.createElement(token)
|
| 336 |
+
if self.openElements[-1].name not in tableInsertModeElements:
|
| 337 |
+
return self.insertElementNormal(token)
|
| 338 |
+
else:
|
| 339 |
+
# We should be in the InTable mode. This means we want to do
|
| 340 |
+
# special magic element rearranging
|
| 341 |
+
parent, insertBefore = self.getTableMisnestedNodePosition()
|
| 342 |
+
if insertBefore is None:
|
| 343 |
+
parent.appendChild(element)
|
| 344 |
+
else:
|
| 345 |
+
parent.insertBefore(element, insertBefore)
|
| 346 |
+
self.openElements.append(element)
|
| 347 |
+
return element
|
| 348 |
+
|
| 349 |
+
def insertText(self, data, parent=None):
|
| 350 |
+
"""Insert text data."""
|
| 351 |
+
if parent is None:
|
| 352 |
+
parent = self.openElements[-1]
|
| 353 |
+
|
| 354 |
+
if (not self.insertFromTable or (self.insertFromTable and
|
| 355 |
+
self.openElements[-1].name
|
| 356 |
+
not in tableInsertModeElements)):
|
| 357 |
+
parent.insertText(data)
|
| 358 |
+
else:
|
| 359 |
+
# We should be in the InTable mode. This means we want to do
|
| 360 |
+
# special magic element rearranging
|
| 361 |
+
parent, insertBefore = self.getTableMisnestedNodePosition()
|
| 362 |
+
parent.insertText(data, insertBefore)
|
| 363 |
+
|
| 364 |
+
def getTableMisnestedNodePosition(self):
|
| 365 |
+
"""Get the foster parent element, and sibling to insert before
|
| 366 |
+
(or None) when inserting a misnested table node"""
|
| 367 |
+
# The foster parent element is the one which comes before the most
|
| 368 |
+
# recently opened table element
|
| 369 |
+
# XXX - this is really inelegant
|
| 370 |
+
lastTable = None
|
| 371 |
+
fosterParent = None
|
| 372 |
+
insertBefore = None
|
| 373 |
+
for elm in self.openElements[::-1]:
|
| 374 |
+
if elm.name == "table":
|
| 375 |
+
lastTable = elm
|
| 376 |
+
break
|
| 377 |
+
if lastTable:
|
| 378 |
+
# XXX - we should really check that this parent is actually a
|
| 379 |
+
# node here
|
| 380 |
+
if lastTable.parent:
|
| 381 |
+
fosterParent = lastTable.parent
|
| 382 |
+
insertBefore = lastTable
|
| 383 |
+
else:
|
| 384 |
+
fosterParent = self.openElements[
|
| 385 |
+
self.openElements.index(lastTable) - 1]
|
| 386 |
+
else:
|
| 387 |
+
fosterParent = self.openElements[0]
|
| 388 |
+
return fosterParent, insertBefore
|
| 389 |
+
|
| 390 |
+
def generateImpliedEndTags(self, exclude=None):
|
| 391 |
+
name = self.openElements[-1].name
|
| 392 |
+
# XXX td, th and tr are not actually needed
|
| 393 |
+
if (name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt")) and
|
| 394 |
+
name != exclude):
|
| 395 |
+
self.openElements.pop()
|
| 396 |
+
# XXX This is not entirely what the specification says. We should
|
| 397 |
+
# investigate it more closely.
|
| 398 |
+
self.generateImpliedEndTags(exclude)
|
| 399 |
+
|
| 400 |
+
def getDocument(self):
|
| 401 |
+
"""Return the final tree"""
|
| 402 |
+
return self.document
|
| 403 |
+
|
| 404 |
+
def getFragment(self):
|
| 405 |
+
"""Return the final fragment"""
|
| 406 |
+
# assert self.innerHTML
|
| 407 |
+
fragment = self.fragmentClass()
|
| 408 |
+
self.openElements[0].reparentChildren(fragment)
|
| 409 |
+
return fragment
|
| 410 |
+
|
| 411 |
+
def testSerializer(self, node):
|
| 412 |
+
"""Serialize the subtree of node in the format required by unit tests
|
| 413 |
+
|
| 414 |
+
:arg node: the node from which to start serializing
|
| 415 |
+
|
| 416 |
+
"""
|
| 417 |
+
raise NotImplementedError
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/dom.py
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
try:
|
| 5 |
+
from collections.abc import MutableMapping
|
| 6 |
+
except ImportError: # Python 2.7
|
| 7 |
+
from collections import MutableMapping
|
| 8 |
+
from xml.dom import minidom, Node
|
| 9 |
+
import weakref
|
| 10 |
+
|
| 11 |
+
from . import base
|
| 12 |
+
from .. import constants
|
| 13 |
+
from ..constants import namespaces
|
| 14 |
+
from .._utils import moduleFactoryFactory
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def getDomBuilder(DomImplementation):
|
| 18 |
+
Dom = DomImplementation
|
| 19 |
+
|
| 20 |
+
class AttrList(MutableMapping):
|
| 21 |
+
def __init__(self, element):
|
| 22 |
+
self.element = element
|
| 23 |
+
|
| 24 |
+
def __iter__(self):
|
| 25 |
+
return iter(self.element.attributes.keys())
|
| 26 |
+
|
| 27 |
+
def __setitem__(self, name, value):
|
| 28 |
+
if isinstance(name, tuple):
|
| 29 |
+
raise NotImplementedError
|
| 30 |
+
else:
|
| 31 |
+
attr = self.element.ownerDocument.createAttribute(name)
|
| 32 |
+
attr.value = value
|
| 33 |
+
self.element.attributes[name] = attr
|
| 34 |
+
|
| 35 |
+
def __len__(self):
|
| 36 |
+
return len(self.element.attributes)
|
| 37 |
+
|
| 38 |
+
def items(self):
|
| 39 |
+
return list(self.element.attributes.items())
|
| 40 |
+
|
| 41 |
+
def values(self):
|
| 42 |
+
return list(self.element.attributes.values())
|
| 43 |
+
|
| 44 |
+
def __getitem__(self, name):
|
| 45 |
+
if isinstance(name, tuple):
|
| 46 |
+
raise NotImplementedError
|
| 47 |
+
else:
|
| 48 |
+
return self.element.attributes[name].value
|
| 49 |
+
|
| 50 |
+
def __delitem__(self, name):
|
| 51 |
+
if isinstance(name, tuple):
|
| 52 |
+
raise NotImplementedError
|
| 53 |
+
else:
|
| 54 |
+
del self.element.attributes[name]
|
| 55 |
+
|
| 56 |
+
class NodeBuilder(base.Node):
|
| 57 |
+
def __init__(self, element):
|
| 58 |
+
base.Node.__init__(self, element.nodeName)
|
| 59 |
+
self.element = element
|
| 60 |
+
|
| 61 |
+
namespace = property(lambda self: hasattr(self.element, "namespaceURI") and
|
| 62 |
+
self.element.namespaceURI or None)
|
| 63 |
+
|
| 64 |
+
def appendChild(self, node):
|
| 65 |
+
node.parent = self
|
| 66 |
+
self.element.appendChild(node.element)
|
| 67 |
+
|
| 68 |
+
def insertText(self, data, insertBefore=None):
|
| 69 |
+
text = self.element.ownerDocument.createTextNode(data)
|
| 70 |
+
if insertBefore:
|
| 71 |
+
self.element.insertBefore(text, insertBefore.element)
|
| 72 |
+
else:
|
| 73 |
+
self.element.appendChild(text)
|
| 74 |
+
|
| 75 |
+
def insertBefore(self, node, refNode):
|
| 76 |
+
self.element.insertBefore(node.element, refNode.element)
|
| 77 |
+
node.parent = self
|
| 78 |
+
|
| 79 |
+
def removeChild(self, node):
|
| 80 |
+
if node.element.parentNode == self.element:
|
| 81 |
+
self.element.removeChild(node.element)
|
| 82 |
+
node.parent = None
|
| 83 |
+
|
| 84 |
+
def reparentChildren(self, newParent):
|
| 85 |
+
while self.element.hasChildNodes():
|
| 86 |
+
child = self.element.firstChild
|
| 87 |
+
self.element.removeChild(child)
|
| 88 |
+
newParent.element.appendChild(child)
|
| 89 |
+
self.childNodes = []
|
| 90 |
+
|
| 91 |
+
def getAttributes(self):
|
| 92 |
+
return AttrList(self.element)
|
| 93 |
+
|
| 94 |
+
def setAttributes(self, attributes):
|
| 95 |
+
if attributes:
|
| 96 |
+
for name, value in list(attributes.items()):
|
| 97 |
+
if isinstance(name, tuple):
|
| 98 |
+
if name[0] is not None:
|
| 99 |
+
qualifiedName = (name[0] + ":" + name[1])
|
| 100 |
+
else:
|
| 101 |
+
qualifiedName = name[1]
|
| 102 |
+
self.element.setAttributeNS(name[2], qualifiedName,
|
| 103 |
+
value)
|
| 104 |
+
else:
|
| 105 |
+
self.element.setAttribute(
|
| 106 |
+
name, value)
|
| 107 |
+
attributes = property(getAttributes, setAttributes)
|
| 108 |
+
|
| 109 |
+
def cloneNode(self):
|
| 110 |
+
return NodeBuilder(self.element.cloneNode(False))
|
| 111 |
+
|
| 112 |
+
def hasContent(self):
|
| 113 |
+
return self.element.hasChildNodes()
|
| 114 |
+
|
| 115 |
+
def getNameTuple(self):
|
| 116 |
+
if self.namespace is None:
|
| 117 |
+
return namespaces["html"], self.name
|
| 118 |
+
else:
|
| 119 |
+
return self.namespace, self.name
|
| 120 |
+
|
| 121 |
+
nameTuple = property(getNameTuple)
|
| 122 |
+
|
| 123 |
+
class TreeBuilder(base.TreeBuilder): # pylint:disable=unused-variable
|
| 124 |
+
def documentClass(self):
|
| 125 |
+
self.dom = Dom.getDOMImplementation().createDocument(None, None, None)
|
| 126 |
+
return weakref.proxy(self)
|
| 127 |
+
|
| 128 |
+
def insertDoctype(self, token):
|
| 129 |
+
name = token["name"]
|
| 130 |
+
publicId = token["publicId"]
|
| 131 |
+
systemId = token["systemId"]
|
| 132 |
+
|
| 133 |
+
domimpl = Dom.getDOMImplementation()
|
| 134 |
+
doctype = domimpl.createDocumentType(name, publicId, systemId)
|
| 135 |
+
self.document.appendChild(NodeBuilder(doctype))
|
| 136 |
+
if Dom == minidom:
|
| 137 |
+
doctype.ownerDocument = self.dom
|
| 138 |
+
|
| 139 |
+
def elementClass(self, name, namespace=None):
|
| 140 |
+
if namespace is None and self.defaultNamespace is None:
|
| 141 |
+
node = self.dom.createElement(name)
|
| 142 |
+
else:
|
| 143 |
+
node = self.dom.createElementNS(namespace, name)
|
| 144 |
+
|
| 145 |
+
return NodeBuilder(node)
|
| 146 |
+
|
| 147 |
+
def commentClass(self, data):
|
| 148 |
+
return NodeBuilder(self.dom.createComment(data))
|
| 149 |
+
|
| 150 |
+
def fragmentClass(self):
|
| 151 |
+
return NodeBuilder(self.dom.createDocumentFragment())
|
| 152 |
+
|
| 153 |
+
def appendChild(self, node):
|
| 154 |
+
self.dom.appendChild(node.element)
|
| 155 |
+
|
| 156 |
+
def testSerializer(self, element):
|
| 157 |
+
return testSerializer(element)
|
| 158 |
+
|
| 159 |
+
def getDocument(self):
|
| 160 |
+
return self.dom
|
| 161 |
+
|
| 162 |
+
def getFragment(self):
|
| 163 |
+
return base.TreeBuilder.getFragment(self).element
|
| 164 |
+
|
| 165 |
+
def insertText(self, data, parent=None):
|
| 166 |
+
data = data
|
| 167 |
+
if parent != self:
|
| 168 |
+
base.TreeBuilder.insertText(self, data, parent)
|
| 169 |
+
else:
|
| 170 |
+
# HACK: allow text nodes as children of the document node
|
| 171 |
+
if hasattr(self.dom, '_child_node_types'):
|
| 172 |
+
# pylint:disable=protected-access
|
| 173 |
+
if Node.TEXT_NODE not in self.dom._child_node_types:
|
| 174 |
+
self.dom._child_node_types = list(self.dom._child_node_types)
|
| 175 |
+
self.dom._child_node_types.append(Node.TEXT_NODE)
|
| 176 |
+
self.dom.appendChild(self.dom.createTextNode(data))
|
| 177 |
+
|
| 178 |
+
implementation = DomImplementation
|
| 179 |
+
name = None
|
| 180 |
+
|
| 181 |
+
def testSerializer(element):
|
| 182 |
+
element.normalize()
|
| 183 |
+
rv = []
|
| 184 |
+
|
| 185 |
+
def serializeElement(element, indent=0):
|
| 186 |
+
if element.nodeType == Node.DOCUMENT_TYPE_NODE:
|
| 187 |
+
if element.name:
|
| 188 |
+
if element.publicId or element.systemId:
|
| 189 |
+
publicId = element.publicId or ""
|
| 190 |
+
systemId = element.systemId or ""
|
| 191 |
+
rv.append("""|%s<!DOCTYPE %s "%s" "%s">""" %
|
| 192 |
+
(' ' * indent, element.name, publicId, systemId))
|
| 193 |
+
else:
|
| 194 |
+
rv.append("|%s<!DOCTYPE %s>" % (' ' * indent, element.name))
|
| 195 |
+
else:
|
| 196 |
+
rv.append("|%s<!DOCTYPE >" % (' ' * indent,))
|
| 197 |
+
elif element.nodeType == Node.DOCUMENT_NODE:
|
| 198 |
+
rv.append("#document")
|
| 199 |
+
elif element.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
|
| 200 |
+
rv.append("#document-fragment")
|
| 201 |
+
elif element.nodeType == Node.COMMENT_NODE:
|
| 202 |
+
rv.append("|%s<!-- %s -->" % (' ' * indent, element.nodeValue))
|
| 203 |
+
elif element.nodeType == Node.TEXT_NODE:
|
| 204 |
+
rv.append("|%s\"%s\"" % (' ' * indent, element.nodeValue))
|
| 205 |
+
else:
|
| 206 |
+
if (hasattr(element, "namespaceURI") and
|
| 207 |
+
element.namespaceURI is not None):
|
| 208 |
+
name = "%s %s" % (constants.prefixes[element.namespaceURI],
|
| 209 |
+
element.nodeName)
|
| 210 |
+
else:
|
| 211 |
+
name = element.nodeName
|
| 212 |
+
rv.append("|%s<%s>" % (' ' * indent, name))
|
| 213 |
+
if element.hasAttributes():
|
| 214 |
+
attributes = []
|
| 215 |
+
for i in range(len(element.attributes)):
|
| 216 |
+
attr = element.attributes.item(i)
|
| 217 |
+
name = attr.nodeName
|
| 218 |
+
value = attr.value
|
| 219 |
+
ns = attr.namespaceURI
|
| 220 |
+
if ns:
|
| 221 |
+
name = "%s %s" % (constants.prefixes[ns], attr.localName)
|
| 222 |
+
else:
|
| 223 |
+
name = attr.nodeName
|
| 224 |
+
attributes.append((name, value))
|
| 225 |
+
|
| 226 |
+
for name, value in sorted(attributes):
|
| 227 |
+
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
|
| 228 |
+
indent += 2
|
| 229 |
+
for child in element.childNodes:
|
| 230 |
+
serializeElement(child, indent)
|
| 231 |
+
serializeElement(element, 0)
|
| 232 |
+
|
| 233 |
+
return "\n".join(rv)
|
| 234 |
+
|
| 235 |
+
return locals()
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
# The actual means to get a module!
|
| 239 |
+
getDomModule = moduleFactoryFactory(getDomBuilder)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/etree.py
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
# pylint:disable=protected-access
|
| 3 |
+
|
| 4 |
+
from pip._vendor.six import text_type
|
| 5 |
+
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
from copy import copy
|
| 9 |
+
|
| 10 |
+
from . import base
|
| 11 |
+
from .. import _ihatexml
|
| 12 |
+
from .. import constants
|
| 13 |
+
from ..constants import namespaces
|
| 14 |
+
from .._utils import moduleFactoryFactory
|
| 15 |
+
|
| 16 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def getETreeBuilder(ElementTreeImplementation, fullTree=False):
|
| 20 |
+
ElementTree = ElementTreeImplementation
|
| 21 |
+
ElementTreeCommentType = ElementTree.Comment("asd").tag
|
| 22 |
+
|
| 23 |
+
class Element(base.Node):
|
| 24 |
+
def __init__(self, name, namespace=None):
|
| 25 |
+
self._name = name
|
| 26 |
+
self._namespace = namespace
|
| 27 |
+
self._element = ElementTree.Element(self._getETreeTag(name,
|
| 28 |
+
namespace))
|
| 29 |
+
if namespace is None:
|
| 30 |
+
self.nameTuple = namespaces["html"], self._name
|
| 31 |
+
else:
|
| 32 |
+
self.nameTuple = self._namespace, self._name
|
| 33 |
+
self.parent = None
|
| 34 |
+
self._childNodes = []
|
| 35 |
+
self._flags = []
|
| 36 |
+
|
| 37 |
+
def _getETreeTag(self, name, namespace):
|
| 38 |
+
if namespace is None:
|
| 39 |
+
etree_tag = name
|
| 40 |
+
else:
|
| 41 |
+
etree_tag = "{%s}%s" % (namespace, name)
|
| 42 |
+
return etree_tag
|
| 43 |
+
|
| 44 |
+
def _setName(self, name):
|
| 45 |
+
self._name = name
|
| 46 |
+
self._element.tag = self._getETreeTag(self._name, self._namespace)
|
| 47 |
+
|
| 48 |
+
def _getName(self):
|
| 49 |
+
return self._name
|
| 50 |
+
|
| 51 |
+
name = property(_getName, _setName)
|
| 52 |
+
|
| 53 |
+
def _setNamespace(self, namespace):
|
| 54 |
+
self._namespace = namespace
|
| 55 |
+
self._element.tag = self._getETreeTag(self._name, self._namespace)
|
| 56 |
+
|
| 57 |
+
def _getNamespace(self):
|
| 58 |
+
return self._namespace
|
| 59 |
+
|
| 60 |
+
namespace = property(_getNamespace, _setNamespace)
|
| 61 |
+
|
| 62 |
+
def _getAttributes(self):
|
| 63 |
+
return self._element.attrib
|
| 64 |
+
|
| 65 |
+
def _setAttributes(self, attributes):
|
| 66 |
+
el_attrib = self._element.attrib
|
| 67 |
+
el_attrib.clear()
|
| 68 |
+
if attributes:
|
| 69 |
+
# calling .items _always_ allocates, and the above truthy check is cheaper than the
|
| 70 |
+
# allocation on average
|
| 71 |
+
for key, value in attributes.items():
|
| 72 |
+
if isinstance(key, tuple):
|
| 73 |
+
name = "{%s}%s" % (key[2], key[1])
|
| 74 |
+
else:
|
| 75 |
+
name = key
|
| 76 |
+
el_attrib[name] = value
|
| 77 |
+
|
| 78 |
+
attributes = property(_getAttributes, _setAttributes)
|
| 79 |
+
|
| 80 |
+
def _getChildNodes(self):
|
| 81 |
+
return self._childNodes
|
| 82 |
+
|
| 83 |
+
def _setChildNodes(self, value):
|
| 84 |
+
del self._element[:]
|
| 85 |
+
self._childNodes = []
|
| 86 |
+
for element in value:
|
| 87 |
+
self.insertChild(element)
|
| 88 |
+
|
| 89 |
+
childNodes = property(_getChildNodes, _setChildNodes)
|
| 90 |
+
|
| 91 |
+
def hasContent(self):
|
| 92 |
+
"""Return true if the node has children or text"""
|
| 93 |
+
return bool(self._element.text or len(self._element))
|
| 94 |
+
|
| 95 |
+
def appendChild(self, node):
|
| 96 |
+
self._childNodes.append(node)
|
| 97 |
+
self._element.append(node._element)
|
| 98 |
+
node.parent = self
|
| 99 |
+
|
| 100 |
+
def insertBefore(self, node, refNode):
|
| 101 |
+
index = list(self._element).index(refNode._element)
|
| 102 |
+
self._element.insert(index, node._element)
|
| 103 |
+
node.parent = self
|
| 104 |
+
|
| 105 |
+
def removeChild(self, node):
|
| 106 |
+
self._childNodes.remove(node)
|
| 107 |
+
self._element.remove(node._element)
|
| 108 |
+
node.parent = None
|
| 109 |
+
|
| 110 |
+
def insertText(self, data, insertBefore=None):
|
| 111 |
+
if not(len(self._element)):
|
| 112 |
+
if not self._element.text:
|
| 113 |
+
self._element.text = ""
|
| 114 |
+
self._element.text += data
|
| 115 |
+
elif insertBefore is None:
|
| 116 |
+
# Insert the text as the tail of the last child element
|
| 117 |
+
if not self._element[-1].tail:
|
| 118 |
+
self._element[-1].tail = ""
|
| 119 |
+
self._element[-1].tail += data
|
| 120 |
+
else:
|
| 121 |
+
# Insert the text before the specified node
|
| 122 |
+
children = list(self._element)
|
| 123 |
+
index = children.index(insertBefore._element)
|
| 124 |
+
if index > 0:
|
| 125 |
+
if not self._element[index - 1].tail:
|
| 126 |
+
self._element[index - 1].tail = ""
|
| 127 |
+
self._element[index - 1].tail += data
|
| 128 |
+
else:
|
| 129 |
+
if not self._element.text:
|
| 130 |
+
self._element.text = ""
|
| 131 |
+
self._element.text += data
|
| 132 |
+
|
| 133 |
+
def cloneNode(self):
|
| 134 |
+
element = type(self)(self.name, self.namespace)
|
| 135 |
+
if self._element.attrib:
|
| 136 |
+
element._element.attrib = copy(self._element.attrib)
|
| 137 |
+
return element
|
| 138 |
+
|
| 139 |
+
def reparentChildren(self, newParent):
|
| 140 |
+
if newParent.childNodes:
|
| 141 |
+
newParent.childNodes[-1]._element.tail += self._element.text
|
| 142 |
+
else:
|
| 143 |
+
if not newParent._element.text:
|
| 144 |
+
newParent._element.text = ""
|
| 145 |
+
if self._element.text is not None:
|
| 146 |
+
newParent._element.text += self._element.text
|
| 147 |
+
self._element.text = ""
|
| 148 |
+
base.Node.reparentChildren(self, newParent)
|
| 149 |
+
|
| 150 |
+
class Comment(Element):
|
| 151 |
+
def __init__(self, data):
|
| 152 |
+
# Use the superclass constructor to set all properties on the
|
| 153 |
+
# wrapper element
|
| 154 |
+
self._element = ElementTree.Comment(data)
|
| 155 |
+
self.parent = None
|
| 156 |
+
self._childNodes = []
|
| 157 |
+
self._flags = []
|
| 158 |
+
|
| 159 |
+
def _getData(self):
|
| 160 |
+
return self._element.text
|
| 161 |
+
|
| 162 |
+
def _setData(self, value):
|
| 163 |
+
self._element.text = value
|
| 164 |
+
|
| 165 |
+
data = property(_getData, _setData)
|
| 166 |
+
|
| 167 |
+
class DocumentType(Element):
|
| 168 |
+
def __init__(self, name, publicId, systemId):
|
| 169 |
+
Element.__init__(self, "<!DOCTYPE>")
|
| 170 |
+
self._element.text = name
|
| 171 |
+
self.publicId = publicId
|
| 172 |
+
self.systemId = systemId
|
| 173 |
+
|
| 174 |
+
def _getPublicId(self):
|
| 175 |
+
return self._element.get("publicId", "")
|
| 176 |
+
|
| 177 |
+
def _setPublicId(self, value):
|
| 178 |
+
if value is not None:
|
| 179 |
+
self._element.set("publicId", value)
|
| 180 |
+
|
| 181 |
+
publicId = property(_getPublicId, _setPublicId)
|
| 182 |
+
|
| 183 |
+
def _getSystemId(self):
|
| 184 |
+
return self._element.get("systemId", "")
|
| 185 |
+
|
| 186 |
+
def _setSystemId(self, value):
|
| 187 |
+
if value is not None:
|
| 188 |
+
self._element.set("systemId", value)
|
| 189 |
+
|
| 190 |
+
systemId = property(_getSystemId, _setSystemId)
|
| 191 |
+
|
| 192 |
+
class Document(Element):
|
| 193 |
+
def __init__(self):
|
| 194 |
+
Element.__init__(self, "DOCUMENT_ROOT")
|
| 195 |
+
|
| 196 |
+
class DocumentFragment(Element):
|
| 197 |
+
def __init__(self):
|
| 198 |
+
Element.__init__(self, "DOCUMENT_FRAGMENT")
|
| 199 |
+
|
| 200 |
+
def testSerializer(element):
|
| 201 |
+
rv = []
|
| 202 |
+
|
| 203 |
+
def serializeElement(element, indent=0):
|
| 204 |
+
if not(hasattr(element, "tag")):
|
| 205 |
+
element = element.getroot()
|
| 206 |
+
if element.tag == "<!DOCTYPE>":
|
| 207 |
+
if element.get("publicId") or element.get("systemId"):
|
| 208 |
+
publicId = element.get("publicId") or ""
|
| 209 |
+
systemId = element.get("systemId") or ""
|
| 210 |
+
rv.append("""<!DOCTYPE %s "%s" "%s">""" %
|
| 211 |
+
(element.text, publicId, systemId))
|
| 212 |
+
else:
|
| 213 |
+
rv.append("<!DOCTYPE %s>" % (element.text,))
|
| 214 |
+
elif element.tag == "DOCUMENT_ROOT":
|
| 215 |
+
rv.append("#document")
|
| 216 |
+
if element.text is not None:
|
| 217 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 218 |
+
if element.tail is not None:
|
| 219 |
+
raise TypeError("Document node cannot have tail")
|
| 220 |
+
if hasattr(element, "attrib") and len(element.attrib):
|
| 221 |
+
raise TypeError("Document node cannot have attributes")
|
| 222 |
+
elif element.tag == ElementTreeCommentType:
|
| 223 |
+
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
|
| 224 |
+
else:
|
| 225 |
+
assert isinstance(element.tag, text_type), \
|
| 226 |
+
"Expected unicode, got %s, %s" % (type(element.tag), element.tag)
|
| 227 |
+
nsmatch = tag_regexp.match(element.tag)
|
| 228 |
+
|
| 229 |
+
if nsmatch is None:
|
| 230 |
+
name = element.tag
|
| 231 |
+
else:
|
| 232 |
+
ns, name = nsmatch.groups()
|
| 233 |
+
prefix = constants.prefixes[ns]
|
| 234 |
+
name = "%s %s" % (prefix, name)
|
| 235 |
+
rv.append("|%s<%s>" % (' ' * indent, name))
|
| 236 |
+
|
| 237 |
+
if hasattr(element, "attrib"):
|
| 238 |
+
attributes = []
|
| 239 |
+
for name, value in element.attrib.items():
|
| 240 |
+
nsmatch = tag_regexp.match(name)
|
| 241 |
+
if nsmatch is not None:
|
| 242 |
+
ns, name = nsmatch.groups()
|
| 243 |
+
prefix = constants.prefixes[ns]
|
| 244 |
+
attr_string = "%s %s" % (prefix, name)
|
| 245 |
+
else:
|
| 246 |
+
attr_string = name
|
| 247 |
+
attributes.append((attr_string, value))
|
| 248 |
+
|
| 249 |
+
for name, value in sorted(attributes):
|
| 250 |
+
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
|
| 251 |
+
if element.text:
|
| 252 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 253 |
+
indent += 2
|
| 254 |
+
for child in element:
|
| 255 |
+
serializeElement(child, indent)
|
| 256 |
+
if element.tail:
|
| 257 |
+
rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail))
|
| 258 |
+
serializeElement(element, 0)
|
| 259 |
+
|
| 260 |
+
return "\n".join(rv)
|
| 261 |
+
|
| 262 |
+
def tostring(element): # pylint:disable=unused-variable
|
| 263 |
+
"""Serialize an element and its child nodes to a string"""
|
| 264 |
+
rv = []
|
| 265 |
+
filter = _ihatexml.InfosetFilter()
|
| 266 |
+
|
| 267 |
+
def serializeElement(element):
|
| 268 |
+
if isinstance(element, ElementTree.ElementTree):
|
| 269 |
+
element = element.getroot()
|
| 270 |
+
|
| 271 |
+
if element.tag == "<!DOCTYPE>":
|
| 272 |
+
if element.get("publicId") or element.get("systemId"):
|
| 273 |
+
publicId = element.get("publicId") or ""
|
| 274 |
+
systemId = element.get("systemId") or ""
|
| 275 |
+
rv.append("""<!DOCTYPE %s PUBLIC "%s" "%s">""" %
|
| 276 |
+
(element.text, publicId, systemId))
|
| 277 |
+
else:
|
| 278 |
+
rv.append("<!DOCTYPE %s>" % (element.text,))
|
| 279 |
+
elif element.tag == "DOCUMENT_ROOT":
|
| 280 |
+
if element.text is not None:
|
| 281 |
+
rv.append(element.text)
|
| 282 |
+
if element.tail is not None:
|
| 283 |
+
raise TypeError("Document node cannot have tail")
|
| 284 |
+
if hasattr(element, "attrib") and len(element.attrib):
|
| 285 |
+
raise TypeError("Document node cannot have attributes")
|
| 286 |
+
|
| 287 |
+
for child in element:
|
| 288 |
+
serializeElement(child)
|
| 289 |
+
|
| 290 |
+
elif element.tag == ElementTreeCommentType:
|
| 291 |
+
rv.append("<!--%s-->" % (element.text,))
|
| 292 |
+
else:
|
| 293 |
+
# This is assumed to be an ordinary element
|
| 294 |
+
if not element.attrib:
|
| 295 |
+
rv.append("<%s>" % (filter.fromXmlName(element.tag),))
|
| 296 |
+
else:
|
| 297 |
+
attr = " ".join(["%s=\"%s\"" % (
|
| 298 |
+
filter.fromXmlName(name), value)
|
| 299 |
+
for name, value in element.attrib.items()])
|
| 300 |
+
rv.append("<%s %s>" % (element.tag, attr))
|
| 301 |
+
if element.text:
|
| 302 |
+
rv.append(element.text)
|
| 303 |
+
|
| 304 |
+
for child in element:
|
| 305 |
+
serializeElement(child)
|
| 306 |
+
|
| 307 |
+
rv.append("</%s>" % (element.tag,))
|
| 308 |
+
|
| 309 |
+
if element.tail:
|
| 310 |
+
rv.append(element.tail)
|
| 311 |
+
|
| 312 |
+
serializeElement(element)
|
| 313 |
+
|
| 314 |
+
return "".join(rv)
|
| 315 |
+
|
| 316 |
+
class TreeBuilder(base.TreeBuilder): # pylint:disable=unused-variable
|
| 317 |
+
documentClass = Document
|
| 318 |
+
doctypeClass = DocumentType
|
| 319 |
+
elementClass = Element
|
| 320 |
+
commentClass = Comment
|
| 321 |
+
fragmentClass = DocumentFragment
|
| 322 |
+
implementation = ElementTreeImplementation
|
| 323 |
+
|
| 324 |
+
def testSerializer(self, element):
|
| 325 |
+
return testSerializer(element)
|
| 326 |
+
|
| 327 |
+
def getDocument(self):
|
| 328 |
+
if fullTree:
|
| 329 |
+
return self.document._element
|
| 330 |
+
else:
|
| 331 |
+
if self.defaultNamespace is not None:
|
| 332 |
+
return self.document._element.find(
|
| 333 |
+
"{%s}html" % self.defaultNamespace)
|
| 334 |
+
else:
|
| 335 |
+
return self.document._element.find("html")
|
| 336 |
+
|
| 337 |
+
def getFragment(self):
|
| 338 |
+
return base.TreeBuilder.getFragment(self)._element
|
| 339 |
+
|
| 340 |
+
return locals()
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
getETreeModule = moduleFactoryFactory(getETreeBuilder)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treebuilders/etree_lxml.py
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Module for supporting the lxml.etree library. The idea here is to use as much
|
| 2 |
+
of the native library as possible, without using fragile hacks like custom element
|
| 3 |
+
names that break between releases. The downside of this is that we cannot represent
|
| 4 |
+
all possible trees; specifically the following are known to cause problems:
|
| 5 |
+
|
| 6 |
+
Text or comments as siblings of the root element
|
| 7 |
+
Docypes with no name
|
| 8 |
+
|
| 9 |
+
When any of these things occur, we emit a DataLossWarning
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 13 |
+
# pylint:disable=protected-access
|
| 14 |
+
|
| 15 |
+
import warnings
|
| 16 |
+
import re
|
| 17 |
+
import sys
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
from collections.abc import MutableMapping
|
| 21 |
+
except ImportError:
|
| 22 |
+
from collections import MutableMapping
|
| 23 |
+
|
| 24 |
+
from . import base
|
| 25 |
+
from ..constants import DataLossWarning
|
| 26 |
+
from .. import constants
|
| 27 |
+
from . import etree as etree_builders
|
| 28 |
+
from .. import _ihatexml
|
| 29 |
+
|
| 30 |
+
import lxml.etree as etree
|
| 31 |
+
from pip._vendor.six import PY3, binary_type
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
fullTree = True
|
| 35 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 36 |
+
|
| 37 |
+
comment_type = etree.Comment("asd").tag
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class DocumentType(object):
|
| 41 |
+
def __init__(self, name, publicId, systemId):
|
| 42 |
+
self.name = name
|
| 43 |
+
self.publicId = publicId
|
| 44 |
+
self.systemId = systemId
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class Document(object):
|
| 48 |
+
def __init__(self):
|
| 49 |
+
self._elementTree = None
|
| 50 |
+
self._childNodes = []
|
| 51 |
+
|
| 52 |
+
def appendChild(self, element):
|
| 53 |
+
last = self._elementTree.getroot()
|
| 54 |
+
for last in self._elementTree.getroot().itersiblings():
|
| 55 |
+
pass
|
| 56 |
+
|
| 57 |
+
last.addnext(element._element)
|
| 58 |
+
|
| 59 |
+
def _getChildNodes(self):
|
| 60 |
+
return self._childNodes
|
| 61 |
+
|
| 62 |
+
childNodes = property(_getChildNodes)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def testSerializer(element):
|
| 66 |
+
rv = []
|
| 67 |
+
infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True)
|
| 68 |
+
|
| 69 |
+
def serializeElement(element, indent=0):
|
| 70 |
+
if not hasattr(element, "tag"):
|
| 71 |
+
if hasattr(element, "getroot"):
|
| 72 |
+
# Full tree case
|
| 73 |
+
rv.append("#document")
|
| 74 |
+
if element.docinfo.internalDTD:
|
| 75 |
+
if not (element.docinfo.public_id or
|
| 76 |
+
element.docinfo.system_url):
|
| 77 |
+
dtd_str = "<!DOCTYPE %s>" % element.docinfo.root_name
|
| 78 |
+
else:
|
| 79 |
+
dtd_str = """<!DOCTYPE %s "%s" "%s">""" % (
|
| 80 |
+
element.docinfo.root_name,
|
| 81 |
+
element.docinfo.public_id,
|
| 82 |
+
element.docinfo.system_url)
|
| 83 |
+
rv.append("|%s%s" % (' ' * (indent + 2), dtd_str))
|
| 84 |
+
next_element = element.getroot()
|
| 85 |
+
while next_element.getprevious() is not None:
|
| 86 |
+
next_element = next_element.getprevious()
|
| 87 |
+
while next_element is not None:
|
| 88 |
+
serializeElement(next_element, indent + 2)
|
| 89 |
+
next_element = next_element.getnext()
|
| 90 |
+
elif isinstance(element, str) or isinstance(element, bytes):
|
| 91 |
+
# Text in a fragment
|
| 92 |
+
assert isinstance(element, str) or sys.version_info[0] == 2
|
| 93 |
+
rv.append("|%s\"%s\"" % (' ' * indent, element))
|
| 94 |
+
else:
|
| 95 |
+
# Fragment case
|
| 96 |
+
rv.append("#document-fragment")
|
| 97 |
+
for next_element in element:
|
| 98 |
+
serializeElement(next_element, indent + 2)
|
| 99 |
+
elif element.tag == comment_type:
|
| 100 |
+
rv.append("|%s<!-- %s -->" % (' ' * indent, element.text))
|
| 101 |
+
if hasattr(element, "tail") and element.tail:
|
| 102 |
+
rv.append("|%s\"%s\"" % (' ' * indent, element.tail))
|
| 103 |
+
else:
|
| 104 |
+
assert isinstance(element, etree._Element)
|
| 105 |
+
nsmatch = etree_builders.tag_regexp.match(element.tag)
|
| 106 |
+
if nsmatch is not None:
|
| 107 |
+
ns = nsmatch.group(1)
|
| 108 |
+
tag = nsmatch.group(2)
|
| 109 |
+
prefix = constants.prefixes[ns]
|
| 110 |
+
rv.append("|%s<%s %s>" % (' ' * indent, prefix,
|
| 111 |
+
infosetFilter.fromXmlName(tag)))
|
| 112 |
+
else:
|
| 113 |
+
rv.append("|%s<%s>" % (' ' * indent,
|
| 114 |
+
infosetFilter.fromXmlName(element.tag)))
|
| 115 |
+
|
| 116 |
+
if hasattr(element, "attrib"):
|
| 117 |
+
attributes = []
|
| 118 |
+
for name, value in element.attrib.items():
|
| 119 |
+
nsmatch = tag_regexp.match(name)
|
| 120 |
+
if nsmatch is not None:
|
| 121 |
+
ns, name = nsmatch.groups()
|
| 122 |
+
name = infosetFilter.fromXmlName(name)
|
| 123 |
+
prefix = constants.prefixes[ns]
|
| 124 |
+
attr_string = "%s %s" % (prefix, name)
|
| 125 |
+
else:
|
| 126 |
+
attr_string = infosetFilter.fromXmlName(name)
|
| 127 |
+
attributes.append((attr_string, value))
|
| 128 |
+
|
| 129 |
+
for name, value in sorted(attributes):
|
| 130 |
+
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
|
| 131 |
+
|
| 132 |
+
if element.text:
|
| 133 |
+
rv.append("|%s\"%s\"" % (' ' * (indent + 2), element.text))
|
| 134 |
+
indent += 2
|
| 135 |
+
for child in element:
|
| 136 |
+
serializeElement(child, indent)
|
| 137 |
+
if hasattr(element, "tail") and element.tail:
|
| 138 |
+
rv.append("|%s\"%s\"" % (' ' * (indent - 2), element.tail))
|
| 139 |
+
serializeElement(element, 0)
|
| 140 |
+
|
| 141 |
+
return "\n".join(rv)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def tostring(element):
|
| 145 |
+
"""Serialize an element and its child nodes to a string"""
|
| 146 |
+
rv = []
|
| 147 |
+
|
| 148 |
+
def serializeElement(element):
|
| 149 |
+
if not hasattr(element, "tag"):
|
| 150 |
+
if element.docinfo.internalDTD:
|
| 151 |
+
if element.docinfo.doctype:
|
| 152 |
+
dtd_str = element.docinfo.doctype
|
| 153 |
+
else:
|
| 154 |
+
dtd_str = "<!DOCTYPE %s>" % element.docinfo.root_name
|
| 155 |
+
rv.append(dtd_str)
|
| 156 |
+
serializeElement(element.getroot())
|
| 157 |
+
|
| 158 |
+
elif element.tag == comment_type:
|
| 159 |
+
rv.append("<!--%s-->" % (element.text,))
|
| 160 |
+
|
| 161 |
+
else:
|
| 162 |
+
# This is assumed to be an ordinary element
|
| 163 |
+
if not element.attrib:
|
| 164 |
+
rv.append("<%s>" % (element.tag,))
|
| 165 |
+
else:
|
| 166 |
+
attr = " ".join(["%s=\"%s\"" % (name, value)
|
| 167 |
+
for name, value in element.attrib.items()])
|
| 168 |
+
rv.append("<%s %s>" % (element.tag, attr))
|
| 169 |
+
if element.text:
|
| 170 |
+
rv.append(element.text)
|
| 171 |
+
|
| 172 |
+
for child in element:
|
| 173 |
+
serializeElement(child)
|
| 174 |
+
|
| 175 |
+
rv.append("</%s>" % (element.tag,))
|
| 176 |
+
|
| 177 |
+
if hasattr(element, "tail") and element.tail:
|
| 178 |
+
rv.append(element.tail)
|
| 179 |
+
|
| 180 |
+
serializeElement(element)
|
| 181 |
+
|
| 182 |
+
return "".join(rv)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class TreeBuilder(base.TreeBuilder):
|
| 186 |
+
documentClass = Document
|
| 187 |
+
doctypeClass = DocumentType
|
| 188 |
+
elementClass = None
|
| 189 |
+
commentClass = None
|
| 190 |
+
fragmentClass = Document
|
| 191 |
+
implementation = etree
|
| 192 |
+
|
| 193 |
+
def __init__(self, namespaceHTMLElements, fullTree=False):
|
| 194 |
+
builder = etree_builders.getETreeModule(etree, fullTree=fullTree)
|
| 195 |
+
infosetFilter = self.infosetFilter = _ihatexml.InfosetFilter(preventDoubleDashComments=True)
|
| 196 |
+
self.namespaceHTMLElements = namespaceHTMLElements
|
| 197 |
+
|
| 198 |
+
class Attributes(MutableMapping):
|
| 199 |
+
def __init__(self, element):
|
| 200 |
+
self._element = element
|
| 201 |
+
|
| 202 |
+
def _coerceKey(self, key):
|
| 203 |
+
if isinstance(key, tuple):
|
| 204 |
+
name = "{%s}%s" % (key[2], infosetFilter.coerceAttribute(key[1]))
|
| 205 |
+
else:
|
| 206 |
+
name = infosetFilter.coerceAttribute(key)
|
| 207 |
+
return name
|
| 208 |
+
|
| 209 |
+
def __getitem__(self, key):
|
| 210 |
+
value = self._element._element.attrib[self._coerceKey(key)]
|
| 211 |
+
if not PY3 and isinstance(value, binary_type):
|
| 212 |
+
value = value.decode("ascii")
|
| 213 |
+
return value
|
| 214 |
+
|
| 215 |
+
def __setitem__(self, key, value):
|
| 216 |
+
self._element._element.attrib[self._coerceKey(key)] = value
|
| 217 |
+
|
| 218 |
+
def __delitem__(self, key):
|
| 219 |
+
del self._element._element.attrib[self._coerceKey(key)]
|
| 220 |
+
|
| 221 |
+
def __iter__(self):
|
| 222 |
+
return iter(self._element._element.attrib)
|
| 223 |
+
|
| 224 |
+
def __len__(self):
|
| 225 |
+
return len(self._element._element.attrib)
|
| 226 |
+
|
| 227 |
+
def clear(self):
|
| 228 |
+
return self._element._element.attrib.clear()
|
| 229 |
+
|
| 230 |
+
class Element(builder.Element):
|
| 231 |
+
def __init__(self, name, namespace):
|
| 232 |
+
name = infosetFilter.coerceElement(name)
|
| 233 |
+
builder.Element.__init__(self, name, namespace=namespace)
|
| 234 |
+
self._attributes = Attributes(self)
|
| 235 |
+
|
| 236 |
+
def _setName(self, name):
|
| 237 |
+
self._name = infosetFilter.coerceElement(name)
|
| 238 |
+
self._element.tag = self._getETreeTag(
|
| 239 |
+
self._name, self._namespace)
|
| 240 |
+
|
| 241 |
+
def _getName(self):
|
| 242 |
+
return infosetFilter.fromXmlName(self._name)
|
| 243 |
+
|
| 244 |
+
name = property(_getName, _setName)
|
| 245 |
+
|
| 246 |
+
def _getAttributes(self):
|
| 247 |
+
return self._attributes
|
| 248 |
+
|
| 249 |
+
def _setAttributes(self, value):
|
| 250 |
+
attributes = self.attributes
|
| 251 |
+
attributes.clear()
|
| 252 |
+
attributes.update(value)
|
| 253 |
+
|
| 254 |
+
attributes = property(_getAttributes, _setAttributes)
|
| 255 |
+
|
| 256 |
+
def insertText(self, data, insertBefore=None):
|
| 257 |
+
data = infosetFilter.coerceCharacters(data)
|
| 258 |
+
builder.Element.insertText(self, data, insertBefore)
|
| 259 |
+
|
| 260 |
+
def cloneNode(self):
|
| 261 |
+
element = type(self)(self.name, self.namespace)
|
| 262 |
+
if self._element.attrib:
|
| 263 |
+
element._element.attrib.update(self._element.attrib)
|
| 264 |
+
return element
|
| 265 |
+
|
| 266 |
+
class Comment(builder.Comment):
|
| 267 |
+
def __init__(self, data):
|
| 268 |
+
data = infosetFilter.coerceComment(data)
|
| 269 |
+
builder.Comment.__init__(self, data)
|
| 270 |
+
|
| 271 |
+
def _setData(self, data):
|
| 272 |
+
data = infosetFilter.coerceComment(data)
|
| 273 |
+
self._element.text = data
|
| 274 |
+
|
| 275 |
+
def _getData(self):
|
| 276 |
+
return self._element.text
|
| 277 |
+
|
| 278 |
+
data = property(_getData, _setData)
|
| 279 |
+
|
| 280 |
+
self.elementClass = Element
|
| 281 |
+
self.commentClass = Comment
|
| 282 |
+
# self.fragmentClass = builder.DocumentFragment
|
| 283 |
+
base.TreeBuilder.__init__(self, namespaceHTMLElements)
|
| 284 |
+
|
| 285 |
+
def reset(self):
|
| 286 |
+
base.TreeBuilder.reset(self)
|
| 287 |
+
self.insertComment = self.insertCommentInitial
|
| 288 |
+
self.initial_comments = []
|
| 289 |
+
self.doctype = None
|
| 290 |
+
|
| 291 |
+
def testSerializer(self, element):
|
| 292 |
+
return testSerializer(element)
|
| 293 |
+
|
| 294 |
+
def getDocument(self):
|
| 295 |
+
if fullTree:
|
| 296 |
+
return self.document._elementTree
|
| 297 |
+
else:
|
| 298 |
+
return self.document._elementTree.getroot()
|
| 299 |
+
|
| 300 |
+
def getFragment(self):
|
| 301 |
+
fragment = []
|
| 302 |
+
element = self.openElements[0]._element
|
| 303 |
+
if element.text:
|
| 304 |
+
fragment.append(element.text)
|
| 305 |
+
fragment.extend(list(element))
|
| 306 |
+
if element.tail:
|
| 307 |
+
fragment.append(element.tail)
|
| 308 |
+
return fragment
|
| 309 |
+
|
| 310 |
+
def insertDoctype(self, token):
|
| 311 |
+
name = token["name"]
|
| 312 |
+
publicId = token["publicId"]
|
| 313 |
+
systemId = token["systemId"]
|
| 314 |
+
|
| 315 |
+
if not name:
|
| 316 |
+
warnings.warn("lxml cannot represent empty doctype", DataLossWarning)
|
| 317 |
+
self.doctype = None
|
| 318 |
+
else:
|
| 319 |
+
coercedName = self.infosetFilter.coerceElement(name)
|
| 320 |
+
if coercedName != name:
|
| 321 |
+
warnings.warn("lxml cannot represent non-xml doctype", DataLossWarning)
|
| 322 |
+
|
| 323 |
+
doctype = self.doctypeClass(coercedName, publicId, systemId)
|
| 324 |
+
self.doctype = doctype
|
| 325 |
+
|
| 326 |
+
def insertCommentInitial(self, data, parent=None):
|
| 327 |
+
assert parent is None or parent is self.document
|
| 328 |
+
assert self.document._elementTree is None
|
| 329 |
+
self.initial_comments.append(data)
|
| 330 |
+
|
| 331 |
+
def insertCommentMain(self, data, parent=None):
|
| 332 |
+
if (parent == self.document and
|
| 333 |
+
self.document._elementTree.getroot()[-1].tag == comment_type):
|
| 334 |
+
warnings.warn("lxml cannot represent adjacent comments beyond the root elements", DataLossWarning)
|
| 335 |
+
super(TreeBuilder, self).insertComment(data, parent)
|
| 336 |
+
|
| 337 |
+
def insertRoot(self, token):
|
| 338 |
+
# Because of the way libxml2 works, it doesn't seem to be possible to
|
| 339 |
+
# alter information like the doctype after the tree has been parsed.
|
| 340 |
+
# Therefore we need to use the built-in parser to create our initial
|
| 341 |
+
# tree, after which we can add elements like normal
|
| 342 |
+
docStr = ""
|
| 343 |
+
if self.doctype:
|
| 344 |
+
assert self.doctype.name
|
| 345 |
+
docStr += "<!DOCTYPE %s" % self.doctype.name
|
| 346 |
+
if (self.doctype.publicId is not None or
|
| 347 |
+
self.doctype.systemId is not None):
|
| 348 |
+
docStr += (' PUBLIC "%s" ' %
|
| 349 |
+
(self.infosetFilter.coercePubid(self.doctype.publicId or "")))
|
| 350 |
+
if self.doctype.systemId:
|
| 351 |
+
sysid = self.doctype.systemId
|
| 352 |
+
if sysid.find("'") >= 0 and sysid.find('"') >= 0:
|
| 353 |
+
warnings.warn("DOCTYPE system cannot contain single and double quotes", DataLossWarning)
|
| 354 |
+
sysid = sysid.replace("'", 'U00027')
|
| 355 |
+
if sysid.find("'") >= 0:
|
| 356 |
+
docStr += '"%s"' % sysid
|
| 357 |
+
else:
|
| 358 |
+
docStr += "'%s'" % sysid
|
| 359 |
+
else:
|
| 360 |
+
docStr += "''"
|
| 361 |
+
docStr += ">"
|
| 362 |
+
if self.doctype.name != token["name"]:
|
| 363 |
+
warnings.warn("lxml cannot represent doctype with a different name to the root element", DataLossWarning)
|
| 364 |
+
docStr += "<THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>"
|
| 365 |
+
root = etree.fromstring(docStr)
|
| 366 |
+
|
| 367 |
+
# Append the initial comments:
|
| 368 |
+
for comment_token in self.initial_comments:
|
| 369 |
+
comment = self.commentClass(comment_token["data"])
|
| 370 |
+
root.addprevious(comment._element)
|
| 371 |
+
|
| 372 |
+
# Create the root document and add the ElementTree to it
|
| 373 |
+
self.document = self.documentClass()
|
| 374 |
+
self.document._elementTree = root.getroottree()
|
| 375 |
+
|
| 376 |
+
# Give the root element the right name
|
| 377 |
+
name = token["name"]
|
| 378 |
+
namespace = token.get("namespace", self.defaultNamespace)
|
| 379 |
+
if namespace is None:
|
| 380 |
+
etree_tag = name
|
| 381 |
+
else:
|
| 382 |
+
etree_tag = "{%s}%s" % (namespace, name)
|
| 383 |
+
root.tag = etree_tag
|
| 384 |
+
|
| 385 |
+
# Add the root element to the internal child/open data structures
|
| 386 |
+
root_element = self.elementClass(name, namespace)
|
| 387 |
+
root_element._element = root
|
| 388 |
+
self.document._childNodes.append(root_element)
|
| 389 |
+
self.openElements.append(root_element)
|
| 390 |
+
|
| 391 |
+
# Reset to the default insert comment function
|
| 392 |
+
self.insertComment = self.insertCommentMain
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__init__.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A collection of modules for iterating through different kinds of
|
| 2 |
+
tree, generating tokens identical to those produced by the tokenizer
|
| 3 |
+
module.
|
| 4 |
+
|
| 5 |
+
To create a tree walker for a new type of tree, you need to
|
| 6 |
+
implement a tree walker object (called TreeWalker by convention) that
|
| 7 |
+
implements a 'serialize' method which takes a tree as sole argument and
|
| 8 |
+
returns an iterator which generates tokens.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 12 |
+
|
| 13 |
+
from .. import constants
|
| 14 |
+
from .._utils import default_etree
|
| 15 |
+
|
| 16 |
+
__all__ = ["getTreeWalker", "pprint"]
|
| 17 |
+
|
| 18 |
+
treeWalkerCache = {}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def getTreeWalker(treeType, implementation=None, **kwargs):
|
| 22 |
+
"""Get a TreeWalker class for various types of tree with built-in support
|
| 23 |
+
|
| 24 |
+
:arg str treeType: the name of the tree type required (case-insensitive).
|
| 25 |
+
Supported values are:
|
| 26 |
+
|
| 27 |
+
* "dom": The xml.dom.minidom DOM implementation
|
| 28 |
+
* "etree": A generic walker for tree implementations exposing an
|
| 29 |
+
elementtree-like interface (known to work with ElementTree,
|
| 30 |
+
cElementTree and lxml.etree).
|
| 31 |
+
* "lxml": Optimized walker for lxml.etree
|
| 32 |
+
* "genshi": a Genshi stream
|
| 33 |
+
|
| 34 |
+
:arg implementation: A module implementing the tree type e.g.
|
| 35 |
+
xml.etree.ElementTree or cElementTree (Currently applies to the "etree"
|
| 36 |
+
tree type only).
|
| 37 |
+
|
| 38 |
+
:arg kwargs: keyword arguments passed to the etree walker--for other
|
| 39 |
+
walkers, this has no effect
|
| 40 |
+
|
| 41 |
+
:returns: a TreeWalker class
|
| 42 |
+
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
treeType = treeType.lower()
|
| 46 |
+
if treeType not in treeWalkerCache:
|
| 47 |
+
if treeType == "dom":
|
| 48 |
+
from . import dom
|
| 49 |
+
treeWalkerCache[treeType] = dom.TreeWalker
|
| 50 |
+
elif treeType == "genshi":
|
| 51 |
+
from . import genshi
|
| 52 |
+
treeWalkerCache[treeType] = genshi.TreeWalker
|
| 53 |
+
elif treeType == "lxml":
|
| 54 |
+
from . import etree_lxml
|
| 55 |
+
treeWalkerCache[treeType] = etree_lxml.TreeWalker
|
| 56 |
+
elif treeType == "etree":
|
| 57 |
+
from . import etree
|
| 58 |
+
if implementation is None:
|
| 59 |
+
implementation = default_etree
|
| 60 |
+
# XXX: NEVER cache here, caching is done in the etree submodule
|
| 61 |
+
return etree.getETreeModule(implementation, **kwargs).TreeWalker
|
| 62 |
+
return treeWalkerCache.get(treeType)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def concatenateCharacterTokens(tokens):
|
| 66 |
+
pendingCharacters = []
|
| 67 |
+
for token in tokens:
|
| 68 |
+
type = token["type"]
|
| 69 |
+
if type in ("Characters", "SpaceCharacters"):
|
| 70 |
+
pendingCharacters.append(token["data"])
|
| 71 |
+
else:
|
| 72 |
+
if pendingCharacters:
|
| 73 |
+
yield {"type": "Characters", "data": "".join(pendingCharacters)}
|
| 74 |
+
pendingCharacters = []
|
| 75 |
+
yield token
|
| 76 |
+
if pendingCharacters:
|
| 77 |
+
yield {"type": "Characters", "data": "".join(pendingCharacters)}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def pprint(walker):
|
| 81 |
+
"""Pretty printer for tree walkers
|
| 82 |
+
|
| 83 |
+
Takes a TreeWalker instance and pretty prints the output of walking the tree.
|
| 84 |
+
|
| 85 |
+
:arg walker: a TreeWalker instance
|
| 86 |
+
|
| 87 |
+
"""
|
| 88 |
+
output = []
|
| 89 |
+
indent = 0
|
| 90 |
+
for token in concatenateCharacterTokens(walker):
|
| 91 |
+
type = token["type"]
|
| 92 |
+
if type in ("StartTag", "EmptyTag"):
|
| 93 |
+
# tag name
|
| 94 |
+
if token["namespace"] and token["namespace"] != constants.namespaces["html"]:
|
| 95 |
+
if token["namespace"] in constants.prefixes:
|
| 96 |
+
ns = constants.prefixes[token["namespace"]]
|
| 97 |
+
else:
|
| 98 |
+
ns = token["namespace"]
|
| 99 |
+
name = "%s %s" % (ns, token["name"])
|
| 100 |
+
else:
|
| 101 |
+
name = token["name"]
|
| 102 |
+
output.append("%s<%s>" % (" " * indent, name))
|
| 103 |
+
indent += 2
|
| 104 |
+
# attributes (sorted for consistent ordering)
|
| 105 |
+
attrs = token["data"]
|
| 106 |
+
for (namespace, localname), value in sorted(attrs.items()):
|
| 107 |
+
if namespace:
|
| 108 |
+
if namespace in constants.prefixes:
|
| 109 |
+
ns = constants.prefixes[namespace]
|
| 110 |
+
else:
|
| 111 |
+
ns = namespace
|
| 112 |
+
name = "%s %s" % (ns, localname)
|
| 113 |
+
else:
|
| 114 |
+
name = localname
|
| 115 |
+
output.append("%s%s=\"%s\"" % (" " * indent, name, value))
|
| 116 |
+
# self-closing
|
| 117 |
+
if type == "EmptyTag":
|
| 118 |
+
indent -= 2
|
| 119 |
+
|
| 120 |
+
elif type == "EndTag":
|
| 121 |
+
indent -= 2
|
| 122 |
+
|
| 123 |
+
elif type == "Comment":
|
| 124 |
+
output.append("%s<!-- %s -->" % (" " * indent, token["data"]))
|
| 125 |
+
|
| 126 |
+
elif type == "Doctype":
|
| 127 |
+
if token["name"]:
|
| 128 |
+
if token["publicId"]:
|
| 129 |
+
output.append("""%s<!DOCTYPE %s "%s" "%s">""" %
|
| 130 |
+
(" " * indent,
|
| 131 |
+
token["name"],
|
| 132 |
+
token["publicId"],
|
| 133 |
+
token["systemId"] if token["systemId"] else ""))
|
| 134 |
+
elif token["systemId"]:
|
| 135 |
+
output.append("""%s<!DOCTYPE %s "" "%s">""" %
|
| 136 |
+
(" " * indent,
|
| 137 |
+
token["name"],
|
| 138 |
+
token["systemId"]))
|
| 139 |
+
else:
|
| 140 |
+
output.append("%s<!DOCTYPE %s>" % (" " * indent,
|
| 141 |
+
token["name"]))
|
| 142 |
+
else:
|
| 143 |
+
output.append("%s<!DOCTYPE >" % (" " * indent,))
|
| 144 |
+
|
| 145 |
+
elif type == "Characters":
|
| 146 |
+
output.append("%s\"%s\"" % (" " * indent, token["data"]))
|
| 147 |
+
|
| 148 |
+
elif type == "SpaceCharacters":
|
| 149 |
+
assert False, "concatenateCharacterTokens should have got rid of all Space tokens"
|
| 150 |
+
|
| 151 |
+
else:
|
| 152 |
+
raise ValueError("Unknown token type, %s" % type)
|
| 153 |
+
|
| 154 |
+
return "\n".join(output)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (4.03 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (6.99 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/dom.cpython-310.pyc
ADDED
|
Binary file (1.77 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/etree.cpython-310.pyc
ADDED
|
Binary file (3.52 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/etree_lxml.cpython-310.pyc
ADDED
|
Binary file (6.61 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/__pycache__/genshi.cpython-310.pyc
ADDED
|
Binary file (1.97 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/base.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from xml.dom import Node
|
| 4 |
+
from ..constants import namespaces, voidElements, spaceCharacters
|
| 5 |
+
|
| 6 |
+
__all__ = ["DOCUMENT", "DOCTYPE", "TEXT", "ELEMENT", "COMMENT", "ENTITY", "UNKNOWN",
|
| 7 |
+
"TreeWalker", "NonRecursiveTreeWalker"]
|
| 8 |
+
|
| 9 |
+
DOCUMENT = Node.DOCUMENT_NODE
|
| 10 |
+
DOCTYPE = Node.DOCUMENT_TYPE_NODE
|
| 11 |
+
TEXT = Node.TEXT_NODE
|
| 12 |
+
ELEMENT = Node.ELEMENT_NODE
|
| 13 |
+
COMMENT = Node.COMMENT_NODE
|
| 14 |
+
ENTITY = Node.ENTITY_NODE
|
| 15 |
+
UNKNOWN = "<#UNKNOWN#>"
|
| 16 |
+
|
| 17 |
+
spaceCharacters = "".join(spaceCharacters)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class TreeWalker(object):
|
| 21 |
+
"""Walks a tree yielding tokens
|
| 22 |
+
|
| 23 |
+
Tokens are dicts that all have a ``type`` field specifying the type of the
|
| 24 |
+
token.
|
| 25 |
+
|
| 26 |
+
"""
|
| 27 |
+
def __init__(self, tree):
|
| 28 |
+
"""Creates a TreeWalker
|
| 29 |
+
|
| 30 |
+
:arg tree: the tree to walk
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
self.tree = tree
|
| 34 |
+
|
| 35 |
+
def __iter__(self):
|
| 36 |
+
raise NotImplementedError
|
| 37 |
+
|
| 38 |
+
def error(self, msg):
|
| 39 |
+
"""Generates an error token with the given message
|
| 40 |
+
|
| 41 |
+
:arg msg: the error message
|
| 42 |
+
|
| 43 |
+
:returns: SerializeError token
|
| 44 |
+
|
| 45 |
+
"""
|
| 46 |
+
return {"type": "SerializeError", "data": msg}
|
| 47 |
+
|
| 48 |
+
def emptyTag(self, namespace, name, attrs, hasChildren=False):
|
| 49 |
+
"""Generates an EmptyTag token
|
| 50 |
+
|
| 51 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 52 |
+
|
| 53 |
+
:arg name: the name of the element
|
| 54 |
+
|
| 55 |
+
:arg attrs: the attributes of the element as a dict
|
| 56 |
+
|
| 57 |
+
:arg hasChildren: whether or not to yield a SerializationError because
|
| 58 |
+
this tag shouldn't have children
|
| 59 |
+
|
| 60 |
+
:returns: EmptyTag token
|
| 61 |
+
|
| 62 |
+
"""
|
| 63 |
+
yield {"type": "EmptyTag", "name": name,
|
| 64 |
+
"namespace": namespace,
|
| 65 |
+
"data": attrs}
|
| 66 |
+
if hasChildren:
|
| 67 |
+
yield self.error("Void element has children")
|
| 68 |
+
|
| 69 |
+
def startTag(self, namespace, name, attrs):
|
| 70 |
+
"""Generates a StartTag token
|
| 71 |
+
|
| 72 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 73 |
+
|
| 74 |
+
:arg name: the name of the element
|
| 75 |
+
|
| 76 |
+
:arg attrs: the attributes of the element as a dict
|
| 77 |
+
|
| 78 |
+
:returns: StartTag token
|
| 79 |
+
|
| 80 |
+
"""
|
| 81 |
+
return {"type": "StartTag",
|
| 82 |
+
"name": name,
|
| 83 |
+
"namespace": namespace,
|
| 84 |
+
"data": attrs}
|
| 85 |
+
|
| 86 |
+
def endTag(self, namespace, name):
|
| 87 |
+
"""Generates an EndTag token
|
| 88 |
+
|
| 89 |
+
:arg namespace: the namespace of the token--can be ``None``
|
| 90 |
+
|
| 91 |
+
:arg name: the name of the element
|
| 92 |
+
|
| 93 |
+
:returns: EndTag token
|
| 94 |
+
|
| 95 |
+
"""
|
| 96 |
+
return {"type": "EndTag",
|
| 97 |
+
"name": name,
|
| 98 |
+
"namespace": namespace}
|
| 99 |
+
|
| 100 |
+
def text(self, data):
|
| 101 |
+
"""Generates SpaceCharacters and Characters tokens
|
| 102 |
+
|
| 103 |
+
Depending on what's in the data, this generates one or more
|
| 104 |
+
``SpaceCharacters`` and ``Characters`` tokens.
|
| 105 |
+
|
| 106 |
+
For example:
|
| 107 |
+
|
| 108 |
+
>>> from html5lib.treewalkers.base import TreeWalker
|
| 109 |
+
>>> # Give it an empty tree just so it instantiates
|
| 110 |
+
>>> walker = TreeWalker([])
|
| 111 |
+
>>> list(walker.text(''))
|
| 112 |
+
[]
|
| 113 |
+
>>> list(walker.text(' '))
|
| 114 |
+
[{u'data': ' ', u'type': u'SpaceCharacters'}]
|
| 115 |
+
>>> list(walker.text(' abc ')) # doctest: +NORMALIZE_WHITESPACE
|
| 116 |
+
[{u'data': ' ', u'type': u'SpaceCharacters'},
|
| 117 |
+
{u'data': u'abc', u'type': u'Characters'},
|
| 118 |
+
{u'data': u' ', u'type': u'SpaceCharacters'}]
|
| 119 |
+
|
| 120 |
+
:arg data: the text data
|
| 121 |
+
|
| 122 |
+
:returns: one or more ``SpaceCharacters`` and ``Characters`` tokens
|
| 123 |
+
|
| 124 |
+
"""
|
| 125 |
+
data = data
|
| 126 |
+
middle = data.lstrip(spaceCharacters)
|
| 127 |
+
left = data[:len(data) - len(middle)]
|
| 128 |
+
if left:
|
| 129 |
+
yield {"type": "SpaceCharacters", "data": left}
|
| 130 |
+
data = middle
|
| 131 |
+
middle = data.rstrip(spaceCharacters)
|
| 132 |
+
right = data[len(middle):]
|
| 133 |
+
if middle:
|
| 134 |
+
yield {"type": "Characters", "data": middle}
|
| 135 |
+
if right:
|
| 136 |
+
yield {"type": "SpaceCharacters", "data": right}
|
| 137 |
+
|
| 138 |
+
def comment(self, data):
|
| 139 |
+
"""Generates a Comment token
|
| 140 |
+
|
| 141 |
+
:arg data: the comment
|
| 142 |
+
|
| 143 |
+
:returns: Comment token
|
| 144 |
+
|
| 145 |
+
"""
|
| 146 |
+
return {"type": "Comment", "data": data}
|
| 147 |
+
|
| 148 |
+
def doctype(self, name, publicId=None, systemId=None):
|
| 149 |
+
"""Generates a Doctype token
|
| 150 |
+
|
| 151 |
+
:arg name:
|
| 152 |
+
|
| 153 |
+
:arg publicId:
|
| 154 |
+
|
| 155 |
+
:arg systemId:
|
| 156 |
+
|
| 157 |
+
:returns: the Doctype token
|
| 158 |
+
|
| 159 |
+
"""
|
| 160 |
+
return {"type": "Doctype",
|
| 161 |
+
"name": name,
|
| 162 |
+
"publicId": publicId,
|
| 163 |
+
"systemId": systemId}
|
| 164 |
+
|
| 165 |
+
def entity(self, name):
|
| 166 |
+
"""Generates an Entity token
|
| 167 |
+
|
| 168 |
+
:arg name: the entity name
|
| 169 |
+
|
| 170 |
+
:returns: an Entity token
|
| 171 |
+
|
| 172 |
+
"""
|
| 173 |
+
return {"type": "Entity", "name": name}
|
| 174 |
+
|
| 175 |
+
def unknown(self, nodeType):
|
| 176 |
+
"""Handles unknown node types"""
|
| 177 |
+
return self.error("Unknown node type: " + nodeType)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
class NonRecursiveTreeWalker(TreeWalker):
|
| 181 |
+
def getNodeDetails(self, node):
|
| 182 |
+
raise NotImplementedError
|
| 183 |
+
|
| 184 |
+
def getFirstChild(self, node):
|
| 185 |
+
raise NotImplementedError
|
| 186 |
+
|
| 187 |
+
def getNextSibling(self, node):
|
| 188 |
+
raise NotImplementedError
|
| 189 |
+
|
| 190 |
+
def getParentNode(self, node):
|
| 191 |
+
raise NotImplementedError
|
| 192 |
+
|
| 193 |
+
def __iter__(self):
|
| 194 |
+
currentNode = self.tree
|
| 195 |
+
while currentNode is not None:
|
| 196 |
+
details = self.getNodeDetails(currentNode)
|
| 197 |
+
type, details = details[0], details[1:]
|
| 198 |
+
hasChildren = False
|
| 199 |
+
|
| 200 |
+
if type == DOCTYPE:
|
| 201 |
+
yield self.doctype(*details)
|
| 202 |
+
|
| 203 |
+
elif type == TEXT:
|
| 204 |
+
for token in self.text(*details):
|
| 205 |
+
yield token
|
| 206 |
+
|
| 207 |
+
elif type == ELEMENT:
|
| 208 |
+
namespace, name, attributes, hasChildren = details
|
| 209 |
+
if (not namespace or namespace == namespaces["html"]) and name in voidElements:
|
| 210 |
+
for token in self.emptyTag(namespace, name, attributes,
|
| 211 |
+
hasChildren):
|
| 212 |
+
yield token
|
| 213 |
+
hasChildren = False
|
| 214 |
+
else:
|
| 215 |
+
yield self.startTag(namespace, name, attributes)
|
| 216 |
+
|
| 217 |
+
elif type == COMMENT:
|
| 218 |
+
yield self.comment(details[0])
|
| 219 |
+
|
| 220 |
+
elif type == ENTITY:
|
| 221 |
+
yield self.entity(details[0])
|
| 222 |
+
|
| 223 |
+
elif type == DOCUMENT:
|
| 224 |
+
hasChildren = True
|
| 225 |
+
|
| 226 |
+
else:
|
| 227 |
+
yield self.unknown(details[0])
|
| 228 |
+
|
| 229 |
+
if hasChildren:
|
| 230 |
+
firstChild = self.getFirstChild(currentNode)
|
| 231 |
+
else:
|
| 232 |
+
firstChild = None
|
| 233 |
+
|
| 234 |
+
if firstChild is not None:
|
| 235 |
+
currentNode = firstChild
|
| 236 |
+
else:
|
| 237 |
+
while currentNode is not None:
|
| 238 |
+
details = self.getNodeDetails(currentNode)
|
| 239 |
+
type, details = details[0], details[1:]
|
| 240 |
+
if type == ELEMENT:
|
| 241 |
+
namespace, name, attributes, hasChildren = details
|
| 242 |
+
if (namespace and namespace != namespaces["html"]) or name not in voidElements:
|
| 243 |
+
yield self.endTag(namespace, name)
|
| 244 |
+
if self.tree is currentNode:
|
| 245 |
+
currentNode = None
|
| 246 |
+
break
|
| 247 |
+
nextSibling = self.getNextSibling(currentNode)
|
| 248 |
+
if nextSibling is not None:
|
| 249 |
+
currentNode = nextSibling
|
| 250 |
+
break
|
| 251 |
+
else:
|
| 252 |
+
currentNode = self.getParentNode(currentNode)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/dom.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from xml.dom import Node
|
| 4 |
+
|
| 5 |
+
from . import base
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class TreeWalker(base.NonRecursiveTreeWalker):
|
| 9 |
+
def getNodeDetails(self, node):
|
| 10 |
+
if node.nodeType == Node.DOCUMENT_TYPE_NODE:
|
| 11 |
+
return base.DOCTYPE, node.name, node.publicId, node.systemId
|
| 12 |
+
|
| 13 |
+
elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
|
| 14 |
+
return base.TEXT, node.nodeValue
|
| 15 |
+
|
| 16 |
+
elif node.nodeType == Node.ELEMENT_NODE:
|
| 17 |
+
attrs = {}
|
| 18 |
+
for attr in list(node.attributes.keys()):
|
| 19 |
+
attr = node.getAttributeNode(attr)
|
| 20 |
+
if attr.namespaceURI:
|
| 21 |
+
attrs[(attr.namespaceURI, attr.localName)] = attr.value
|
| 22 |
+
else:
|
| 23 |
+
attrs[(None, attr.name)] = attr.value
|
| 24 |
+
return (base.ELEMENT, node.namespaceURI, node.nodeName,
|
| 25 |
+
attrs, node.hasChildNodes())
|
| 26 |
+
|
| 27 |
+
elif node.nodeType == Node.COMMENT_NODE:
|
| 28 |
+
return base.COMMENT, node.nodeValue
|
| 29 |
+
|
| 30 |
+
elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
|
| 31 |
+
return (base.DOCUMENT,)
|
| 32 |
+
|
| 33 |
+
else:
|
| 34 |
+
return base.UNKNOWN, node.nodeType
|
| 35 |
+
|
| 36 |
+
def getFirstChild(self, node):
|
| 37 |
+
return node.firstChild
|
| 38 |
+
|
| 39 |
+
def getNextSibling(self, node):
|
| 40 |
+
return node.nextSibling
|
| 41 |
+
|
| 42 |
+
def getParentNode(self, node):
|
| 43 |
+
return node.parentNode
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/etree.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from collections import OrderedDict
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
from pip._vendor.six import string_types
|
| 7 |
+
|
| 8 |
+
from . import base
|
| 9 |
+
from .._utils import moduleFactoryFactory
|
| 10 |
+
|
| 11 |
+
tag_regexp = re.compile("{([^}]*)}(.*)")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def getETreeBuilder(ElementTreeImplementation):
|
| 15 |
+
ElementTree = ElementTreeImplementation
|
| 16 |
+
ElementTreeCommentType = ElementTree.Comment("asd").tag
|
| 17 |
+
|
| 18 |
+
class TreeWalker(base.NonRecursiveTreeWalker): # pylint:disable=unused-variable
|
| 19 |
+
"""Given the particular ElementTree representation, this implementation,
|
| 20 |
+
to avoid using recursion, returns "nodes" as tuples with the following
|
| 21 |
+
content:
|
| 22 |
+
|
| 23 |
+
1. The current element
|
| 24 |
+
|
| 25 |
+
2. The index of the element relative to its parent
|
| 26 |
+
|
| 27 |
+
3. A stack of ancestor elements
|
| 28 |
+
|
| 29 |
+
4. A flag "text", "tail" or None to indicate if the current node is a
|
| 30 |
+
text node; either the text or tail of the current element (1)
|
| 31 |
+
"""
|
| 32 |
+
def getNodeDetails(self, node):
|
| 33 |
+
if isinstance(node, tuple): # It might be the root Element
|
| 34 |
+
elt, _, _, flag = node
|
| 35 |
+
if flag in ("text", "tail"):
|
| 36 |
+
return base.TEXT, getattr(elt, flag)
|
| 37 |
+
else:
|
| 38 |
+
node = elt
|
| 39 |
+
|
| 40 |
+
if not(hasattr(node, "tag")):
|
| 41 |
+
node = node.getroot()
|
| 42 |
+
|
| 43 |
+
if node.tag in ("DOCUMENT_ROOT", "DOCUMENT_FRAGMENT"):
|
| 44 |
+
return (base.DOCUMENT,)
|
| 45 |
+
|
| 46 |
+
elif node.tag == "<!DOCTYPE>":
|
| 47 |
+
return (base.DOCTYPE, node.text,
|
| 48 |
+
node.get("publicId"), node.get("systemId"))
|
| 49 |
+
|
| 50 |
+
elif node.tag == ElementTreeCommentType:
|
| 51 |
+
return base.COMMENT, node.text
|
| 52 |
+
|
| 53 |
+
else:
|
| 54 |
+
assert isinstance(node.tag, string_types), type(node.tag)
|
| 55 |
+
# This is assumed to be an ordinary element
|
| 56 |
+
match = tag_regexp.match(node.tag)
|
| 57 |
+
if match:
|
| 58 |
+
namespace, tag = match.groups()
|
| 59 |
+
else:
|
| 60 |
+
namespace = None
|
| 61 |
+
tag = node.tag
|
| 62 |
+
attrs = OrderedDict()
|
| 63 |
+
for name, value in list(node.attrib.items()):
|
| 64 |
+
match = tag_regexp.match(name)
|
| 65 |
+
if match:
|
| 66 |
+
attrs[(match.group(1), match.group(2))] = value
|
| 67 |
+
else:
|
| 68 |
+
attrs[(None, name)] = value
|
| 69 |
+
return (base.ELEMENT, namespace, tag,
|
| 70 |
+
attrs, len(node) or node.text)
|
| 71 |
+
|
| 72 |
+
def getFirstChild(self, node):
|
| 73 |
+
if isinstance(node, tuple):
|
| 74 |
+
element, key, parents, flag = node
|
| 75 |
+
else:
|
| 76 |
+
element, key, parents, flag = node, None, [], None
|
| 77 |
+
|
| 78 |
+
if flag in ("text", "tail"):
|
| 79 |
+
return None
|
| 80 |
+
else:
|
| 81 |
+
if element.text:
|
| 82 |
+
return element, key, parents, "text"
|
| 83 |
+
elif len(element):
|
| 84 |
+
parents.append(element)
|
| 85 |
+
return element[0], 0, parents, None
|
| 86 |
+
else:
|
| 87 |
+
return None
|
| 88 |
+
|
| 89 |
+
def getNextSibling(self, node):
|
| 90 |
+
if isinstance(node, tuple):
|
| 91 |
+
element, key, parents, flag = node
|
| 92 |
+
else:
|
| 93 |
+
return None
|
| 94 |
+
|
| 95 |
+
if flag == "text":
|
| 96 |
+
if len(element):
|
| 97 |
+
parents.append(element)
|
| 98 |
+
return element[0], 0, parents, None
|
| 99 |
+
else:
|
| 100 |
+
return None
|
| 101 |
+
else:
|
| 102 |
+
if element.tail and flag != "tail":
|
| 103 |
+
return element, key, parents, "tail"
|
| 104 |
+
elif key < len(parents[-1]) - 1:
|
| 105 |
+
return parents[-1][key + 1], key + 1, parents, None
|
| 106 |
+
else:
|
| 107 |
+
return None
|
| 108 |
+
|
| 109 |
+
def getParentNode(self, node):
|
| 110 |
+
if isinstance(node, tuple):
|
| 111 |
+
element, key, parents, flag = node
|
| 112 |
+
else:
|
| 113 |
+
return None
|
| 114 |
+
|
| 115 |
+
if flag == "text":
|
| 116 |
+
if not parents:
|
| 117 |
+
return element
|
| 118 |
+
else:
|
| 119 |
+
return element, key, parents, None
|
| 120 |
+
else:
|
| 121 |
+
parent = parents.pop()
|
| 122 |
+
if not parents:
|
| 123 |
+
return parent
|
| 124 |
+
else:
|
| 125 |
+
assert list(parents[-1]).count(parent) == 1
|
| 126 |
+
return parent, list(parents[-1]).index(parent), parents, None
|
| 127 |
+
|
| 128 |
+
return locals()
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
getETreeModule = moduleFactoryFactory(getETreeBuilder)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/etree_lxml.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
from pip._vendor.six import text_type
|
| 3 |
+
|
| 4 |
+
from collections import OrderedDict
|
| 5 |
+
|
| 6 |
+
from lxml import etree
|
| 7 |
+
from ..treebuilders.etree import tag_regexp
|
| 8 |
+
|
| 9 |
+
from . import base
|
| 10 |
+
|
| 11 |
+
from .. import _ihatexml
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def ensure_str(s):
|
| 15 |
+
if s is None:
|
| 16 |
+
return None
|
| 17 |
+
elif isinstance(s, text_type):
|
| 18 |
+
return s
|
| 19 |
+
else:
|
| 20 |
+
return s.decode("ascii", "strict")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Root(object):
|
| 24 |
+
def __init__(self, et):
|
| 25 |
+
self.elementtree = et
|
| 26 |
+
self.children = []
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
if et.docinfo.internalDTD:
|
| 30 |
+
self.children.append(Doctype(self,
|
| 31 |
+
ensure_str(et.docinfo.root_name),
|
| 32 |
+
ensure_str(et.docinfo.public_id),
|
| 33 |
+
ensure_str(et.docinfo.system_url)))
|
| 34 |
+
except AttributeError:
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
node = et.getroot()
|
| 39 |
+
except AttributeError:
|
| 40 |
+
node = et
|
| 41 |
+
|
| 42 |
+
while node.getprevious() is not None:
|
| 43 |
+
node = node.getprevious()
|
| 44 |
+
while node is not None:
|
| 45 |
+
self.children.append(node)
|
| 46 |
+
node = node.getnext()
|
| 47 |
+
|
| 48 |
+
self.text = None
|
| 49 |
+
self.tail = None
|
| 50 |
+
|
| 51 |
+
def __getitem__(self, key):
|
| 52 |
+
return self.children[key]
|
| 53 |
+
|
| 54 |
+
def getnext(self):
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
def __len__(self):
|
| 58 |
+
return 1
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class Doctype(object):
|
| 62 |
+
def __init__(self, root_node, name, public_id, system_id):
|
| 63 |
+
self.root_node = root_node
|
| 64 |
+
self.name = name
|
| 65 |
+
self.public_id = public_id
|
| 66 |
+
self.system_id = system_id
|
| 67 |
+
|
| 68 |
+
self.text = None
|
| 69 |
+
self.tail = None
|
| 70 |
+
|
| 71 |
+
def getnext(self):
|
| 72 |
+
return self.root_node.children[1]
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class FragmentRoot(Root):
|
| 76 |
+
def __init__(self, children):
|
| 77 |
+
self.children = [FragmentWrapper(self, child) for child in children]
|
| 78 |
+
self.text = self.tail = None
|
| 79 |
+
|
| 80 |
+
def getnext(self):
|
| 81 |
+
return None
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class FragmentWrapper(object):
|
| 85 |
+
def __init__(self, fragment_root, obj):
|
| 86 |
+
self.root_node = fragment_root
|
| 87 |
+
self.obj = obj
|
| 88 |
+
if hasattr(self.obj, 'text'):
|
| 89 |
+
self.text = ensure_str(self.obj.text)
|
| 90 |
+
else:
|
| 91 |
+
self.text = None
|
| 92 |
+
if hasattr(self.obj, 'tail'):
|
| 93 |
+
self.tail = ensure_str(self.obj.tail)
|
| 94 |
+
else:
|
| 95 |
+
self.tail = None
|
| 96 |
+
|
| 97 |
+
def __getattr__(self, name):
|
| 98 |
+
return getattr(self.obj, name)
|
| 99 |
+
|
| 100 |
+
def getnext(self):
|
| 101 |
+
siblings = self.root_node.children
|
| 102 |
+
idx = siblings.index(self)
|
| 103 |
+
if idx < len(siblings) - 1:
|
| 104 |
+
return siblings[idx + 1]
|
| 105 |
+
else:
|
| 106 |
+
return None
|
| 107 |
+
|
| 108 |
+
def __getitem__(self, key):
|
| 109 |
+
return self.obj[key]
|
| 110 |
+
|
| 111 |
+
def __bool__(self):
|
| 112 |
+
return bool(self.obj)
|
| 113 |
+
|
| 114 |
+
def getparent(self):
|
| 115 |
+
return None
|
| 116 |
+
|
| 117 |
+
def __str__(self):
|
| 118 |
+
return str(self.obj)
|
| 119 |
+
|
| 120 |
+
def __unicode__(self):
|
| 121 |
+
return str(self.obj)
|
| 122 |
+
|
| 123 |
+
def __len__(self):
|
| 124 |
+
return len(self.obj)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
class TreeWalker(base.NonRecursiveTreeWalker):
|
| 128 |
+
def __init__(self, tree):
|
| 129 |
+
# pylint:disable=redefined-variable-type
|
| 130 |
+
if isinstance(tree, list):
|
| 131 |
+
self.fragmentChildren = set(tree)
|
| 132 |
+
tree = FragmentRoot(tree)
|
| 133 |
+
else:
|
| 134 |
+
self.fragmentChildren = set()
|
| 135 |
+
tree = Root(tree)
|
| 136 |
+
base.NonRecursiveTreeWalker.__init__(self, tree)
|
| 137 |
+
self.filter = _ihatexml.InfosetFilter()
|
| 138 |
+
|
| 139 |
+
def getNodeDetails(self, node):
|
| 140 |
+
if isinstance(node, tuple): # Text node
|
| 141 |
+
node, key = node
|
| 142 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 143 |
+
return base.TEXT, ensure_str(getattr(node, key))
|
| 144 |
+
|
| 145 |
+
elif isinstance(node, Root):
|
| 146 |
+
return (base.DOCUMENT,)
|
| 147 |
+
|
| 148 |
+
elif isinstance(node, Doctype):
|
| 149 |
+
return base.DOCTYPE, node.name, node.public_id, node.system_id
|
| 150 |
+
|
| 151 |
+
elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"):
|
| 152 |
+
return base.TEXT, ensure_str(node.obj)
|
| 153 |
+
|
| 154 |
+
elif node.tag == etree.Comment:
|
| 155 |
+
return base.COMMENT, ensure_str(node.text)
|
| 156 |
+
|
| 157 |
+
elif node.tag == etree.Entity:
|
| 158 |
+
return base.ENTITY, ensure_str(node.text)[1:-1] # strip &;
|
| 159 |
+
|
| 160 |
+
else:
|
| 161 |
+
# This is assumed to be an ordinary element
|
| 162 |
+
match = tag_regexp.match(ensure_str(node.tag))
|
| 163 |
+
if match:
|
| 164 |
+
namespace, tag = match.groups()
|
| 165 |
+
else:
|
| 166 |
+
namespace = None
|
| 167 |
+
tag = ensure_str(node.tag)
|
| 168 |
+
attrs = OrderedDict()
|
| 169 |
+
for name, value in list(node.attrib.items()):
|
| 170 |
+
name = ensure_str(name)
|
| 171 |
+
value = ensure_str(value)
|
| 172 |
+
match = tag_regexp.match(name)
|
| 173 |
+
if match:
|
| 174 |
+
attrs[(match.group(1), match.group(2))] = value
|
| 175 |
+
else:
|
| 176 |
+
attrs[(None, name)] = value
|
| 177 |
+
return (base.ELEMENT, namespace, self.filter.fromXmlName(tag),
|
| 178 |
+
attrs, len(node) > 0 or node.text)
|
| 179 |
+
|
| 180 |
+
def getFirstChild(self, node):
|
| 181 |
+
assert not isinstance(node, tuple), "Text nodes have no children"
|
| 182 |
+
|
| 183 |
+
assert len(node) or node.text, "Node has no children"
|
| 184 |
+
if node.text:
|
| 185 |
+
return (node, "text")
|
| 186 |
+
else:
|
| 187 |
+
return node[0]
|
| 188 |
+
|
| 189 |
+
def getNextSibling(self, node):
|
| 190 |
+
if isinstance(node, tuple): # Text node
|
| 191 |
+
node, key = node
|
| 192 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 193 |
+
if key == "text":
|
| 194 |
+
# XXX: we cannot use a "bool(node) and node[0] or None" construct here
|
| 195 |
+
# because node[0] might evaluate to False if it has no child element
|
| 196 |
+
if len(node):
|
| 197 |
+
return node[0]
|
| 198 |
+
else:
|
| 199 |
+
return None
|
| 200 |
+
else: # tail
|
| 201 |
+
return node.getnext()
|
| 202 |
+
|
| 203 |
+
return (node, "tail") if node.tail else node.getnext()
|
| 204 |
+
|
| 205 |
+
def getParentNode(self, node):
|
| 206 |
+
if isinstance(node, tuple): # Text node
|
| 207 |
+
node, key = node
|
| 208 |
+
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
|
| 209 |
+
if key == "text":
|
| 210 |
+
return node
|
| 211 |
+
# else: fallback to "normal" processing
|
| 212 |
+
elif node in self.fragmentChildren:
|
| 213 |
+
return None
|
| 214 |
+
|
| 215 |
+
return node.getparent()
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/html5lib/treewalkers/genshi.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import, division, unicode_literals
|
| 2 |
+
|
| 3 |
+
from genshi.core import QName
|
| 4 |
+
from genshi.core import START, END, XML_NAMESPACE, DOCTYPE, TEXT
|
| 5 |
+
from genshi.core import START_NS, END_NS, START_CDATA, END_CDATA, PI, COMMENT
|
| 6 |
+
|
| 7 |
+
from . import base
|
| 8 |
+
|
| 9 |
+
from ..constants import voidElements, namespaces
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class TreeWalker(base.TreeWalker):
|
| 13 |
+
def __iter__(self):
|
| 14 |
+
# Buffer the events so we can pass in the following one
|
| 15 |
+
previous = None
|
| 16 |
+
for event in self.tree:
|
| 17 |
+
if previous is not None:
|
| 18 |
+
for token in self.tokens(previous, event):
|
| 19 |
+
yield token
|
| 20 |
+
previous = event
|
| 21 |
+
|
| 22 |
+
# Don't forget the final event!
|
| 23 |
+
if previous is not None:
|
| 24 |
+
for token in self.tokens(previous, None):
|
| 25 |
+
yield token
|
| 26 |
+
|
| 27 |
+
def tokens(self, event, next):
|
| 28 |
+
kind, data, _ = event
|
| 29 |
+
if kind == START:
|
| 30 |
+
tag, attribs = data
|
| 31 |
+
name = tag.localname
|
| 32 |
+
namespace = tag.namespace
|
| 33 |
+
converted_attribs = {}
|
| 34 |
+
for k, v in attribs:
|
| 35 |
+
if isinstance(k, QName):
|
| 36 |
+
converted_attribs[(k.namespace, k.localname)] = v
|
| 37 |
+
else:
|
| 38 |
+
converted_attribs[(None, k)] = v
|
| 39 |
+
|
| 40 |
+
if namespace == namespaces["html"] and name in voidElements:
|
| 41 |
+
for token in self.emptyTag(namespace, name, converted_attribs,
|
| 42 |
+
not next or next[0] != END or
|
| 43 |
+
next[1] != tag):
|
| 44 |
+
yield token
|
| 45 |
+
else:
|
| 46 |
+
yield self.startTag(namespace, name, converted_attribs)
|
| 47 |
+
|
| 48 |
+
elif kind == END:
|
| 49 |
+
name = data.localname
|
| 50 |
+
namespace = data.namespace
|
| 51 |
+
if namespace != namespaces["html"] or name not in voidElements:
|
| 52 |
+
yield self.endTag(namespace, name)
|
| 53 |
+
|
| 54 |
+
elif kind == COMMENT:
|
| 55 |
+
yield self.comment(data)
|
| 56 |
+
|
| 57 |
+
elif kind == TEXT:
|
| 58 |
+
for token in self.text(data):
|
| 59 |
+
yield token
|
| 60 |
+
|
| 61 |
+
elif kind == DOCTYPE:
|
| 62 |
+
yield self.doctype(*data)
|
| 63 |
+
|
| 64 |
+
elif kind in (XML_NAMESPACE, DOCTYPE, START_NS, END_NS,
|
| 65 |
+
START_CDATA, END_CDATA, PI):
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
else:
|
| 69 |
+
yield self.unknown(kind)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__init__.py
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utilities for determining application-specific dirs. See <https://github.com/platformdirs/platformdirs> for details and
|
| 3 |
+
usage.
|
| 4 |
+
"""
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
+
import importlib
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import TYPE_CHECKING
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from pip._vendor.typing_extensions import Literal # pragma: no cover
|
| 15 |
+
|
| 16 |
+
from .api import PlatformDirsABC
|
| 17 |
+
from .version import __version__, __version_info__
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _set_platform_dir_class() -> type[PlatformDirsABC]:
|
| 21 |
+
if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
|
| 22 |
+
module, name = "pip._vendor.platformdirs.android", "Android"
|
| 23 |
+
elif sys.platform == "win32":
|
| 24 |
+
module, name = "pip._vendor.platformdirs.windows", "Windows"
|
| 25 |
+
elif sys.platform == "darwin":
|
| 26 |
+
module, name = "pip._vendor.platformdirs.macos", "MacOS"
|
| 27 |
+
else:
|
| 28 |
+
module, name = "pip._vendor.platformdirs.unix", "Unix"
|
| 29 |
+
result: type[PlatformDirsABC] = getattr(importlib.import_module(module), name)
|
| 30 |
+
return result
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
PlatformDirs = _set_platform_dir_class() #: Currently active platform
|
| 34 |
+
AppDirs = PlatformDirs #: Backwards compatibility with appdirs
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def user_data_dir(
|
| 38 |
+
appname: str | None = None,
|
| 39 |
+
appauthor: str | None | Literal[False] = None,
|
| 40 |
+
version: str | None = None,
|
| 41 |
+
roaming: bool = False,
|
| 42 |
+
) -> str:
|
| 43 |
+
"""
|
| 44 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 45 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 46 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 47 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 48 |
+
:returns: data directory tied to the user
|
| 49 |
+
"""
|
| 50 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_data_dir
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def site_data_dir(
|
| 54 |
+
appname: str | None = None,
|
| 55 |
+
appauthor: str | None | Literal[False] = None,
|
| 56 |
+
version: str | None = None,
|
| 57 |
+
multipath: bool = False,
|
| 58 |
+
) -> str:
|
| 59 |
+
"""
|
| 60 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 61 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 62 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 63 |
+
:param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
|
| 64 |
+
:returns: data directory shared by users
|
| 65 |
+
"""
|
| 66 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_data_dir
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def user_config_dir(
|
| 70 |
+
appname: str | None = None,
|
| 71 |
+
appauthor: str | None | Literal[False] = None,
|
| 72 |
+
version: str | None = None,
|
| 73 |
+
roaming: bool = False,
|
| 74 |
+
) -> str:
|
| 75 |
+
"""
|
| 76 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 77 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 78 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 79 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 80 |
+
:returns: config directory tied to the user
|
| 81 |
+
"""
|
| 82 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_config_dir
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def site_config_dir(
|
| 86 |
+
appname: str | None = None,
|
| 87 |
+
appauthor: str | None | Literal[False] = None,
|
| 88 |
+
version: str | None = None,
|
| 89 |
+
multipath: bool = False,
|
| 90 |
+
) -> str:
|
| 91 |
+
"""
|
| 92 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 93 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 94 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 95 |
+
:param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
|
| 96 |
+
:returns: config directory shared by the users
|
| 97 |
+
"""
|
| 98 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_config_dir
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def user_cache_dir(
|
| 102 |
+
appname: str | None = None,
|
| 103 |
+
appauthor: str | None | Literal[False] = None,
|
| 104 |
+
version: str | None = None,
|
| 105 |
+
opinion: bool = True,
|
| 106 |
+
) -> str:
|
| 107 |
+
"""
|
| 108 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 109 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 110 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 111 |
+
:param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 112 |
+
:returns: cache directory tied to the user
|
| 113 |
+
"""
|
| 114 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_cache_dir
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def user_state_dir(
|
| 118 |
+
appname: str | None = None,
|
| 119 |
+
appauthor: str | None | Literal[False] = None,
|
| 120 |
+
version: str | None = None,
|
| 121 |
+
roaming: bool = False,
|
| 122 |
+
) -> str:
|
| 123 |
+
"""
|
| 124 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 125 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 126 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 127 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 128 |
+
:returns: state directory tied to the user
|
| 129 |
+
"""
|
| 130 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_state_dir
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def user_log_dir(
|
| 134 |
+
appname: str | None = None,
|
| 135 |
+
appauthor: str | None | Literal[False] = None,
|
| 136 |
+
version: str | None = None,
|
| 137 |
+
opinion: bool = True,
|
| 138 |
+
) -> str:
|
| 139 |
+
"""
|
| 140 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 141 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 142 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 143 |
+
:param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 144 |
+
:returns: log directory tied to the user
|
| 145 |
+
"""
|
| 146 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_log_dir
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def user_documents_dir() -> str:
|
| 150 |
+
"""
|
| 151 |
+
:returns: documents directory tied to the user
|
| 152 |
+
"""
|
| 153 |
+
return PlatformDirs().user_documents_dir
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def user_runtime_dir(
|
| 157 |
+
appname: str | None = None,
|
| 158 |
+
appauthor: str | None | Literal[False] = None,
|
| 159 |
+
version: str | None = None,
|
| 160 |
+
opinion: bool = True,
|
| 161 |
+
) -> str:
|
| 162 |
+
"""
|
| 163 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 164 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 165 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 166 |
+
:param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 167 |
+
:returns: runtime directory tied to the user
|
| 168 |
+
"""
|
| 169 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_runtime_dir
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def user_data_path(
|
| 173 |
+
appname: str | None = None,
|
| 174 |
+
appauthor: str | None | Literal[False] = None,
|
| 175 |
+
version: str | None = None,
|
| 176 |
+
roaming: bool = False,
|
| 177 |
+
) -> Path:
|
| 178 |
+
"""
|
| 179 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 180 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 181 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 182 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 183 |
+
:returns: data path tied to the user
|
| 184 |
+
"""
|
| 185 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_data_path
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def site_data_path(
|
| 189 |
+
appname: str | None = None,
|
| 190 |
+
appauthor: str | None | Literal[False] = None,
|
| 191 |
+
version: str | None = None,
|
| 192 |
+
multipath: bool = False,
|
| 193 |
+
) -> Path:
|
| 194 |
+
"""
|
| 195 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 196 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 197 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 198 |
+
:param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
|
| 199 |
+
:returns: data path shared by users
|
| 200 |
+
"""
|
| 201 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_data_path
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def user_config_path(
|
| 205 |
+
appname: str | None = None,
|
| 206 |
+
appauthor: str | None | Literal[False] = None,
|
| 207 |
+
version: str | None = None,
|
| 208 |
+
roaming: bool = False,
|
| 209 |
+
) -> Path:
|
| 210 |
+
"""
|
| 211 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 212 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 213 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 214 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 215 |
+
:returns: config path tied to the user
|
| 216 |
+
"""
|
| 217 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_config_path
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def site_config_path(
|
| 221 |
+
appname: str | None = None,
|
| 222 |
+
appauthor: str | None | Literal[False] = None,
|
| 223 |
+
version: str | None = None,
|
| 224 |
+
multipath: bool = False,
|
| 225 |
+
) -> Path:
|
| 226 |
+
"""
|
| 227 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 228 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 229 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 230 |
+
:param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
|
| 231 |
+
:returns: config path shared by the users
|
| 232 |
+
"""
|
| 233 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_config_path
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def user_cache_path(
|
| 237 |
+
appname: str | None = None,
|
| 238 |
+
appauthor: str | None | Literal[False] = None,
|
| 239 |
+
version: str | None = None,
|
| 240 |
+
opinion: bool = True,
|
| 241 |
+
) -> Path:
|
| 242 |
+
"""
|
| 243 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 244 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 245 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 246 |
+
:param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 247 |
+
:returns: cache path tied to the user
|
| 248 |
+
"""
|
| 249 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_cache_path
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def user_state_path(
|
| 253 |
+
appname: str | None = None,
|
| 254 |
+
appauthor: str | None | Literal[False] = None,
|
| 255 |
+
version: str | None = None,
|
| 256 |
+
roaming: bool = False,
|
| 257 |
+
) -> Path:
|
| 258 |
+
"""
|
| 259 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 260 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 261 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 262 |
+
:param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
|
| 263 |
+
:returns: state path tied to the user
|
| 264 |
+
"""
|
| 265 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_state_path
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def user_log_path(
|
| 269 |
+
appname: str | None = None,
|
| 270 |
+
appauthor: str | None | Literal[False] = None,
|
| 271 |
+
version: str | None = None,
|
| 272 |
+
opinion: bool = True,
|
| 273 |
+
) -> Path:
|
| 274 |
+
"""
|
| 275 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 276 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 277 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 278 |
+
:param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 279 |
+
:returns: log path tied to the user
|
| 280 |
+
"""
|
| 281 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_log_path
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def user_documents_path() -> Path:
|
| 285 |
+
"""
|
| 286 |
+
:returns: documents path tied to the user
|
| 287 |
+
"""
|
| 288 |
+
return PlatformDirs().user_documents_path
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def user_runtime_path(
|
| 292 |
+
appname: str | None = None,
|
| 293 |
+
appauthor: str | None | Literal[False] = None,
|
| 294 |
+
version: str | None = None,
|
| 295 |
+
opinion: bool = True,
|
| 296 |
+
) -> Path:
|
| 297 |
+
"""
|
| 298 |
+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
|
| 299 |
+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
|
| 300 |
+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
|
| 301 |
+
:param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
|
| 302 |
+
:returns: runtime path tied to the user
|
| 303 |
+
"""
|
| 304 |
+
return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_runtime_path
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
__all__ = [
|
| 308 |
+
"__version__",
|
| 309 |
+
"__version_info__",
|
| 310 |
+
"PlatformDirs",
|
| 311 |
+
"AppDirs",
|
| 312 |
+
"PlatformDirsABC",
|
| 313 |
+
"user_data_dir",
|
| 314 |
+
"user_config_dir",
|
| 315 |
+
"user_cache_dir",
|
| 316 |
+
"user_state_dir",
|
| 317 |
+
"user_log_dir",
|
| 318 |
+
"user_documents_dir",
|
| 319 |
+
"user_runtime_dir",
|
| 320 |
+
"site_data_dir",
|
| 321 |
+
"site_config_dir",
|
| 322 |
+
"user_data_path",
|
| 323 |
+
"user_config_path",
|
| 324 |
+
"user_cache_path",
|
| 325 |
+
"user_state_path",
|
| 326 |
+
"user_log_path",
|
| 327 |
+
"user_documents_path",
|
| 328 |
+
"user_runtime_path",
|
| 329 |
+
"site_data_path",
|
| 330 |
+
"site_config_path",
|
| 331 |
+
]
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__main__.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from pip._vendor.platformdirs import PlatformDirs, __version__
|
| 4 |
+
|
| 5 |
+
PROPS = (
|
| 6 |
+
"user_data_dir",
|
| 7 |
+
"user_config_dir",
|
| 8 |
+
"user_cache_dir",
|
| 9 |
+
"user_state_dir",
|
| 10 |
+
"user_log_dir",
|
| 11 |
+
"user_documents_dir",
|
| 12 |
+
"user_runtime_dir",
|
| 13 |
+
"site_data_dir",
|
| 14 |
+
"site_config_dir",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main() -> None:
|
| 19 |
+
app_name = "MyApp"
|
| 20 |
+
app_author = "MyCompany"
|
| 21 |
+
|
| 22 |
+
print(f"-- platformdirs {__version__} --")
|
| 23 |
+
|
| 24 |
+
print("-- app dirs (with optional 'version')")
|
| 25 |
+
dirs = PlatformDirs(app_name, app_author, version="1.0")
|
| 26 |
+
for prop in PROPS:
|
| 27 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 28 |
+
|
| 29 |
+
print("\n-- app dirs (without optional 'version')")
|
| 30 |
+
dirs = PlatformDirs(app_name, app_author)
|
| 31 |
+
for prop in PROPS:
|
| 32 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 33 |
+
|
| 34 |
+
print("\n-- app dirs (without optional 'appauthor')")
|
| 35 |
+
dirs = PlatformDirs(app_name)
|
| 36 |
+
for prop in PROPS:
|
| 37 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 38 |
+
|
| 39 |
+
print("\n-- app dirs (with disabled 'appauthor')")
|
| 40 |
+
dirs = PlatformDirs(app_name, appauthor=False)
|
| 41 |
+
for prop in PROPS:
|
| 42 |
+
print(f"{prop}: {getattr(dirs, prop)}")
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (1.29 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/api.cpython-310.pyc
ADDED
|
Binary file (5.25 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/version.cpython-310.pyc
ADDED
|
Binary file (346 Bytes). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/__pycache__/windows.cpython-310.pyc
ADDED
|
Binary file (6.49 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/android.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import sys
|
| 6 |
+
from functools import lru_cache
|
| 7 |
+
|
| 8 |
+
from .api import PlatformDirsABC
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class Android(PlatformDirsABC):
|
| 12 |
+
"""
|
| 13 |
+
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Makes use of the
|
| 14 |
+
`appname <platformdirs.api.PlatformDirsABC.appname>` and
|
| 15 |
+
`version <platformdirs.api.PlatformDirsABC.version>`.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
@property
|
| 19 |
+
def user_data_dir(self) -> str:
|
| 20 |
+
""":return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``"""
|
| 21 |
+
return self._append_app_name_and_version(_android_folder(), "files")
|
| 22 |
+
|
| 23 |
+
@property
|
| 24 |
+
def site_data_dir(self) -> str:
|
| 25 |
+
""":return: data directory shared by users, same as `user_data_dir`"""
|
| 26 |
+
return self.user_data_dir
|
| 27 |
+
|
| 28 |
+
@property
|
| 29 |
+
def user_config_dir(self) -> str:
|
| 30 |
+
"""
|
| 31 |
+
:return: config directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
|
| 32 |
+
"""
|
| 33 |
+
return self._append_app_name_and_version(_android_folder(), "shared_prefs")
|
| 34 |
+
|
| 35 |
+
@property
|
| 36 |
+
def site_config_dir(self) -> str:
|
| 37 |
+
""":return: config directory shared by the users, same as `user_config_dir`"""
|
| 38 |
+
return self.user_config_dir
|
| 39 |
+
|
| 40 |
+
@property
|
| 41 |
+
def user_cache_dir(self) -> str:
|
| 42 |
+
""":return: cache directory tied to the user, e.g. e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>``"""
|
| 43 |
+
return self._append_app_name_and_version(_android_folder(), "cache")
|
| 44 |
+
|
| 45 |
+
@property
|
| 46 |
+
def user_state_dir(self) -> str:
|
| 47 |
+
""":return: state directory tied to the user, same as `user_data_dir`"""
|
| 48 |
+
return self.user_data_dir
|
| 49 |
+
|
| 50 |
+
@property
|
| 51 |
+
def user_log_dir(self) -> str:
|
| 52 |
+
"""
|
| 53 |
+
:return: log directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it,
|
| 54 |
+
e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``
|
| 55 |
+
"""
|
| 56 |
+
path = self.user_cache_dir
|
| 57 |
+
if self.opinion:
|
| 58 |
+
path = os.path.join(path, "log")
|
| 59 |
+
return path
|
| 60 |
+
|
| 61 |
+
@property
|
| 62 |
+
def user_documents_dir(self) -> str:
|
| 63 |
+
"""
|
| 64 |
+
:return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``
|
| 65 |
+
"""
|
| 66 |
+
return _android_documents_folder()
|
| 67 |
+
|
| 68 |
+
@property
|
| 69 |
+
def user_runtime_dir(self) -> str:
|
| 70 |
+
"""
|
| 71 |
+
:return: runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it,
|
| 72 |
+
e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``
|
| 73 |
+
"""
|
| 74 |
+
path = self.user_cache_dir
|
| 75 |
+
if self.opinion:
|
| 76 |
+
path = os.path.join(path, "tmp")
|
| 77 |
+
return path
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@lru_cache(maxsize=1)
|
| 81 |
+
def _android_folder() -> str:
|
| 82 |
+
""":return: base folder for the Android OS"""
|
| 83 |
+
try:
|
| 84 |
+
# First try to get path to android app via pyjnius
|
| 85 |
+
from jnius import autoclass
|
| 86 |
+
|
| 87 |
+
Context = autoclass("android.content.Context") # noqa: N806
|
| 88 |
+
result: str = Context.getFilesDir().getParentFile().getAbsolutePath()
|
| 89 |
+
except Exception:
|
| 90 |
+
# if fails find an android folder looking path on the sys.path
|
| 91 |
+
pattern = re.compile(r"/data/(data|user/\d+)/(.+)/files")
|
| 92 |
+
for path in sys.path:
|
| 93 |
+
if pattern.match(path):
|
| 94 |
+
result = path.split("/files")[0]
|
| 95 |
+
break
|
| 96 |
+
else:
|
| 97 |
+
raise OSError("Cannot find path to android app folder")
|
| 98 |
+
return result
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@lru_cache(maxsize=1)
|
| 102 |
+
def _android_documents_folder() -> str:
|
| 103 |
+
""":return: documents folder for the Android OS"""
|
| 104 |
+
# Get directories with pyjnius
|
| 105 |
+
try:
|
| 106 |
+
from jnius import autoclass
|
| 107 |
+
|
| 108 |
+
Context = autoclass("android.content.Context") # noqa: N806
|
| 109 |
+
Environment = autoclass("android.os.Environment") # noqa: N806
|
| 110 |
+
documents_dir: str = Context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath()
|
| 111 |
+
except Exception:
|
| 112 |
+
documents_dir = "/storage/emulated/0/Documents"
|
| 113 |
+
|
| 114 |
+
return documents_dir
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
__all__ = [
|
| 118 |
+
"Android",
|
| 119 |
+
]
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/api.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from abc import ABC, abstractmethod
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
if sys.version_info >= (3, 8): # pragma: no branch
|
| 9 |
+
from typing import Literal # pragma: no cover
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class PlatformDirsABC(ABC):
|
| 13 |
+
"""
|
| 14 |
+
Abstract base class for platform directories.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
def __init__(
|
| 18 |
+
self,
|
| 19 |
+
appname: str | None = None,
|
| 20 |
+
appauthor: str | None | Literal[False] = None,
|
| 21 |
+
version: str | None = None,
|
| 22 |
+
roaming: bool = False,
|
| 23 |
+
multipath: bool = False,
|
| 24 |
+
opinion: bool = True,
|
| 25 |
+
):
|
| 26 |
+
"""
|
| 27 |
+
Create a new platform directory.
|
| 28 |
+
|
| 29 |
+
:param appname: See `appname`.
|
| 30 |
+
:param appauthor: See `appauthor`.
|
| 31 |
+
:param version: See `version`.
|
| 32 |
+
:param roaming: See `roaming`.
|
| 33 |
+
:param multipath: See `multipath`.
|
| 34 |
+
:param opinion: See `opinion`.
|
| 35 |
+
"""
|
| 36 |
+
self.appname = appname #: The name of application.
|
| 37 |
+
self.appauthor = appauthor
|
| 38 |
+
"""
|
| 39 |
+
The name of the app author or distributing body for this application. Typically, it is the owning company name.
|
| 40 |
+
Defaults to `appname`. You may pass ``False`` to disable it.
|
| 41 |
+
"""
|
| 42 |
+
self.version = version
|
| 43 |
+
"""
|
| 44 |
+
An optional version path element to append to the path. You might want to use this if you want multiple versions
|
| 45 |
+
of your app to be able to run independently. If used, this would typically be ``<major>.<minor>``.
|
| 46 |
+
"""
|
| 47 |
+
self.roaming = roaming
|
| 48 |
+
"""
|
| 49 |
+
Whether to use the roaming appdata directory on Windows. That means that for users on a Windows network setup
|
| 50 |
+
for roaming profiles, this user data will be synced on login (see
|
| 51 |
+
`here <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>`_).
|
| 52 |
+
"""
|
| 53 |
+
self.multipath = multipath
|
| 54 |
+
"""
|
| 55 |
+
An optional parameter only applicable to Unix/Linux which indicates that the entire list of data dirs should be
|
| 56 |
+
returned. By default, the first item would only be returned.
|
| 57 |
+
"""
|
| 58 |
+
self.opinion = opinion #: A flag to indicating to use opinionated values.
|
| 59 |
+
|
| 60 |
+
def _append_app_name_and_version(self, *base: str) -> str:
|
| 61 |
+
params = list(base[1:])
|
| 62 |
+
if self.appname:
|
| 63 |
+
params.append(self.appname)
|
| 64 |
+
if self.version:
|
| 65 |
+
params.append(self.version)
|
| 66 |
+
return os.path.join(base[0], *params)
|
| 67 |
+
|
| 68 |
+
@property
|
| 69 |
+
@abstractmethod
|
| 70 |
+
def user_data_dir(self) -> str:
|
| 71 |
+
""":return: data directory tied to the user"""
|
| 72 |
+
|
| 73 |
+
@property
|
| 74 |
+
@abstractmethod
|
| 75 |
+
def site_data_dir(self) -> str:
|
| 76 |
+
""":return: data directory shared by users"""
|
| 77 |
+
|
| 78 |
+
@property
|
| 79 |
+
@abstractmethod
|
| 80 |
+
def user_config_dir(self) -> str:
|
| 81 |
+
""":return: config directory tied to the user"""
|
| 82 |
+
|
| 83 |
+
@property
|
| 84 |
+
@abstractmethod
|
| 85 |
+
def site_config_dir(self) -> str:
|
| 86 |
+
""":return: config directory shared by the users"""
|
| 87 |
+
|
| 88 |
+
@property
|
| 89 |
+
@abstractmethod
|
| 90 |
+
def user_cache_dir(self) -> str:
|
| 91 |
+
""":return: cache directory tied to the user"""
|
| 92 |
+
|
| 93 |
+
@property
|
| 94 |
+
@abstractmethod
|
| 95 |
+
def user_state_dir(self) -> str:
|
| 96 |
+
""":return: state directory tied to the user"""
|
| 97 |
+
|
| 98 |
+
@property
|
| 99 |
+
@abstractmethod
|
| 100 |
+
def user_log_dir(self) -> str:
|
| 101 |
+
""":return: log directory tied to the user"""
|
| 102 |
+
|
| 103 |
+
@property
|
| 104 |
+
@abstractmethod
|
| 105 |
+
def user_documents_dir(self) -> str:
|
| 106 |
+
""":return: documents directory tied to the user"""
|
| 107 |
+
|
| 108 |
+
@property
|
| 109 |
+
@abstractmethod
|
| 110 |
+
def user_runtime_dir(self) -> str:
|
| 111 |
+
""":return: runtime directory tied to the user"""
|
| 112 |
+
|
| 113 |
+
@property
|
| 114 |
+
def user_data_path(self) -> Path:
|
| 115 |
+
""":return: data path tied to the user"""
|
| 116 |
+
return Path(self.user_data_dir)
|
| 117 |
+
|
| 118 |
+
@property
|
| 119 |
+
def site_data_path(self) -> Path:
|
| 120 |
+
""":return: data path shared by users"""
|
| 121 |
+
return Path(self.site_data_dir)
|
| 122 |
+
|
| 123 |
+
@property
|
| 124 |
+
def user_config_path(self) -> Path:
|
| 125 |
+
""":return: config path tied to the user"""
|
| 126 |
+
return Path(self.user_config_dir)
|
| 127 |
+
|
| 128 |
+
@property
|
| 129 |
+
def site_config_path(self) -> Path:
|
| 130 |
+
""":return: config path shared by the users"""
|
| 131 |
+
return Path(self.site_config_dir)
|
| 132 |
+
|
| 133 |
+
@property
|
| 134 |
+
def user_cache_path(self) -> Path:
|
| 135 |
+
""":return: cache path tied to the user"""
|
| 136 |
+
return Path(self.user_cache_dir)
|
| 137 |
+
|
| 138 |
+
@property
|
| 139 |
+
def user_state_path(self) -> Path:
|
| 140 |
+
""":return: state path tied to the user"""
|
| 141 |
+
return Path(self.user_state_dir)
|
| 142 |
+
|
| 143 |
+
@property
|
| 144 |
+
def user_log_path(self) -> Path:
|
| 145 |
+
""":return: log path tied to the user"""
|
| 146 |
+
return Path(self.user_log_dir)
|
| 147 |
+
|
| 148 |
+
@property
|
| 149 |
+
def user_documents_path(self) -> Path:
|
| 150 |
+
""":return: documents path tied to the user"""
|
| 151 |
+
return Path(self.user_documents_dir)
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def user_runtime_path(self) -> Path:
|
| 155 |
+
""":return: runtime path tied to the user"""
|
| 156 |
+
return Path(self.user_runtime_dir)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/macos.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
from .api import PlatformDirsABC
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class MacOS(PlatformDirsABC):
|
| 9 |
+
"""
|
| 10 |
+
Platform directories for the macOS operating system. Follows the guidance from `Apple documentation
|
| 11 |
+
<https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
|
| 12 |
+
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>` and
|
| 13 |
+
`version <platformdirs.api.PlatformDirsABC.version>`.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
@property
|
| 17 |
+
def user_data_dir(self) -> str:
|
| 18 |
+
""":return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
|
| 19 |
+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support/"))
|
| 20 |
+
|
| 21 |
+
@property
|
| 22 |
+
def site_data_dir(self) -> str:
|
| 23 |
+
""":return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``"""
|
| 24 |
+
return self._append_app_name_and_version("/Library/Application Support")
|
| 25 |
+
|
| 26 |
+
@property
|
| 27 |
+
def user_config_dir(self) -> str:
|
| 28 |
+
""":return: config directory tied to the user, e.g. ``~/Library/Preferences/$appname/$version``"""
|
| 29 |
+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Preferences/"))
|
| 30 |
+
|
| 31 |
+
@property
|
| 32 |
+
def site_config_dir(self) -> str:
|
| 33 |
+
""":return: config directory shared by the users, e.g. ``/Library/Preferences/$appname``"""
|
| 34 |
+
return self._append_app_name_and_version("/Library/Preferences")
|
| 35 |
+
|
| 36 |
+
@property
|
| 37 |
+
def user_cache_dir(self) -> str:
|
| 38 |
+
""":return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``"""
|
| 39 |
+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches"))
|
| 40 |
+
|
| 41 |
+
@property
|
| 42 |
+
def user_state_dir(self) -> str:
|
| 43 |
+
""":return: state directory tied to the user, same as `user_data_dir`"""
|
| 44 |
+
return self.user_data_dir
|
| 45 |
+
|
| 46 |
+
@property
|
| 47 |
+
def user_log_dir(self) -> str:
|
| 48 |
+
""":return: log directory tied to the user, e.g. ``~/Library/Logs/$appname/$version``"""
|
| 49 |
+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Logs"))
|
| 50 |
+
|
| 51 |
+
@property
|
| 52 |
+
def user_documents_dir(self) -> str:
|
| 53 |
+
""":return: documents directory tied to the user, e.g. ``~/Documents``"""
|
| 54 |
+
return os.path.expanduser("~/Documents")
|
| 55 |
+
|
| 56 |
+
@property
|
| 57 |
+
def user_runtime_dir(self) -> str:
|
| 58 |
+
""":return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``"""
|
| 59 |
+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems"))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
__all__ = [
|
| 63 |
+
"MacOS",
|
| 64 |
+
]
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/platformdirs/version.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Version information """
|
| 2 |
+
|
| 3 |
+
__version__ = "2.4.1"
|
| 4 |
+
__version_info__ = (2, 4, 1)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__init__.py
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
+
# __
|
| 4 |
+
# /__) _ _ _ _ _/ _
|
| 5 |
+
# / ( (- (/ (/ (- _) / _)
|
| 6 |
+
# /
|
| 7 |
+
|
| 8 |
+
"""
|
| 9 |
+
Requests HTTP Library
|
| 10 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 11 |
+
|
| 12 |
+
Requests is an HTTP library, written in Python, for human beings.
|
| 13 |
+
Basic GET usage:
|
| 14 |
+
|
| 15 |
+
>>> import requests
|
| 16 |
+
>>> r = requests.get('https://www.python.org')
|
| 17 |
+
>>> r.status_code
|
| 18 |
+
200
|
| 19 |
+
>>> b'Python is a programming language' in r.content
|
| 20 |
+
True
|
| 21 |
+
|
| 22 |
+
... or POST:
|
| 23 |
+
|
| 24 |
+
>>> payload = dict(key1='value1', key2='value2')
|
| 25 |
+
>>> r = requests.post('https://httpbin.org/post', data=payload)
|
| 26 |
+
>>> print(r.text)
|
| 27 |
+
{
|
| 28 |
+
...
|
| 29 |
+
"form": {
|
| 30 |
+
"key1": "value1",
|
| 31 |
+
"key2": "value2"
|
| 32 |
+
},
|
| 33 |
+
...
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
The other HTTP methods are supported - see `requests.api`. Full documentation
|
| 37 |
+
is at <https://requests.readthedocs.io>.
|
| 38 |
+
|
| 39 |
+
:copyright: (c) 2017 by Kenneth Reitz.
|
| 40 |
+
:license: Apache 2.0, see LICENSE for more details.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
from pip._vendor import urllib3
|
| 44 |
+
import warnings
|
| 45 |
+
from .exceptions import RequestsDependencyWarning
|
| 46 |
+
|
| 47 |
+
charset_normalizer_version = None
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
from pip._vendor.chardet import __version__ as chardet_version
|
| 51 |
+
except ImportError:
|
| 52 |
+
chardet_version = None
|
| 53 |
+
|
| 54 |
+
def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
|
| 55 |
+
urllib3_version = urllib3_version.split('.')
|
| 56 |
+
assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.
|
| 57 |
+
|
| 58 |
+
# Sometimes, urllib3 only reports its version as 16.1.
|
| 59 |
+
if len(urllib3_version) == 2:
|
| 60 |
+
urllib3_version.append('0')
|
| 61 |
+
|
| 62 |
+
# Check urllib3 for compatibility.
|
| 63 |
+
major, minor, patch = urllib3_version # noqa: F811
|
| 64 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
| 65 |
+
# urllib3 >= 1.21.1, <= 1.26
|
| 66 |
+
assert major == 1
|
| 67 |
+
assert minor >= 21
|
| 68 |
+
assert minor <= 26
|
| 69 |
+
|
| 70 |
+
# Check charset_normalizer for compatibility.
|
| 71 |
+
if chardet_version:
|
| 72 |
+
major, minor, patch = chardet_version.split('.')[:3]
|
| 73 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
| 74 |
+
# chardet_version >= 3.0.2, < 5.0.0
|
| 75 |
+
assert (3, 0, 2) <= (major, minor, patch) < (5, 0, 0)
|
| 76 |
+
elif charset_normalizer_version:
|
| 77 |
+
major, minor, patch = charset_normalizer_version.split('.')[:3]
|
| 78 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
| 79 |
+
# charset_normalizer >= 2.0.0 < 3.0.0
|
| 80 |
+
assert (2, 0, 0) <= (major, minor, patch) < (3, 0, 0)
|
| 81 |
+
else:
|
| 82 |
+
raise Exception("You need either charset_normalizer or chardet installed")
|
| 83 |
+
|
| 84 |
+
def _check_cryptography(cryptography_version):
|
| 85 |
+
# cryptography < 1.3.4
|
| 86 |
+
try:
|
| 87 |
+
cryptography_version = list(map(int, cryptography_version.split('.')))
|
| 88 |
+
except ValueError:
|
| 89 |
+
return
|
| 90 |
+
|
| 91 |
+
if cryptography_version < [1, 3, 4]:
|
| 92 |
+
warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
|
| 93 |
+
warnings.warn(warning, RequestsDependencyWarning)
|
| 94 |
+
|
| 95 |
+
# Check imported dependencies for compatibility.
|
| 96 |
+
try:
|
| 97 |
+
check_compatibility(urllib3.__version__, chardet_version, charset_normalizer_version)
|
| 98 |
+
except (AssertionError, ValueError):
|
| 99 |
+
warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
|
| 100 |
+
"version!".format(urllib3.__version__, chardet_version, charset_normalizer_version),
|
| 101 |
+
RequestsDependencyWarning)
|
| 102 |
+
|
| 103 |
+
# Attempt to enable urllib3's fallback for SNI support
|
| 104 |
+
# if the standard library doesn't support SNI or the
|
| 105 |
+
# 'ssl' library isn't available.
|
| 106 |
+
try:
|
| 107 |
+
# Note: This logic prevents upgrading cryptography on Windows, if imported
|
| 108 |
+
# as part of pip.
|
| 109 |
+
from pip._internal.utils.compat import WINDOWS
|
| 110 |
+
if not WINDOWS:
|
| 111 |
+
raise ImportError("pip internals: don't import cryptography on Windows")
|
| 112 |
+
try:
|
| 113 |
+
import ssl
|
| 114 |
+
except ImportError:
|
| 115 |
+
ssl = None
|
| 116 |
+
|
| 117 |
+
if not getattr(ssl, "HAS_SNI", False):
|
| 118 |
+
from pip._vendor.urllib3.contrib import pyopenssl
|
| 119 |
+
pyopenssl.inject_into_urllib3()
|
| 120 |
+
|
| 121 |
+
# Check cryptography version
|
| 122 |
+
from cryptography import __version__ as cryptography_version
|
| 123 |
+
_check_cryptography(cryptography_version)
|
| 124 |
+
except ImportError:
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
# urllib3's DependencyWarnings should be silenced.
|
| 128 |
+
from pip._vendor.urllib3.exceptions import DependencyWarning
|
| 129 |
+
warnings.simplefilter('ignore', DependencyWarning)
|
| 130 |
+
|
| 131 |
+
from .__version__ import __title__, __description__, __url__, __version__
|
| 132 |
+
from .__version__ import __build__, __author__, __author_email__, __license__
|
| 133 |
+
from .__version__ import __copyright__, __cake__
|
| 134 |
+
|
| 135 |
+
from . import utils
|
| 136 |
+
from . import packages
|
| 137 |
+
from .models import Request, Response, PreparedRequest
|
| 138 |
+
from .api import request, get, head, post, patch, put, delete, options
|
| 139 |
+
from .sessions import session, Session
|
| 140 |
+
from .status_codes import codes
|
| 141 |
+
from .exceptions import (
|
| 142 |
+
RequestException, Timeout, URLRequired,
|
| 143 |
+
TooManyRedirects, HTTPError, ConnectionError,
|
| 144 |
+
FileModeWarning, ConnectTimeout, ReadTimeout, JSONDecodeError
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
# Set default logging handler to avoid "No handler found" warnings.
|
| 148 |
+
import logging
|
| 149 |
+
from logging import NullHandler
|
| 150 |
+
|
| 151 |
+
logging.getLogger(__name__).addHandler(NullHandler())
|
| 152 |
+
|
| 153 |
+
# FileModeWarnings go off per the default.
|
| 154 |
+
warnings.simplefilter('default', FileModeWarning, append=True)
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/api.cpython-310.pyc
ADDED
|
Binary file (6.71 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/auth.cpython-310.pyc
ADDED
|
Binary file (8.15 kB). View file
|
|
|
material/dataset/xpsdeeplearning/.venv/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/certs.cpython-310.pyc
ADDED
|
Binary file (690 Bytes). View file
|
|
|