applied-ai-018 commited on
Commit
37a0d05
·
verified ·
1 Parent(s): 4d5e55a

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ckpts/universal/global_step80/zero/10.attention.query_key_value.weight/exp_avg_sq.pt +3 -0
  2. ckpts/universal/global_step80/zero/22.input_layernorm.weight/exp_avg_sq.pt +3 -0
  3. venv/lib/python3.10/site-packages/lxml/html/ElementSoup.py +10 -0
  4. venv/lib/python3.10/site-packages/lxml/html/__init__.py +1923 -0
  5. venv/lib/python3.10/site-packages/lxml/html/__pycache__/ElementSoup.cpython-310.pyc +0 -0
  6. venv/lib/python3.10/site-packages/lxml/html/__pycache__/__init__.cpython-310.pyc +0 -0
  7. venv/lib/python3.10/site-packages/lxml/html/__pycache__/_diffcommand.cpython-310.pyc +0 -0
  8. venv/lib/python3.10/site-packages/lxml/html/__pycache__/_html5builder.cpython-310.pyc +0 -0
  9. venv/lib/python3.10/site-packages/lxml/html/__pycache__/_setmixin.cpython-310.pyc +0 -0
  10. venv/lib/python3.10/site-packages/lxml/html/__pycache__/builder.cpython-310.pyc +0 -0
  11. venv/lib/python3.10/site-packages/lxml/html/__pycache__/clean.cpython-310.pyc +0 -0
  12. venv/lib/python3.10/site-packages/lxml/html/__pycache__/defs.cpython-310.pyc +0 -0
  13. venv/lib/python3.10/site-packages/lxml/html/__pycache__/diff.cpython-310.pyc +0 -0
  14. venv/lib/python3.10/site-packages/lxml/html/__pycache__/formfill.cpython-310.pyc +0 -0
  15. venv/lib/python3.10/site-packages/lxml/html/__pycache__/html5parser.cpython-310.pyc +0 -0
  16. venv/lib/python3.10/site-packages/lxml/html/__pycache__/soupparser.cpython-310.pyc +0 -0
  17. venv/lib/python3.10/site-packages/lxml/html/__pycache__/usedoctest.cpython-310.pyc +0 -0
  18. venv/lib/python3.10/site-packages/lxml/html/_diffcommand.py +86 -0
  19. venv/lib/python3.10/site-packages/lxml/html/_html5builder.py +100 -0
  20. venv/lib/python3.10/site-packages/lxml/html/_setmixin.py +56 -0
  21. venv/lib/python3.10/site-packages/lxml/html/builder.py +133 -0
  22. venv/lib/python3.10/site-packages/lxml/html/clean.py +21 -0
  23. venv/lib/python3.10/site-packages/lxml/html/defs.py +135 -0
  24. venv/lib/python3.10/site-packages/lxml/html/diff.cpython-310-x86_64-linux-gnu.so +0 -0
  25. venv/lib/python3.10/site-packages/lxml/html/diff.py +878 -0
  26. venv/lib/python3.10/site-packages/lxml/html/formfill.py +299 -0
  27. venv/lib/python3.10/site-packages/lxml/html/html5parser.py +260 -0
  28. venv/lib/python3.10/site-packages/lxml/html/soupparser.py +314 -0
  29. venv/lib/python3.10/site-packages/lxml/html/usedoctest.py +13 -0
  30. venv/lib/python3.10/site-packages/lxml/includes/__pycache__/__init__.cpython-310.pyc +0 -0
  31. venv/lib/python3.10/site-packages/lxml/includes/libexslt/__init__.py +0 -0
  32. venv/lib/python3.10/site-packages/lxml/includes/libexslt/__pycache__/__init__.cpython-310.pyc +0 -0
  33. venv/lib/python3.10/site-packages/lxml/includes/libexslt/exslt.h +108 -0
  34. venv/lib/python3.10/site-packages/lxml/includes/libexslt/exsltconfig.h +70 -0
  35. venv/lib/python3.10/site-packages/lxml/includes/libexslt/exsltexports.h +63 -0
  36. venv/lib/python3.10/site-packages/lxml/includes/libxml/HTMLparser.h +343 -0
  37. venv/lib/python3.10/site-packages/lxml/includes/libxml/HTMLtree.h +147 -0
  38. venv/lib/python3.10/site-packages/lxml/includes/libxml/__init__.py +0 -0
  39. venv/lib/python3.10/site-packages/lxml/includes/libxml/__pycache__/__init__.cpython-310.pyc +0 -0
  40. venv/lib/python3.10/site-packages/lxml/includes/libxml/catalog.h +182 -0
  41. venv/lib/python3.10/site-packages/lxml/includes/libxml/chvalid.h +230 -0
  42. venv/lib/python3.10/site-packages/lxml/includes/libxml/debugXML.h +217 -0
  43. venv/lib/python3.10/site-packages/lxml/includes/libxml/dict.h +82 -0
  44. venv/lib/python3.10/site-packages/lxml/includes/libxml/entities.h +155 -0
  45. venv/lib/python3.10/site-packages/lxml/includes/libxml/globals.h +41 -0
  46. venv/lib/python3.10/site-packages/lxml/includes/libxml/list.h +137 -0
  47. venv/lib/python3.10/site-packages/lxml/includes/libxml/nanoftp.h +186 -0
  48. venv/lib/python3.10/site-packages/lxml/includes/libxml/nanohttp.h +81 -0
  49. venv/lib/python3.10/site-packages/lxml/includes/libxml/parserInternals.h +663 -0
  50. venv/lib/python3.10/site-packages/lxml/includes/libxml/relaxng.h +219 -0
ckpts/universal/global_step80/zero/10.attention.query_key_value.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d4c25449a0e6dcba1e44df0cc1fc2d6152bf13c87e7a687af047142345999e1
3
+ size 50332843
ckpts/universal/global_step80/zero/22.input_layernorm.weight/exp_avg_sq.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d45ecc96b85eb0ad052755af322185a6fc00f6014265446fc2b351e80ff881c4
3
+ size 9387
venv/lib/python3.10/site-packages/lxml/html/ElementSoup.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ __doc__ = """Legacy interface to the BeautifulSoup HTML parser.
2
+ """
3
+
4
+ __all__ = ["parse", "convert_tree"]
5
+
6
+ from .soupparser import convert_tree, parse as _parse
7
+
8
+ def parse(file, beautifulsoup=None, makeelement=None):
9
+ root = _parse(file, beautifulsoup=beautifulsoup, makeelement=makeelement)
10
+ return root.getroot()
venv/lib/python3.10/site-packages/lxml/html/__init__.py ADDED
@@ -0,0 +1,1923 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2004 Ian Bicking. All rights reserved.
2
+ #
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are
5
+ # met:
6
+ #
7
+ # 1. Redistributions of source code must retain the above copyright
8
+ # notice, this list of conditions and the following disclaimer.
9
+ #
10
+ # 2. Redistributions in binary form must reproduce the above copyright
11
+ # notice, this list of conditions and the following disclaimer in
12
+ # the documentation and/or other materials provided with the
13
+ # distribution.
14
+ #
15
+ # 3. Neither the name of Ian Bicking nor the names of its contributors may
16
+ # be used to endorse or promote products derived from this software
17
+ # without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IAN BICKING OR
23
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ """The ``lxml.html`` tool set for HTML handling.
32
+ """
33
+
34
+
35
+ __all__ = [
36
+ 'document_fromstring', 'fragment_fromstring', 'fragments_fromstring', 'fromstring',
37
+ 'tostring', 'Element', 'defs', 'open_in_browser', 'submit_form',
38
+ 'find_rel_links', 'find_class', 'make_links_absolute',
39
+ 'resolve_base_href', 'iterlinks', 'rewrite_links', 'parse']
40
+
41
+
42
+ import copy
43
+ import re
44
+
45
+ from collections.abc import MutableMapping, MutableSet
46
+ from functools import partial
47
+ from urllib.parse import urljoin
48
+
49
+ from .. import etree
50
+ from . import defs
51
+ from ._setmixin import SetMixin
52
+
53
+
54
+ def __fix_docstring(s):
55
+ # TODO: remove and clean up doctests
56
+ if not s:
57
+ return s
58
+ sub = re.compile(r"^(\s*)u'", re.M).sub
59
+ return sub(r"\1'", s)
60
+
61
+
62
+ XHTML_NAMESPACE = "http://www.w3.org/1999/xhtml"
63
+
64
+ _rel_links_xpath = etree.XPath("descendant-or-self::a[@rel]|descendant-or-self::x:a[@rel]",
65
+ namespaces={'x':XHTML_NAMESPACE})
66
+ _options_xpath = etree.XPath("descendant-or-self::option|descendant-or-self::x:option",
67
+ namespaces={'x':XHTML_NAMESPACE})
68
+ _forms_xpath = etree.XPath("descendant-or-self::form|descendant-or-self::x:form",
69
+ namespaces={'x':XHTML_NAMESPACE})
70
+ #_class_xpath = etree.XPath(r"descendant-or-self::*[regexp:match(@class, concat('\b', $class_name, '\b'))]", {'regexp': 'http://exslt.org/regular-expressions'})
71
+ _class_xpath = etree.XPath("descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), concat(' ', $class_name, ' '))]")
72
+ _id_xpath = etree.XPath("descendant-or-self::*[@id=$id]")
73
+ _collect_string_content = etree.XPath("string()")
74
+ _iter_css_urls = re.compile(r'url\(('+'["][^"]*["]|'+"['][^']*[']|"+r'[^)]*)\)', re.I).finditer
75
+ _iter_css_imports = re.compile(r'@import "(.*?)"').finditer
76
+ _label_xpath = etree.XPath("//label[@for=$id]|//x:label[@for=$id]",
77
+ namespaces={'x':XHTML_NAMESPACE})
78
+ _archive_re = re.compile(r'[^ ]+')
79
+ _parse_meta_refresh_url = re.compile(
80
+ r'[^;=]*;\s*(?:url\s*=\s*)?(?P<url>.*)$', re.I).search
81
+
82
+
83
+ def _unquote_match(s, pos):
84
+ if s[:1] == '"' and s[-1:] == '"' or s[:1] == "'" and s[-1:] == "'":
85
+ return s[1:-1], pos+1
86
+ else:
87
+ return s,pos
88
+
89
+
90
+ def _transform_result(typ, result):
91
+ """Convert the result back into the input type.
92
+ """
93
+ if issubclass(typ, bytes):
94
+ return tostring(result, encoding='utf-8')
95
+ elif issubclass(typ, str):
96
+ return tostring(result, encoding='unicode')
97
+ else:
98
+ return result
99
+
100
+
101
+ def _nons(tag):
102
+ if isinstance(tag, str):
103
+ if tag[0] == '{' and tag[1:len(XHTML_NAMESPACE)+1] == XHTML_NAMESPACE:
104
+ return tag.split('}')[-1]
105
+ return tag
106
+
107
+
108
+ class Classes(MutableSet):
109
+ """Provides access to an element's class attribute as a set-like collection.
110
+ Usage::
111
+
112
+ >>> el = fromstring('<p class="hidden large">Text</p>')
113
+ >>> classes = el.classes # or: classes = Classes(el.attrib)
114
+ >>> classes |= ['block', 'paragraph']
115
+ >>> el.get('class')
116
+ 'hidden large block paragraph'
117
+ >>> classes.toggle('hidden')
118
+ False
119
+ >>> el.get('class')
120
+ 'large block paragraph'
121
+ >>> classes -= ('some', 'classes', 'block')
122
+ >>> el.get('class')
123
+ 'large paragraph'
124
+ """
125
+ def __init__(self, attributes):
126
+ self._attributes = attributes
127
+ self._get_class_value = partial(attributes.get, 'class', '')
128
+
129
+ def add(self, value):
130
+ """
131
+ Add a class.
132
+
133
+ This has no effect if the class is already present.
134
+ """
135
+ if not value or re.search(r'\s', value):
136
+ raise ValueError("Invalid class name: %r" % value)
137
+ classes = self._get_class_value().split()
138
+ if value in classes:
139
+ return
140
+ classes.append(value)
141
+ self._attributes['class'] = ' '.join(classes)
142
+
143
+ def discard(self, value):
144
+ """
145
+ Remove a class if it is currently present.
146
+
147
+ If the class is not present, do nothing.
148
+ """
149
+ if not value or re.search(r'\s', value):
150
+ raise ValueError("Invalid class name: %r" % value)
151
+ classes = [name for name in self._get_class_value().split()
152
+ if name != value]
153
+ if classes:
154
+ self._attributes['class'] = ' '.join(classes)
155
+ elif 'class' in self._attributes:
156
+ del self._attributes['class']
157
+
158
+ def remove(self, value):
159
+ """
160
+ Remove a class; it must currently be present.
161
+
162
+ If the class is not present, raise a KeyError.
163
+ """
164
+ if not value or re.search(r'\s', value):
165
+ raise ValueError("Invalid class name: %r" % value)
166
+ super().remove(value)
167
+
168
+ def __contains__(self, name):
169
+ classes = self._get_class_value()
170
+ return name in classes and name in classes.split()
171
+
172
+ def __iter__(self):
173
+ return iter(self._get_class_value().split())
174
+
175
+ def __len__(self):
176
+ return len(self._get_class_value().split())
177
+
178
+ # non-standard methods
179
+
180
+ def update(self, values):
181
+ """
182
+ Add all names from 'values'.
183
+ """
184
+ classes = self._get_class_value().split()
185
+ extended = False
186
+ for value in values:
187
+ if value not in classes:
188
+ classes.append(value)
189
+ extended = True
190
+ if extended:
191
+ self._attributes['class'] = ' '.join(classes)
192
+
193
+ def toggle(self, value):
194
+ """
195
+ Add a class name if it isn't there yet, or remove it if it exists.
196
+
197
+ Returns true if the class was added (and is now enabled) and
198
+ false if it was removed (and is now disabled).
199
+ """
200
+ if not value or re.search(r'\s', value):
201
+ raise ValueError("Invalid class name: %r" % value)
202
+ classes = self._get_class_value().split()
203
+ try:
204
+ classes.remove(value)
205
+ enabled = False
206
+ except ValueError:
207
+ classes.append(value)
208
+ enabled = True
209
+ if classes:
210
+ self._attributes['class'] = ' '.join(classes)
211
+ else:
212
+ del self._attributes['class']
213
+ return enabled
214
+
215
+
216
+ class HtmlMixin:
217
+
218
+ def set(self, key, value=None):
219
+ """set(self, key, value=None)
220
+
221
+ Sets an element attribute. If no value is provided, or if the value is None,
222
+ creates a 'boolean' attribute without value, e.g. "<form novalidate></form>"
223
+ for ``form.set('novalidate')``.
224
+ """
225
+ super().set(key, value)
226
+
227
+ @property
228
+ def classes(self):
229
+ """
230
+ A set-like wrapper around the 'class' attribute.
231
+ """
232
+ return Classes(self.attrib)
233
+
234
+ @classes.setter
235
+ def classes(self, classes):
236
+ assert isinstance(classes, Classes) # only allow "el.classes |= ..." etc.
237
+ value = classes._get_class_value()
238
+ if value:
239
+ self.set('class', value)
240
+ elif self.get('class') is not None:
241
+ del self.attrib['class']
242
+
243
+ @property
244
+ def base_url(self):
245
+ """
246
+ Returns the base URL, given when the page was parsed.
247
+
248
+ Use with ``urlparse.urljoin(el.base_url, href)`` to get
249
+ absolute URLs.
250
+ """
251
+ return self.getroottree().docinfo.URL
252
+
253
+ @property
254
+ def forms(self):
255
+ """
256
+ Return a list of all the forms
257
+ """
258
+ return _forms_xpath(self)
259
+
260
+ @property
261
+ def body(self):
262
+ """
263
+ Return the <body> element. Can be called from a child element
264
+ to get the document's head.
265
+ """
266
+ return self.xpath('//body|//x:body', namespaces={'x':XHTML_NAMESPACE})[0]
267
+
268
+ @property
269
+ def head(self):
270
+ """
271
+ Returns the <head> element. Can be called from a child
272
+ element to get the document's head.
273
+ """
274
+ return self.xpath('//head|//x:head', namespaces={'x':XHTML_NAMESPACE})[0]
275
+
276
+ @property
277
+ def label(self):
278
+ """
279
+ Get or set any <label> element associated with this element.
280
+ """
281
+ id = self.get('id')
282
+ if not id:
283
+ return None
284
+ result = _label_xpath(self, id=id)
285
+ if not result:
286
+ return None
287
+ else:
288
+ return result[0]
289
+
290
+ @label.setter
291
+ def label(self, label):
292
+ id = self.get('id')
293
+ if not id:
294
+ raise TypeError(
295
+ "You cannot set a label for an element (%r) that has no id"
296
+ % self)
297
+ if _nons(label.tag) != 'label':
298
+ raise TypeError(
299
+ "You can only assign label to a label element (not %r)"
300
+ % label)
301
+ label.set('for', id)
302
+
303
+ @label.deleter
304
+ def label(self):
305
+ label = self.label
306
+ if label is not None:
307
+ del label.attrib['for']
308
+
309
+ def drop_tree(self):
310
+ """
311
+ Removes this element from the tree, including its children and
312
+ text. The tail text is joined to the previous element or
313
+ parent.
314
+ """
315
+ parent = self.getparent()
316
+ assert parent is not None
317
+ if self.tail:
318
+ previous = self.getprevious()
319
+ if previous is None:
320
+ parent.text = (parent.text or '') + self.tail
321
+ else:
322
+ previous.tail = (previous.tail or '') + self.tail
323
+ parent.remove(self)
324
+
325
+ def drop_tag(self):
326
+ """
327
+ Remove the tag, but not its children or text. The children and text
328
+ are merged into the parent.
329
+
330
+ Example::
331
+
332
+ >>> h = fragment_fromstring('<div>Hello <b>World!</b></div>')
333
+ >>> h.find('.//b').drop_tag()
334
+ >>> print(tostring(h, encoding='unicode'))
335
+ <div>Hello World!</div>
336
+ """
337
+ parent = self.getparent()
338
+ assert parent is not None
339
+ previous = self.getprevious()
340
+ if self.text and isinstance(self.tag, str):
341
+ # not a Comment, etc.
342
+ if previous is None:
343
+ parent.text = (parent.text or '') + self.text
344
+ else:
345
+ previous.tail = (previous.tail or '') + self.text
346
+ if self.tail:
347
+ if len(self):
348
+ last = self[-1]
349
+ last.tail = (last.tail or '') + self.tail
350
+ elif previous is None:
351
+ parent.text = (parent.text or '') + self.tail
352
+ else:
353
+ previous.tail = (previous.tail or '') + self.tail
354
+ index = parent.index(self)
355
+ parent[index:index+1] = self[:]
356
+
357
+ def find_rel_links(self, rel):
358
+ """
359
+ Find any links like ``<a rel="{rel}">...</a>``; returns a list of elements.
360
+ """
361
+ rel = rel.lower()
362
+ return [el for el in _rel_links_xpath(self)
363
+ if el.get('rel').lower() == rel]
364
+
365
+ def find_class(self, class_name):
366
+ """
367
+ Find any elements with the given class name.
368
+ """
369
+ return _class_xpath(self, class_name=class_name)
370
+
371
+ def get_element_by_id(self, id, *default):
372
+ """
373
+ Get the first element in a document with the given id. If none is
374
+ found, return the default argument if provided or raise KeyError
375
+ otherwise.
376
+
377
+ Note that there can be more than one element with the same id,
378
+ and this isn't uncommon in HTML documents found in the wild.
379
+ Browsers return only the first match, and this function does
380
+ the same.
381
+ """
382
+ try:
383
+ # FIXME: should this check for multiple matches?
384
+ # browsers just return the first one
385
+ return _id_xpath(self, id=id)[0]
386
+ except IndexError:
387
+ if default:
388
+ return default[0]
389
+ else:
390
+ raise KeyError(id)
391
+
392
+ def text_content(self):
393
+ """
394
+ Return the text content of the tag (and the text in any children).
395
+ """
396
+ return _collect_string_content(self)
397
+
398
+ def cssselect(self, expr, translator='html'):
399
+ """
400
+ Run the CSS expression on this element and its children,
401
+ returning a list of the results.
402
+
403
+ Equivalent to lxml.cssselect.CSSSelect(expr, translator='html')(self)
404
+ -- note that pre-compiling the expression can provide a substantial
405
+ speedup.
406
+ """
407
+ # Do the import here to make the dependency optional.
408
+ from lxml.cssselect import CSSSelector
409
+ return CSSSelector(expr, translator=translator)(self)
410
+
411
+ ########################################
412
+ ## Link functions
413
+ ########################################
414
+
415
+ def make_links_absolute(self, base_url=None, resolve_base_href=True,
416
+ handle_failures=None):
417
+ """
418
+ Make all links in the document absolute, given the
419
+ ``base_url`` for the document (the full URL where the document
420
+ came from), or if no ``base_url`` is given, then the ``.base_url``
421
+ of the document.
422
+
423
+ If ``resolve_base_href`` is true, then any ``<base href>``
424
+ tags in the document are used *and* removed from the document.
425
+ If it is false then any such tag is ignored.
426
+
427
+ If ``handle_failures`` is None (default), a failure to process
428
+ a URL will abort the processing. If set to 'ignore', errors
429
+ are ignored. If set to 'discard', failing URLs will be removed.
430
+ """
431
+ if base_url is None:
432
+ base_url = self.base_url
433
+ if base_url is None:
434
+ raise TypeError(
435
+ "No base_url given, and the document has no base_url")
436
+ if resolve_base_href:
437
+ self.resolve_base_href()
438
+
439
+ if handle_failures == 'ignore':
440
+ def link_repl(href):
441
+ try:
442
+ return urljoin(base_url, href)
443
+ except ValueError:
444
+ return href
445
+ elif handle_failures == 'discard':
446
+ def link_repl(href):
447
+ try:
448
+ return urljoin(base_url, href)
449
+ except ValueError:
450
+ return None
451
+ elif handle_failures is None:
452
+ def link_repl(href):
453
+ return urljoin(base_url, href)
454
+ else:
455
+ raise ValueError(
456
+ "unexpected value for handle_failures: %r" % handle_failures)
457
+
458
+ self.rewrite_links(link_repl)
459
+
460
+ def resolve_base_href(self, handle_failures=None):
461
+ """
462
+ Find any ``<base href>`` tag in the document, and apply its
463
+ values to all links found in the document. Also remove the
464
+ tag once it has been applied.
465
+
466
+ If ``handle_failures`` is None (default), a failure to process
467
+ a URL will abort the processing. If set to 'ignore', errors
468
+ are ignored. If set to 'discard', failing URLs will be removed.
469
+ """
470
+ base_href = None
471
+ basetags = self.xpath('//base[@href]|//x:base[@href]',
472
+ namespaces={'x': XHTML_NAMESPACE})
473
+ for b in basetags:
474
+ base_href = b.get('href')
475
+ b.drop_tree()
476
+ if not base_href:
477
+ return
478
+ self.make_links_absolute(base_href, resolve_base_href=False,
479
+ handle_failures=handle_failures)
480
+
481
+ def iterlinks(self):
482
+ """
483
+ Yield (element, attribute, link, pos), where attribute may be None
484
+ (indicating the link is in the text). ``pos`` is the position
485
+ where the link occurs; often 0, but sometimes something else in
486
+ the case of links in stylesheets or style tags.
487
+
488
+ Note: <base href> is *not* taken into account in any way. The
489
+ link you get is exactly the link in the document.
490
+
491
+ Note: multiple links inside of a single text string or
492
+ attribute value are returned in reversed order. This makes it
493
+ possible to replace or delete them from the text string value
494
+ based on their reported text positions. Otherwise, a
495
+ modification at one text position can change the positions of
496
+ links reported later on.
497
+ """
498
+ link_attrs = defs.link_attrs
499
+ for el in self.iter(etree.Element):
500
+ attribs = el.attrib
501
+ tag = _nons(el.tag)
502
+ if tag == 'object':
503
+ codebase = None
504
+ ## <object> tags have attributes that are relative to
505
+ ## codebase
506
+ if 'codebase' in attribs:
507
+ codebase = el.get('codebase')
508
+ yield (el, 'codebase', codebase, 0)
509
+ for attrib in ('classid', 'data'):
510
+ if attrib in attribs:
511
+ value = el.get(attrib)
512
+ if codebase is not None:
513
+ value = urljoin(codebase, value)
514
+ yield (el, attrib, value, 0)
515
+ if 'archive' in attribs:
516
+ for match in _archive_re.finditer(el.get('archive')):
517
+ value = match.group(0)
518
+ if codebase is not None:
519
+ value = urljoin(codebase, value)
520
+ yield (el, 'archive', value, match.start())
521
+ else:
522
+ for attrib in link_attrs:
523
+ if attrib in attribs:
524
+ yield (el, attrib, attribs[attrib], 0)
525
+ if tag == 'meta':
526
+ http_equiv = attribs.get('http-equiv', '').lower()
527
+ if http_equiv == 'refresh':
528
+ content = attribs.get('content', '')
529
+ match = _parse_meta_refresh_url(content)
530
+ url = (match.group('url') if match else content).strip()
531
+ # unexpected content means the redirect won't work, but we might
532
+ # as well be permissive and return the entire string.
533
+ if url:
534
+ url, pos = _unquote_match(
535
+ url, match.start('url') if match else content.find(url))
536
+ yield (el, 'content', url, pos)
537
+ elif tag == 'param':
538
+ valuetype = el.get('valuetype') or ''
539
+ if valuetype.lower() == 'ref':
540
+ ## FIXME: while it's fine we *find* this link,
541
+ ## according to the spec we aren't supposed to
542
+ ## actually change the value, including resolving
543
+ ## it. It can also still be a link, even if it
544
+ ## doesn't have a valuetype="ref" (which seems to be the norm)
545
+ ## http://www.w3.org/TR/html401/struct/objects.html#adef-valuetype
546
+ yield (el, 'value', el.get('value'), 0)
547
+ elif tag == 'style' and el.text:
548
+ urls = [
549
+ # (start_pos, url)
550
+ _unquote_match(match.group(1), match.start(1))[::-1]
551
+ for match in _iter_css_urls(el.text)
552
+ ] + [
553
+ (match.start(1), match.group(1))
554
+ for match in _iter_css_imports(el.text)
555
+ ]
556
+ if urls:
557
+ # sort by start pos to bring both match sets back into order
558
+ # and reverse the list to report correct positions despite
559
+ # modifications
560
+ urls.sort(reverse=True)
561
+ for start, url in urls:
562
+ yield (el, None, url, start)
563
+ if 'style' in attribs:
564
+ urls = list(_iter_css_urls(attribs['style']))
565
+ if urls:
566
+ # return in reversed order to simplify in-place modifications
567
+ for match in urls[::-1]:
568
+ url, start = _unquote_match(match.group(1), match.start(1))
569
+ yield (el, 'style', url, start)
570
+
571
+ def rewrite_links(self, link_repl_func, resolve_base_href=True,
572
+ base_href=None):
573
+ """
574
+ Rewrite all the links in the document. For each link
575
+ ``link_repl_func(link)`` will be called, and the return value
576
+ will replace the old link.
577
+
578
+ Note that links may not be absolute (unless you first called
579
+ ``make_links_absolute()``), and may be internal (e.g.,
580
+ ``'#anchor'``). They can also be values like
581
+ ``'mailto:email'`` or ``'javascript:expr'``.
582
+
583
+ If you give ``base_href`` then all links passed to
584
+ ``link_repl_func()`` will take that into account.
585
+
586
+ If the ``link_repl_func`` returns None, the attribute or
587
+ tag text will be removed completely.
588
+ """
589
+ if base_href is not None:
590
+ # FIXME: this can be done in one pass with a wrapper
591
+ # around link_repl_func
592
+ self.make_links_absolute(
593
+ base_href, resolve_base_href=resolve_base_href)
594
+ elif resolve_base_href:
595
+ self.resolve_base_href()
596
+
597
+ for el, attrib, link, pos in self.iterlinks():
598
+ new_link = link_repl_func(link.strip())
599
+ if new_link == link:
600
+ continue
601
+ if new_link is None:
602
+ # Remove the attribute or element content
603
+ if attrib is None:
604
+ el.text = ''
605
+ else:
606
+ del el.attrib[attrib]
607
+ continue
608
+
609
+ if attrib is None:
610
+ new = el.text[:pos] + new_link + el.text[pos+len(link):]
611
+ el.text = new
612
+ else:
613
+ cur = el.get(attrib)
614
+ if not pos and len(cur) == len(link):
615
+ new = new_link # most common case
616
+ else:
617
+ new = cur[:pos] + new_link + cur[pos+len(link):]
618
+ el.set(attrib, new)
619
+
620
+
621
+ class _MethodFunc:
622
+ """
623
+ An object that represents a method on an element as a function;
624
+ the function takes either an element or an HTML string. It
625
+ returns whatever the function normally returns, or if the function
626
+ works in-place (and so returns None) it returns a serialized form
627
+ of the resulting document.
628
+ """
629
+ def __init__(self, name, copy=False, source_class=HtmlMixin):
630
+ self.name = name
631
+ self.copy = copy
632
+ self.__doc__ = getattr(source_class, self.name).__doc__
633
+ def __call__(self, doc, *args, **kw):
634
+ result_type = type(doc)
635
+ if isinstance(doc, (str, bytes)):
636
+ if 'copy' in kw:
637
+ raise TypeError(
638
+ "The keyword 'copy' can only be used with element inputs to %s, not a string input" % self.name)
639
+ doc = fromstring(doc, **kw)
640
+ else:
641
+ if 'copy' in kw:
642
+ make_a_copy = kw.pop('copy')
643
+ else:
644
+ make_a_copy = self.copy
645
+ if make_a_copy:
646
+ doc = copy.deepcopy(doc)
647
+ meth = getattr(doc, self.name)
648
+ result = meth(*args, **kw)
649
+ # FIXME: this None test is a bit sloppy
650
+ if result is None:
651
+ # Then return what we got in
652
+ return _transform_result(result_type, doc)
653
+ else:
654
+ return result
655
+
656
+
657
+ find_rel_links = _MethodFunc('find_rel_links', copy=False)
658
+ find_class = _MethodFunc('find_class', copy=False)
659
+ make_links_absolute = _MethodFunc('make_links_absolute', copy=True)
660
+ resolve_base_href = _MethodFunc('resolve_base_href', copy=True)
661
+ iterlinks = _MethodFunc('iterlinks', copy=False)
662
+ rewrite_links = _MethodFunc('rewrite_links', copy=True)
663
+
664
+
665
+ class HtmlComment(HtmlMixin, etree.CommentBase):
666
+ pass
667
+
668
+
669
+ class HtmlElement(HtmlMixin, etree.ElementBase):
670
+ pass
671
+
672
+
673
+ class HtmlProcessingInstruction(HtmlMixin, etree.PIBase):
674
+ pass
675
+
676
+
677
+ class HtmlEntity(HtmlMixin, etree.EntityBase):
678
+ pass
679
+
680
+
681
+ class HtmlElementClassLookup(etree.CustomElementClassLookup):
682
+ """A lookup scheme for HTML Element classes.
683
+
684
+ To create a lookup instance with different Element classes, pass a tag
685
+ name mapping of Element classes in the ``classes`` keyword argument and/or
686
+ a tag name mapping of Mixin classes in the ``mixins`` keyword argument.
687
+ The special key '*' denotes a Mixin class that should be mixed into all
688
+ Element classes.
689
+ """
690
+ _default_element_classes = {}
691
+
692
+ def __init__(self, classes=None, mixins=None):
693
+ etree.CustomElementClassLookup.__init__(self)
694
+ if classes is None:
695
+ classes = self._default_element_classes.copy()
696
+ if mixins:
697
+ mixers = {}
698
+ for name, value in mixins:
699
+ if name == '*':
700
+ for n in classes.keys():
701
+ mixers.setdefault(n, []).append(value)
702
+ else:
703
+ mixers.setdefault(name, []).append(value)
704
+ for name, mix_bases in mixers.items():
705
+ cur = classes.get(name, HtmlElement)
706
+ bases = tuple(mix_bases + [cur])
707
+ classes[name] = type(cur.__name__, bases, {})
708
+ self._element_classes = classes
709
+
710
+ def lookup(self, node_type, document, namespace, name):
711
+ if node_type == 'element':
712
+ return self._element_classes.get(name.lower(), HtmlElement)
713
+ elif node_type == 'comment':
714
+ return HtmlComment
715
+ elif node_type == 'PI':
716
+ return HtmlProcessingInstruction
717
+ elif node_type == 'entity':
718
+ return HtmlEntity
719
+ # Otherwise normal lookup
720
+ return None
721
+
722
+
723
+ ################################################################################
724
+ # parsing
725
+ ################################################################################
726
+
727
+ _looks_like_full_html_unicode = re.compile(
728
+ r'^\s*<(?:html|!doctype)', re.I).match
729
+ _looks_like_full_html_bytes = re.compile(
730
+ br'^\s*<(?:html|!doctype)', re.I).match
731
+
732
+
733
+ def document_fromstring(html, parser=None, ensure_head_body=False, **kw):
734
+ if parser is None:
735
+ parser = html_parser
736
+ value = etree.fromstring(html, parser, **kw)
737
+ if value is None:
738
+ raise etree.ParserError(
739
+ "Document is empty")
740
+ if ensure_head_body and value.find('head') is None:
741
+ value.insert(0, Element('head'))
742
+ if ensure_head_body and value.find('body') is None:
743
+ value.append(Element('body'))
744
+ return value
745
+
746
+
747
+ def fragments_fromstring(html, no_leading_text=False, base_url=None,
748
+ parser=None, **kw):
749
+ """Parses several HTML elements, returning a list of elements.
750
+
751
+ The first item in the list may be a string.
752
+ If no_leading_text is true, then it will be an error if there is
753
+ leading text, and it will always be a list of only elements.
754
+
755
+ base_url will set the document's base_url attribute
756
+ (and the tree's docinfo.URL).
757
+ """
758
+ if parser is None:
759
+ parser = html_parser
760
+ # FIXME: check what happens when you give html with a body, head, etc.
761
+ if isinstance(html, bytes):
762
+ if not _looks_like_full_html_bytes(html):
763
+ # can't use %-formatting in early Py3 versions
764
+ html = (b'<html><body>' + html +
765
+ b'</body></html>')
766
+ else:
767
+ if not _looks_like_full_html_unicode(html):
768
+ html = '<html><body>%s</body></html>' % html
769
+ doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
770
+ assert _nons(doc.tag) == 'html'
771
+ bodies = [e for e in doc if _nons(e.tag) == 'body']
772
+ assert len(bodies) == 1, ("too many bodies: %r in %r" % (bodies, html))
773
+ body = bodies[0]
774
+ elements = []
775
+ if no_leading_text and body.text and body.text.strip():
776
+ raise etree.ParserError(
777
+ "There is leading text: %r" % body.text)
778
+ if body.text and body.text.strip():
779
+ elements.append(body.text)
780
+ elements.extend(body)
781
+ # FIXME: removing the reference to the parent artificial document
782
+ # would be nice
783
+ return elements
784
+
785
+
786
+ def fragment_fromstring(html, create_parent=False, base_url=None,
787
+ parser=None, **kw):
788
+ """
789
+ Parses a single HTML element; it is an error if there is more than
790
+ one element, or if anything but whitespace precedes or follows the
791
+ element.
792
+
793
+ If ``create_parent`` is true (or is a tag name) then a parent node
794
+ will be created to encapsulate the HTML in a single element. In this
795
+ case, leading or trailing text is also allowed, as are multiple elements
796
+ as result of the parsing.
797
+
798
+ Passing a ``base_url`` will set the document's ``base_url`` attribute
799
+ (and the tree's docinfo.URL).
800
+ """
801
+ if parser is None:
802
+ parser = html_parser
803
+
804
+ accept_leading_text = bool(create_parent)
805
+
806
+ elements = fragments_fromstring(
807
+ html, parser=parser, no_leading_text=not accept_leading_text,
808
+ base_url=base_url, **kw)
809
+
810
+ if create_parent:
811
+ if not isinstance(create_parent, str):
812
+ create_parent = 'div'
813
+ new_root = Element(create_parent)
814
+ if elements:
815
+ if isinstance(elements[0], str):
816
+ new_root.text = elements[0]
817
+ del elements[0]
818
+ new_root.extend(elements)
819
+ return new_root
820
+
821
+ if not elements:
822
+ raise etree.ParserError('No elements found')
823
+ if len(elements) > 1:
824
+ raise etree.ParserError(
825
+ "Multiple elements found (%s)"
826
+ % ', '.join([_element_name(e) for e in elements]))
827
+ el = elements[0]
828
+ if el.tail and el.tail.strip():
829
+ raise etree.ParserError(
830
+ "Element followed by text: %r" % el.tail)
831
+ el.tail = None
832
+ return el
833
+
834
+
835
+ def fromstring(html, base_url=None, parser=None, **kw):
836
+ """
837
+ Parse the html, returning a single element/document.
838
+
839
+ This tries to minimally parse the chunk of text, without knowing if it
840
+ is a fragment or a document.
841
+
842
+ base_url will set the document's base_url attribute (and the tree's docinfo.URL)
843
+ """
844
+ if parser is None:
845
+ parser = html_parser
846
+ if isinstance(html, bytes):
847
+ is_full_html = _looks_like_full_html_bytes(html)
848
+ else:
849
+ is_full_html = _looks_like_full_html_unicode(html)
850
+ doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
851
+ if is_full_html:
852
+ return doc
853
+ # otherwise, lets parse it out...
854
+ bodies = doc.findall('body')
855
+ if not bodies:
856
+ bodies = doc.findall('{%s}body' % XHTML_NAMESPACE)
857
+ if bodies:
858
+ body = bodies[0]
859
+ if len(bodies) > 1:
860
+ # Somehow there are multiple bodies, which is bad, but just
861
+ # smash them into one body
862
+ for other_body in bodies[1:]:
863
+ if other_body.text:
864
+ if len(body):
865
+ body[-1].tail = (body[-1].tail or '') + other_body.text
866
+ else:
867
+ body.text = (body.text or '') + other_body.text
868
+ body.extend(other_body)
869
+ # We'll ignore tail
870
+ # I guess we are ignoring attributes too
871
+ other_body.drop_tree()
872
+ else:
873
+ body = None
874
+ heads = doc.findall('head')
875
+ if not heads:
876
+ heads = doc.findall('{%s}head' % XHTML_NAMESPACE)
877
+ if heads:
878
+ # Well, we have some sort of structure, so lets keep it all
879
+ head = heads[0]
880
+ if len(heads) > 1:
881
+ for other_head in heads[1:]:
882
+ head.extend(other_head)
883
+ # We don't care about text or tail in a head
884
+ other_head.drop_tree()
885
+ return doc
886
+ if body is None:
887
+ return doc
888
+ if (len(body) == 1 and (not body.text or not body.text.strip())
889
+ and (not body[-1].tail or not body[-1].tail.strip())):
890
+ # The body has just one element, so it was probably a single
891
+ # element passed in
892
+ return body[0]
893
+ # Now we have a body which represents a bunch of tags which have the
894
+ # content that was passed in. We will create a fake container, which
895
+ # is the body tag, except <body> implies too much structure.
896
+ if _contains_block_level_tag(body):
897
+ body.tag = 'div'
898
+ else:
899
+ body.tag = 'span'
900
+ return body
901
+
902
+
903
+ def parse(filename_or_url, parser=None, base_url=None, **kw):
904
+ """
905
+ Parse a filename, URL, or file-like object into an HTML document
906
+ tree. Note: this returns a tree, not an element. Use
907
+ ``parse(...).getroot()`` to get the document root.
908
+
909
+ You can override the base URL with the ``base_url`` keyword. This
910
+ is most useful when parsing from a file-like object.
911
+ """
912
+ if parser is None:
913
+ parser = html_parser
914
+ return etree.parse(filename_or_url, parser, base_url=base_url, **kw)
915
+
916
+
917
+ def _contains_block_level_tag(el):
918
+ # FIXME: I could do this with XPath, but would that just be
919
+ # unnecessarily slow?
920
+ for el in el.iter(etree.Element):
921
+ if _nons(el.tag) in defs.block_tags:
922
+ return True
923
+ return False
924
+
925
+
926
+ def _element_name(el):
927
+ if isinstance(el, etree.CommentBase):
928
+ return 'comment'
929
+ elif isinstance(el, str):
930
+ return 'string'
931
+ else:
932
+ return _nons(el.tag)
933
+
934
+
935
+ ################################################################################
936
+ # form handling
937
+ ################################################################################
938
+
939
+ class FormElement(HtmlElement):
940
+ """
941
+ Represents a <form> element.
942
+ """
943
+
944
+ @property
945
+ def inputs(self):
946
+ """
947
+ Returns an accessor for all the input elements in the form.
948
+
949
+ See `InputGetter` for more information about the object.
950
+ """
951
+ return InputGetter(self)
952
+
953
+ @property
954
+ def fields(self):
955
+ """
956
+ Dictionary-like object that represents all the fields in this
957
+ form. You can set values in this dictionary to effect the
958
+ form.
959
+ """
960
+ return FieldsDict(self.inputs)
961
+
962
+ @fields.setter
963
+ def fields(self, value):
964
+ fields = self.fields
965
+ prev_keys = fields.keys()
966
+ for key, value in value.items():
967
+ if key in prev_keys:
968
+ prev_keys.remove(key)
969
+ fields[key] = value
970
+ for key in prev_keys:
971
+ if key is None:
972
+ # Case of an unnamed input; these aren't really
973
+ # expressed in form_values() anyway.
974
+ continue
975
+ fields[key] = None
976
+
977
+ def _name(self):
978
+ if self.get('name'):
979
+ return self.get('name')
980
+ elif self.get('id'):
981
+ return '#' + self.get('id')
982
+ iter_tags = self.body.iter
983
+ forms = list(iter_tags('form'))
984
+ if not forms:
985
+ forms = list(iter_tags('{%s}form' % XHTML_NAMESPACE))
986
+ return str(forms.index(self))
987
+
988
+ def form_values(self):
989
+ """
990
+ Return a list of tuples of the field values for the form.
991
+ This is suitable to be passed to ``urllib.urlencode()``.
992
+ """
993
+ results = []
994
+ for el in self.inputs:
995
+ name = el.name
996
+ if not name or 'disabled' in el.attrib:
997
+ continue
998
+ tag = _nons(el.tag)
999
+ if tag == 'textarea':
1000
+ results.append((name, el.value))
1001
+ elif tag == 'select':
1002
+ value = el.value
1003
+ if el.multiple:
1004
+ for v in value:
1005
+ results.append((name, v))
1006
+ elif value is not None:
1007
+ results.append((name, el.value))
1008
+ else:
1009
+ assert tag == 'input', (
1010
+ "Unexpected tag: %r" % el)
1011
+ if el.checkable and not el.checked:
1012
+ continue
1013
+ if el.type in ('submit', 'image', 'reset', 'file'):
1014
+ continue
1015
+ value = el.value
1016
+ if value is not None:
1017
+ results.append((name, el.value))
1018
+ return results
1019
+
1020
+ @property
1021
+ def action(self):
1022
+ """
1023
+ Get/set the form's ``action`` attribute.
1024
+ """
1025
+ base_url = self.base_url
1026
+ action = self.get('action')
1027
+ if base_url and action is not None:
1028
+ return urljoin(base_url, action)
1029
+ else:
1030
+ return action
1031
+
1032
+ @action.setter
1033
+ def action(self, value):
1034
+ self.set('action', value)
1035
+
1036
+ @action.deleter
1037
+ def action(self):
1038
+ attrib = self.attrib
1039
+ if 'action' in attrib:
1040
+ del attrib['action']
1041
+
1042
+ @property
1043
+ def method(self):
1044
+ """
1045
+ Get/set the form's method. Always returns a capitalized
1046
+ string, and defaults to ``'GET'``
1047
+ """
1048
+ return self.get('method', 'GET').upper()
1049
+
1050
+ @method.setter
1051
+ def method(self, value):
1052
+ self.set('method', value.upper())
1053
+
1054
+
1055
+ HtmlElementClassLookup._default_element_classes['form'] = FormElement
1056
+
1057
+
1058
+ def submit_form(form, extra_values=None, open_http=None):
1059
+ """
1060
+ Helper function to submit a form. Returns a file-like object, as from
1061
+ ``urllib.urlopen()``. This object also has a ``.geturl()`` function,
1062
+ which shows the URL if there were any redirects.
1063
+
1064
+ You can use this like::
1065
+
1066
+ form = doc.forms[0]
1067
+ form.inputs['foo'].value = 'bar' # etc
1068
+ response = form.submit()
1069
+ doc = parse(response)
1070
+ doc.make_links_absolute(response.geturl())
1071
+
1072
+ To change the HTTP requester, pass a function as ``open_http`` keyword
1073
+ argument that opens the URL for you. The function must have the following
1074
+ signature::
1075
+
1076
+ open_http(method, URL, values)
1077
+
1078
+ The action is one of 'GET' or 'POST', the URL is the target URL as a
1079
+ string, and the values are a sequence of ``(name, value)`` tuples with the
1080
+ form data.
1081
+ """
1082
+ values = form.form_values()
1083
+ if extra_values:
1084
+ if hasattr(extra_values, 'items'):
1085
+ extra_values = extra_values.items()
1086
+ values.extend(extra_values)
1087
+ if open_http is None:
1088
+ open_http = open_http_urllib
1089
+ if form.action:
1090
+ url = form.action
1091
+ else:
1092
+ url = form.base_url
1093
+ return open_http(form.method, url, values)
1094
+
1095
+
1096
+ def open_http_urllib(method, url, values):
1097
+ if not url:
1098
+ raise ValueError("cannot submit, no URL provided")
1099
+ ## FIXME: should test that it's not a relative URL or something
1100
+ try:
1101
+ from urllib import urlencode, urlopen
1102
+ except ImportError: # Python 3
1103
+ from urllib.request import urlopen
1104
+ from urllib.parse import urlencode
1105
+ if method == 'GET':
1106
+ if '?' in url:
1107
+ url += '&'
1108
+ else:
1109
+ url += '?'
1110
+ url += urlencode(values)
1111
+ data = None
1112
+ else:
1113
+ data = urlencode(values)
1114
+ if not isinstance(data, bytes):
1115
+ data = data.encode('ASCII')
1116
+ return urlopen(url, data)
1117
+
1118
+
1119
+ class FieldsDict(MutableMapping):
1120
+
1121
+ def __init__(self, inputs):
1122
+ self.inputs = inputs
1123
+ def __getitem__(self, item):
1124
+ return self.inputs[item].value
1125
+ def __setitem__(self, item, value):
1126
+ self.inputs[item].value = value
1127
+ def __delitem__(self, item):
1128
+ raise KeyError(
1129
+ "You cannot remove keys from ElementDict")
1130
+ def keys(self):
1131
+ return self.inputs.keys()
1132
+ def __contains__(self, item):
1133
+ return item in self.inputs
1134
+ def __iter__(self):
1135
+ return iter(self.inputs.keys())
1136
+ def __len__(self):
1137
+ return len(self.inputs)
1138
+
1139
+ def __repr__(self):
1140
+ return '<%s for form %s>' % (
1141
+ self.__class__.__name__,
1142
+ self.inputs.form._name())
1143
+
1144
+
1145
+ class InputGetter:
1146
+
1147
+ """
1148
+ An accessor that represents all the input fields in a form.
1149
+
1150
+ You can get fields by name from this, with
1151
+ ``form.inputs['field_name']``. If there are a set of checkboxes
1152
+ with the same name, they are returned as a list (a `CheckboxGroup`
1153
+ which also allows value setting). Radio inputs are handled
1154
+ similarly. Use ``.keys()`` and ``.items()`` to process all fields
1155
+ in this way.
1156
+
1157
+ You can also iterate over this to get all input elements. This
1158
+ won't return the same thing as if you get all the names, as
1159
+ checkboxes and radio elements are returned individually.
1160
+ """
1161
+
1162
+ def __init__(self, form):
1163
+ self.form = form
1164
+
1165
+ def __repr__(self):
1166
+ return '<%s for form %s>' % (
1167
+ self.__class__.__name__,
1168
+ self.form._name())
1169
+
1170
+ ## FIXME: there should be more methods, and it's unclear if this is
1171
+ ## a dictionary-like object or list-like object
1172
+
1173
+ def __getitem__(self, name):
1174
+ fields = [field for field in self if field.name == name]
1175
+ if not fields:
1176
+ raise KeyError("No input element with the name %r" % name)
1177
+
1178
+ input_type = fields[0].get('type')
1179
+ if input_type == 'radio' and len(fields) > 1:
1180
+ group = RadioGroup(fields)
1181
+ group.name = name
1182
+ return group
1183
+ elif input_type == 'checkbox' and len(fields) > 1:
1184
+ group = CheckboxGroup(fields)
1185
+ group.name = name
1186
+ return group
1187
+ else:
1188
+ # I don't like throwing away elements like this
1189
+ return fields[0]
1190
+
1191
+ def __contains__(self, name):
1192
+ for field in self:
1193
+ if field.name == name:
1194
+ return True
1195
+ return False
1196
+
1197
+ def keys(self):
1198
+ """
1199
+ Returns all unique field names, in document order.
1200
+
1201
+ :return: A list of all unique field names.
1202
+ """
1203
+ names = []
1204
+ seen = {None}
1205
+ for el in self:
1206
+ name = el.name
1207
+ if name not in seen:
1208
+ names.append(name)
1209
+ seen.add(name)
1210
+ return names
1211
+
1212
+ def items(self):
1213
+ """
1214
+ Returns all fields with their names, similar to dict.items().
1215
+
1216
+ :return: A list of (name, field) tuples.
1217
+ """
1218
+ items = []
1219
+ seen = set()
1220
+ for el in self:
1221
+ name = el.name
1222
+ if name not in seen:
1223
+ seen.add(name)
1224
+ items.append((name, self[name]))
1225
+ return items
1226
+
1227
+ def __iter__(self):
1228
+ return self.form.iter('select', 'input', 'textarea')
1229
+
1230
+ def __len__(self):
1231
+ return sum(1 for _ in self)
1232
+
1233
+
1234
+ class InputMixin:
1235
+ """
1236
+ Mix-in for all input elements (input, select, and textarea)
1237
+ """
1238
+ @property
1239
+ def name(self):
1240
+ """
1241
+ Get/set the name of the element
1242
+ """
1243
+ return self.get('name')
1244
+
1245
+ @name.setter
1246
+ def name(self, value):
1247
+ self.set('name', value)
1248
+
1249
+ @name.deleter
1250
+ def name(self):
1251
+ attrib = self.attrib
1252
+ if 'name' in attrib:
1253
+ del attrib['name']
1254
+
1255
+ def __repr__(self):
1256
+ type_name = getattr(self, 'type', None)
1257
+ if type_name:
1258
+ type_name = ' type=%r' % type_name
1259
+ else:
1260
+ type_name = ''
1261
+ return '<%s %x name=%r%s>' % (
1262
+ self.__class__.__name__, id(self), self.name, type_name)
1263
+
1264
+
1265
+ class TextareaElement(InputMixin, HtmlElement):
1266
+ """
1267
+ ``<textarea>`` element. You can get the name with ``.name`` and
1268
+ get/set the value with ``.value``
1269
+ """
1270
+ @property
1271
+ def value(self):
1272
+ """
1273
+ Get/set the value (which is the contents of this element)
1274
+ """
1275
+ content = self.text or ''
1276
+ if self.tag.startswith("{%s}" % XHTML_NAMESPACE):
1277
+ serialisation_method = 'xml'
1278
+ else:
1279
+ serialisation_method = 'html'
1280
+ for el in self:
1281
+ # it's rare that we actually get here, so let's not use ''.join()
1282
+ content += etree.tostring(
1283
+ el, method=serialisation_method, encoding='unicode')
1284
+ return content
1285
+
1286
+ @value.setter
1287
+ def value(self, value):
1288
+ del self[:]
1289
+ self.text = value
1290
+
1291
+ @value.deleter
1292
+ def value(self):
1293
+ self.text = ''
1294
+ del self[:]
1295
+
1296
+
1297
+ HtmlElementClassLookup._default_element_classes['textarea'] = TextareaElement
1298
+
1299
+
1300
+ class SelectElement(InputMixin, HtmlElement):
1301
+ """
1302
+ ``<select>`` element. You can get the name with ``.name``.
1303
+
1304
+ ``.value`` will be the value of the selected option, unless this
1305
+ is a multi-select element (``<select multiple>``), in which case
1306
+ it will be a set-like object. In either case ``.value_options``
1307
+ gives the possible values.
1308
+
1309
+ The boolean attribute ``.multiple`` shows if this is a
1310
+ multi-select.
1311
+ """
1312
+ @property
1313
+ def value(self):
1314
+ """
1315
+ Get/set the value of this select (the selected option).
1316
+
1317
+ If this is a multi-select, this is a set-like object that
1318
+ represents all the selected options.
1319
+ """
1320
+ if self.multiple:
1321
+ return MultipleSelectOptions(self)
1322
+ options = _options_xpath(self)
1323
+
1324
+ try:
1325
+ selected_option = next(el for el in reversed(options) if el.get('selected') is not None)
1326
+ except StopIteration:
1327
+ try:
1328
+ selected_option = next(el for el in options if el.get('disabled') is None)
1329
+ except StopIteration:
1330
+ return None
1331
+ value = selected_option.get('value')
1332
+ if value is None:
1333
+ value = (selected_option.text or '').strip()
1334
+ return value
1335
+
1336
+ @value.setter
1337
+ def value(self, value):
1338
+ if self.multiple:
1339
+ if isinstance(value, str):
1340
+ raise TypeError("You must pass in a sequence")
1341
+ values = self.value
1342
+ values.clear()
1343
+ values.update(value)
1344
+ return
1345
+ checked_option = None
1346
+ if value is not None:
1347
+ for el in _options_xpath(self):
1348
+ opt_value = el.get('value')
1349
+ if opt_value is None:
1350
+ opt_value = (el.text or '').strip()
1351
+ if opt_value == value:
1352
+ checked_option = el
1353
+ break
1354
+ else:
1355
+ raise ValueError(
1356
+ "There is no option with the value of %r" % value)
1357
+ for el in _options_xpath(self):
1358
+ if 'selected' in el.attrib:
1359
+ del el.attrib['selected']
1360
+ if checked_option is not None:
1361
+ checked_option.set('selected', '')
1362
+
1363
+ @value.deleter
1364
+ def value(self):
1365
+ # FIXME: should del be allowed at all?
1366
+ if self.multiple:
1367
+ self.value.clear()
1368
+ else:
1369
+ self.value = None
1370
+
1371
+ @property
1372
+ def value_options(self):
1373
+ """
1374
+ All the possible values this select can have (the ``value``
1375
+ attribute of all the ``<option>`` elements.
1376
+ """
1377
+ options = []
1378
+ for el in _options_xpath(self):
1379
+ value = el.get('value')
1380
+ if value is None:
1381
+ value = (el.text or '').strip()
1382
+ options.append(value)
1383
+ return options
1384
+
1385
+ @property
1386
+ def multiple(self):
1387
+ """
1388
+ Boolean attribute: is there a ``multiple`` attribute on this element.
1389
+ """
1390
+ return 'multiple' in self.attrib
1391
+
1392
+ @multiple.setter
1393
+ def multiple(self, value):
1394
+ if value:
1395
+ self.set('multiple', '')
1396
+ elif 'multiple' in self.attrib:
1397
+ del self.attrib['multiple']
1398
+
1399
+
1400
+ HtmlElementClassLookup._default_element_classes['select'] = SelectElement
1401
+
1402
+
1403
+ class MultipleSelectOptions(SetMixin):
1404
+ """
1405
+ Represents all the selected options in a ``<select multiple>`` element.
1406
+
1407
+ You can add to this set-like option to select an option, or remove
1408
+ to unselect the option.
1409
+ """
1410
+
1411
+ def __init__(self, select):
1412
+ self.select = select
1413
+
1414
+ @property
1415
+ def options(self):
1416
+ """
1417
+ Iterator of all the ``<option>`` elements.
1418
+ """
1419
+ return iter(_options_xpath(self.select))
1420
+
1421
+ def __iter__(self):
1422
+ for option in self.options:
1423
+ if 'selected' in option.attrib:
1424
+ opt_value = option.get('value')
1425
+ if opt_value is None:
1426
+ opt_value = (option.text or '').strip()
1427
+ yield opt_value
1428
+
1429
+ def add(self, item):
1430
+ for option in self.options:
1431
+ opt_value = option.get('value')
1432
+ if opt_value is None:
1433
+ opt_value = (option.text or '').strip()
1434
+ if opt_value == item:
1435
+ option.set('selected', '')
1436
+ break
1437
+ else:
1438
+ raise ValueError(
1439
+ "There is no option with the value %r" % item)
1440
+
1441
+ def remove(self, item):
1442
+ for option in self.options:
1443
+ opt_value = option.get('value')
1444
+ if opt_value is None:
1445
+ opt_value = (option.text or '').strip()
1446
+ if opt_value == item:
1447
+ if 'selected' in option.attrib:
1448
+ del option.attrib['selected']
1449
+ else:
1450
+ raise ValueError(
1451
+ "The option %r is not currently selected" % item)
1452
+ break
1453
+ else:
1454
+ raise ValueError(
1455
+ "There is not option with the value %r" % item)
1456
+
1457
+ def __repr__(self):
1458
+ return '<%s {%s} for select name=%r>' % (
1459
+ self.__class__.__name__,
1460
+ ', '.join([repr(v) for v in self]),
1461
+ self.select.name)
1462
+
1463
+
1464
+ class RadioGroup(list):
1465
+ """
1466
+ This object represents several ``<input type=radio>`` elements
1467
+ that have the same name.
1468
+
1469
+ You can use this like a list, but also use the property
1470
+ ``.value`` to check/uncheck inputs. Also you can use
1471
+ ``.value_options`` to get the possible values.
1472
+ """
1473
+ @property
1474
+ def value(self):
1475
+ """
1476
+ Get/set the value, which checks the radio with that value (and
1477
+ unchecks any other value).
1478
+ """
1479
+ for el in self:
1480
+ if 'checked' in el.attrib:
1481
+ return el.get('value')
1482
+ return None
1483
+
1484
+ @value.setter
1485
+ def value(self, value):
1486
+ checked_option = None
1487
+ if value is not None:
1488
+ for el in self:
1489
+ if el.get('value') == value:
1490
+ checked_option = el
1491
+ break
1492
+ else:
1493
+ raise ValueError("There is no radio input with the value %r" % value)
1494
+ for el in self:
1495
+ if 'checked' in el.attrib:
1496
+ del el.attrib['checked']
1497
+ if checked_option is not None:
1498
+ checked_option.set('checked', '')
1499
+
1500
+ @value.deleter
1501
+ def value(self):
1502
+ self.value = None
1503
+
1504
+ @property
1505
+ def value_options(self):
1506
+ """
1507
+ Returns a list of all the possible values.
1508
+ """
1509
+ return [el.get('value') for el in self]
1510
+
1511
+ def __repr__(self):
1512
+ return '%s(%s)' % (
1513
+ self.__class__.__name__,
1514
+ list.__repr__(self))
1515
+
1516
+
1517
+ class CheckboxGroup(list):
1518
+ """
1519
+ Represents a group of checkboxes (``<input type=checkbox>``) that
1520
+ have the same name.
1521
+
1522
+ In addition to using this like a list, the ``.value`` attribute
1523
+ returns a set-like object that you can add to or remove from to
1524
+ check and uncheck checkboxes. You can also use ``.value_options``
1525
+ to get the possible values.
1526
+ """
1527
+ @property
1528
+ def value(self):
1529
+ """
1530
+ Return a set-like object that can be modified to check or
1531
+ uncheck individual checkboxes according to their value.
1532
+ """
1533
+ return CheckboxValues(self)
1534
+
1535
+ @value.setter
1536
+ def value(self, value):
1537
+ values = self.value
1538
+ values.clear()
1539
+ if not hasattr(value, '__iter__'):
1540
+ raise ValueError(
1541
+ "A CheckboxGroup (name=%r) must be set to a sequence (not %r)"
1542
+ % (self[0].name, value))
1543
+ values.update(value)
1544
+
1545
+ @value.deleter
1546
+ def value(self):
1547
+ self.value.clear()
1548
+
1549
+ @property
1550
+ def value_options(self):
1551
+ """
1552
+ Returns a list of all the possible values.
1553
+ """
1554
+ return [el.get('value') for el in self]
1555
+
1556
+ def __repr__(self):
1557
+ return '%s(%s)' % (
1558
+ self.__class__.__name__, list.__repr__(self))
1559
+
1560
+
1561
+ class CheckboxValues(SetMixin):
1562
+ """
1563
+ Represents the values of the checked checkboxes in a group of
1564
+ checkboxes with the same name.
1565
+ """
1566
+
1567
+ def __init__(self, group):
1568
+ self.group = group
1569
+
1570
+ def __iter__(self):
1571
+ return iter([
1572
+ el.get('value')
1573
+ for el in self.group
1574
+ if 'checked' in el.attrib])
1575
+
1576
+ def add(self, value):
1577
+ for el in self.group:
1578
+ if el.get('value') == value:
1579
+ el.set('checked', '')
1580
+ break
1581
+ else:
1582
+ raise KeyError("No checkbox with value %r" % value)
1583
+
1584
+ def remove(self, value):
1585
+ for el in self.group:
1586
+ if el.get('value') == value:
1587
+ if 'checked' in el.attrib:
1588
+ del el.attrib['checked']
1589
+ else:
1590
+ raise KeyError(
1591
+ "The checkbox with value %r was already unchecked" % value)
1592
+ break
1593
+ else:
1594
+ raise KeyError(
1595
+ "No checkbox with value %r" % value)
1596
+
1597
+ def __repr__(self):
1598
+ return '<%s {%s} for checkboxes name=%r>' % (
1599
+ self.__class__.__name__,
1600
+ ', '.join([repr(v) for v in self]),
1601
+ self.group.name)
1602
+
1603
+
1604
+ class InputElement(InputMixin, HtmlElement):
1605
+ """
1606
+ Represents an ``<input>`` element.
1607
+
1608
+ You can get the type with ``.type`` (which is lower-cased and
1609
+ defaults to ``'text'``).
1610
+
1611
+ Also you can get and set the value with ``.value``
1612
+
1613
+ Checkboxes and radios have the attribute ``input.checkable ==
1614
+ True`` (for all others it is false) and a boolean attribute
1615
+ ``.checked``.
1616
+
1617
+ """
1618
+
1619
+ ## FIXME: I'm a little uncomfortable with the use of .checked
1620
+ @property
1621
+ def value(self):
1622
+ """
1623
+ Get/set the value of this element, using the ``value`` attribute.
1624
+
1625
+ Also, if this is a checkbox and it has no value, this defaults
1626
+ to ``'on'``. If it is a checkbox or radio that is not
1627
+ checked, this returns None.
1628
+ """
1629
+ if self.checkable:
1630
+ if self.checked:
1631
+ return self.get('value') or 'on'
1632
+ else:
1633
+ return None
1634
+ return self.get('value')
1635
+
1636
+ @value.setter
1637
+ def value(self, value):
1638
+ if self.checkable:
1639
+ if not value:
1640
+ self.checked = False
1641
+ else:
1642
+ self.checked = True
1643
+ if isinstance(value, str):
1644
+ self.set('value', value)
1645
+ else:
1646
+ self.set('value', value)
1647
+
1648
+ @value.deleter
1649
+ def value(self):
1650
+ if self.checkable:
1651
+ self.checked = False
1652
+ else:
1653
+ if 'value' in self.attrib:
1654
+ del self.attrib['value']
1655
+
1656
+ @property
1657
+ def type(self):
1658
+ """
1659
+ Return the type of this element (using the type attribute).
1660
+ """
1661
+ return self.get('type', 'text').lower()
1662
+
1663
+ @type.setter
1664
+ def type(self, value):
1665
+ self.set('type', value)
1666
+
1667
+ @property
1668
+ def checkable(self):
1669
+ """
1670
+ Boolean: can this element be checked?
1671
+ """
1672
+ return self.type in ('checkbox', 'radio')
1673
+
1674
+ @property
1675
+ def checked(self):
1676
+ """
1677
+ Boolean attribute to get/set the presence of the ``checked``
1678
+ attribute.
1679
+
1680
+ You can only use this on checkable input types.
1681
+ """
1682
+ if not self.checkable:
1683
+ raise AttributeError('Not a checkable input type')
1684
+ return 'checked' in self.attrib
1685
+
1686
+ @checked.setter
1687
+ def checked(self, value):
1688
+ if not self.checkable:
1689
+ raise AttributeError('Not a checkable input type')
1690
+ if value:
1691
+ self.set('checked', '')
1692
+ else:
1693
+ attrib = self.attrib
1694
+ if 'checked' in attrib:
1695
+ del attrib['checked']
1696
+
1697
+
1698
+ HtmlElementClassLookup._default_element_classes['input'] = InputElement
1699
+
1700
+
1701
+ class LabelElement(HtmlElement):
1702
+ """
1703
+ Represents a ``<label>`` element.
1704
+
1705
+ Label elements are linked to other elements with their ``for``
1706
+ attribute. You can access this element with ``label.for_element``.
1707
+ """
1708
+ @property
1709
+ def for_element(self):
1710
+ """
1711
+ Get/set the element this label points to. Return None if it
1712
+ can't be found.
1713
+ """
1714
+ id = self.get('for')
1715
+ if not id:
1716
+ return None
1717
+ return self.body.get_element_by_id(id)
1718
+
1719
+ @for_element.setter
1720
+ def for_element(self, other):
1721
+ id = other.get('id')
1722
+ if not id:
1723
+ raise TypeError(
1724
+ "Element %r has no id attribute" % other)
1725
+ self.set('for', id)
1726
+
1727
+ @for_element.deleter
1728
+ def for_element(self):
1729
+ attrib = self.attrib
1730
+ if 'id' in attrib:
1731
+ del attrib['id']
1732
+
1733
+
1734
+ HtmlElementClassLookup._default_element_classes['label'] = LabelElement
1735
+
1736
+
1737
+ ############################################################
1738
+ ## Serialization
1739
+ ############################################################
1740
+
1741
+ def html_to_xhtml(html):
1742
+ """Convert all tags in an HTML tree to XHTML by moving them to the
1743
+ XHTML namespace.
1744
+ """
1745
+ try:
1746
+ html = html.getroot()
1747
+ except AttributeError:
1748
+ pass
1749
+ prefix = "{%s}" % XHTML_NAMESPACE
1750
+ for el in html.iter(etree.Element):
1751
+ tag = el.tag
1752
+ if tag[0] != '{':
1753
+ el.tag = prefix + tag
1754
+
1755
+
1756
+ def xhtml_to_html(xhtml):
1757
+ """Convert all tags in an XHTML tree to HTML by removing their
1758
+ XHTML namespace.
1759
+ """
1760
+ try:
1761
+ xhtml = xhtml.getroot()
1762
+ except AttributeError:
1763
+ pass
1764
+ prefix = "{%s}" % XHTML_NAMESPACE
1765
+ prefix_len = len(prefix)
1766
+ for el in xhtml.iter(prefix + "*"):
1767
+ el.tag = el.tag[prefix_len:]
1768
+
1769
+
1770
+ # This isn't a general match, but it's a match for what libxml2
1771
+ # specifically serialises:
1772
+ __str_replace_meta_content_type = re.compile(
1773
+ r'<meta http-equiv="Content-Type"[^>]*>').sub
1774
+ __bytes_replace_meta_content_type = re.compile(
1775
+ br'<meta http-equiv="Content-Type"[^>]*>').sub
1776
+
1777
+
1778
+ def tostring(doc, pretty_print=False, include_meta_content_type=False,
1779
+ encoding=None, method="html", with_tail=True, doctype=None):
1780
+ """Return an HTML string representation of the document.
1781
+
1782
+ Note: if include_meta_content_type is true this will create a
1783
+ ``<meta http-equiv="Content-Type" ...>`` tag in the head;
1784
+ regardless of the value of include_meta_content_type any existing
1785
+ ``<meta http-equiv="Content-Type" ...>`` tag will be removed
1786
+
1787
+ The ``encoding`` argument controls the output encoding (defaults to
1788
+ ASCII, with &#...; character references for any characters outside
1789
+ of ASCII). Note that you can pass the name ``'unicode'`` as
1790
+ ``encoding`` argument to serialise to a Unicode string.
1791
+
1792
+ The ``method`` argument defines the output method. It defaults to
1793
+ 'html', but can also be 'xml' for xhtml output, or 'text' to
1794
+ serialise to plain text without markup.
1795
+
1796
+ To leave out the tail text of the top-level element that is being
1797
+ serialised, pass ``with_tail=False``.
1798
+
1799
+ The ``doctype`` option allows passing in a plain string that will
1800
+ be serialised before the XML tree. Note that passing in non
1801
+ well-formed content here will make the XML output non well-formed.
1802
+ Also, an existing doctype in the document tree will not be removed
1803
+ when serialising an ElementTree instance.
1804
+
1805
+ Example::
1806
+
1807
+ >>> from lxml import html
1808
+ >>> root = html.fragment_fromstring('<p>Hello<br>world!</p>')
1809
+
1810
+ >>> html.tostring(root)
1811
+ b'<p>Hello<br>world!</p>'
1812
+ >>> html.tostring(root, method='html')
1813
+ b'<p>Hello<br>world!</p>'
1814
+
1815
+ >>> html.tostring(root, method='xml')
1816
+ b'<p>Hello<br/>world!</p>'
1817
+
1818
+ >>> html.tostring(root, method='text')
1819
+ b'Helloworld!'
1820
+
1821
+ >>> html.tostring(root, method='text', encoding='unicode')
1822
+ u'Helloworld!'
1823
+
1824
+ >>> root = html.fragment_fromstring('<div><p>Hello<br>world!</p>TAIL</div>')
1825
+ >>> html.tostring(root[0], method='text', encoding='unicode')
1826
+ u'Helloworld!TAIL'
1827
+
1828
+ >>> html.tostring(root[0], method='text', encoding='unicode', with_tail=False)
1829
+ u'Helloworld!'
1830
+
1831
+ >>> doc = html.document_fromstring('<p>Hello<br>world!</p>')
1832
+ >>> html.tostring(doc, method='html', encoding='unicode')
1833
+ u'<html><body><p>Hello<br>world!</p></body></html>'
1834
+
1835
+ >>> print(html.tostring(doc, method='html', encoding='unicode',
1836
+ ... doctype='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'
1837
+ ... ' "http://www.w3.org/TR/html4/strict.dtd">'))
1838
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
1839
+ <html><body><p>Hello<br>world!</p></body></html>
1840
+ """
1841
+ html = etree.tostring(doc, method=method, pretty_print=pretty_print,
1842
+ encoding=encoding, with_tail=with_tail,
1843
+ doctype=doctype)
1844
+ if method == 'html' and not include_meta_content_type:
1845
+ if isinstance(html, str):
1846
+ html = __str_replace_meta_content_type('', html)
1847
+ else:
1848
+ html = __bytes_replace_meta_content_type(b'', html)
1849
+ return html
1850
+
1851
+
1852
+ tostring.__doc__ = __fix_docstring(tostring.__doc__)
1853
+
1854
+
1855
+ def open_in_browser(doc, encoding=None):
1856
+ """
1857
+ Open the HTML document in a web browser, saving it to a temporary
1858
+ file to open it. Note that this does not delete the file after
1859
+ use. This is mainly meant for debugging.
1860
+ """
1861
+ import os
1862
+ import webbrowser
1863
+ import tempfile
1864
+ if not isinstance(doc, etree._ElementTree):
1865
+ doc = etree.ElementTree(doc)
1866
+ handle, fn = tempfile.mkstemp(suffix='.html')
1867
+ f = os.fdopen(handle, 'wb')
1868
+ try:
1869
+ doc.write(f, method="html", encoding=encoding or doc.docinfo.encoding or "UTF-8")
1870
+ finally:
1871
+ # we leak the file itself here, but we should at least close it
1872
+ f.close()
1873
+ url = 'file://' + fn.replace(os.path.sep, '/')
1874
+ print(url)
1875
+ webbrowser.open(url)
1876
+
1877
+
1878
+ ################################################################################
1879
+ # configure Element class lookup
1880
+ ################################################################################
1881
+
1882
+ class HTMLParser(etree.HTMLParser):
1883
+ """An HTML parser that is configured to return lxml.html Element
1884
+ objects.
1885
+ """
1886
+ def __init__(self, **kwargs):
1887
+ super().__init__(**kwargs)
1888
+ self.set_element_class_lookup(HtmlElementClassLookup())
1889
+
1890
+
1891
+ class XHTMLParser(etree.XMLParser):
1892
+ """An XML parser that is configured to return lxml.html Element
1893
+ objects.
1894
+
1895
+ Note that this parser is not really XHTML aware unless you let it
1896
+ load a DTD that declares the HTML entities. To do this, make sure
1897
+ you have the XHTML DTDs installed in your catalogs, and create the
1898
+ parser like this::
1899
+
1900
+ >>> parser = XHTMLParser(load_dtd=True)
1901
+
1902
+ If you additionally want to validate the document, use this::
1903
+
1904
+ >>> parser = XHTMLParser(dtd_validation=True)
1905
+
1906
+ For catalog support, see http://www.xmlsoft.org/catalog.html.
1907
+ """
1908
+ def __init__(self, **kwargs):
1909
+ super().__init__(**kwargs)
1910
+ self.set_element_class_lookup(HtmlElementClassLookup())
1911
+
1912
+
1913
+ def Element(*args, **kw):
1914
+ """Create a new HTML Element.
1915
+
1916
+ This can also be used for XHTML documents.
1917
+ """
1918
+ v = html_parser.makeelement(*args, **kw)
1919
+ return v
1920
+
1921
+
1922
+ html_parser = HTMLParser()
1923
+ xhtml_parser = XHTMLParser()
venv/lib/python3.10/site-packages/lxml/html/__pycache__/ElementSoup.cpython-310.pyc ADDED
Binary file (522 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (56 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/_diffcommand.cpython-310.pyc ADDED
Binary file (2.26 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/_html5builder.cpython-310.pyc ADDED
Binary file (3.6 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/_setmixin.cpython-310.pyc ADDED
Binary file (2.09 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/builder.cpython-310.pyc ADDED
Binary file (2.95 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/clean.cpython-310.pyc ADDED
Binary file (553 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/defs.cpython-310.pyc ADDED
Binary file (2.82 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/diff.cpython-310.pyc ADDED
Binary file (24 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/formfill.cpython-310.pyc ADDED
Binary file (7.39 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/html5parser.cpython-310.pyc ADDED
Binary file (6.43 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/soupparser.cpython-310.pyc ADDED
Binary file (8.02 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/__pycache__/usedoctest.cpython-310.pyc ADDED
Binary file (448 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/html/_diffcommand.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import optparse
2
+ import sys
3
+ import re
4
+ import os
5
+ from .diff import htmldiff
6
+
7
+ description = """\
8
+ """
9
+
10
+ parser = optparse.OptionParser(
11
+ usage="%prog [OPTIONS] FILE1 FILE2\n"
12
+ "%prog --annotate [OPTIONS] INFO1 FILE1 INFO2 FILE2 ...",
13
+ description=description,
14
+ )
15
+
16
+ parser.add_option(
17
+ '-o', '--output',
18
+ metavar="FILE",
19
+ dest="output",
20
+ default="-",
21
+ help="File to write the difference to",
22
+ )
23
+
24
+ parser.add_option(
25
+ '-a', '--annotation',
26
+ action="store_true",
27
+ dest="annotation",
28
+ help="Do an annotation")
29
+
30
+ def main(args=None):
31
+ if args is None:
32
+ args = sys.argv[1:]
33
+ options, args = parser.parse_args(args)
34
+ if options.annotation:
35
+ return annotate(options, args)
36
+ if len(args) != 2:
37
+ print('Error: you must give two files')
38
+ parser.print_help()
39
+ sys.exit(1)
40
+ file1, file2 = args
41
+ input1 = read_file(file1)
42
+ input2 = read_file(file2)
43
+ body1 = split_body(input1)[1]
44
+ pre, body2, post = split_body(input2)
45
+ result = htmldiff(body1, body2)
46
+ result = pre + result + post
47
+ if options.output == '-':
48
+ if not result.endswith('\n'):
49
+ result += '\n'
50
+ sys.stdout.write(result)
51
+ else:
52
+ with open(options.output, 'wb') as f:
53
+ f.write(result)
54
+
55
+ def read_file(filename):
56
+ if filename == '-':
57
+ c = sys.stdin.read()
58
+ elif not os.path.exists(filename):
59
+ raise OSError(
60
+ "Input file %s does not exist" % filename)
61
+ else:
62
+ with open(filename, 'rb') as f:
63
+ c = f.read()
64
+ return c
65
+
66
+ body_start_re = re.compile(
67
+ r"<body.*?>", re.I|re.S)
68
+ body_end_re = re.compile(
69
+ r"</body.*?>", re.I|re.S)
70
+
71
+ def split_body(html):
72
+ pre = post = ''
73
+ match = body_start_re.search(html)
74
+ if match:
75
+ pre = html[:match.end()]
76
+ html = html[match.end():]
77
+ match = body_end_re.search(html)
78
+ if match:
79
+ post = html[match.start():]
80
+ html = html[:match.start()]
81
+ return pre, html, post
82
+
83
+ def annotate(options, args):
84
+ print("Not yet implemented")
85
+ sys.exit(1)
86
+
venv/lib/python3.10/site-packages/lxml/html/_html5builder.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Legacy module - don't use in new code!
3
+
4
+ html5lib now has its own proper implementation.
5
+
6
+ This module implements a tree builder for html5lib that generates lxml
7
+ html element trees. This module uses camelCase as it follows the
8
+ html5lib style guide.
9
+ """
10
+
11
+ from html5lib.treebuilders import _base, etree as etree_builders
12
+ from lxml import html, etree
13
+
14
+
15
+ class DocumentType:
16
+
17
+ def __init__(self, name, publicId, systemId):
18
+ self.name = name
19
+ self.publicId = publicId
20
+ self.systemId = systemId
21
+
22
+ class Document:
23
+
24
+ def __init__(self):
25
+ self._elementTree = None
26
+ self.childNodes = []
27
+
28
+ def appendChild(self, element):
29
+ self._elementTree.getroot().addnext(element._element)
30
+
31
+
32
+ class TreeBuilder(_base.TreeBuilder):
33
+ documentClass = Document
34
+ doctypeClass = DocumentType
35
+ elementClass = None
36
+ commentClass = None
37
+ fragmentClass = Document
38
+
39
+ def __init__(self, *args, **kwargs):
40
+ html_builder = etree_builders.getETreeModule(html, fullTree=False)
41
+ etree_builder = etree_builders.getETreeModule(etree, fullTree=False)
42
+ self.elementClass = html_builder.Element
43
+ self.commentClass = etree_builder.Comment
44
+ _base.TreeBuilder.__init__(self, *args, **kwargs)
45
+
46
+ def reset(self):
47
+ _base.TreeBuilder.reset(self)
48
+ self.rootInserted = False
49
+ self.initialComments = []
50
+ self.doctype = None
51
+
52
+ def getDocument(self):
53
+ return self.document._elementTree
54
+
55
+ def getFragment(self):
56
+ fragment = []
57
+ element = self.openElements[0]._element
58
+ if element.text:
59
+ fragment.append(element.text)
60
+ fragment.extend(element.getchildren())
61
+ if element.tail:
62
+ fragment.append(element.tail)
63
+ return fragment
64
+
65
+ def insertDoctype(self, name, publicId, systemId):
66
+ doctype = self.doctypeClass(name, publicId, systemId)
67
+ self.doctype = doctype
68
+
69
+ def insertComment(self, data, parent=None):
70
+ if not self.rootInserted:
71
+ self.initialComments.append(data)
72
+ else:
73
+ _base.TreeBuilder.insertComment(self, data, parent)
74
+
75
+ def insertRoot(self, name):
76
+ buf = []
77
+ if self.doctype and self.doctype.name:
78
+ buf.append('<!DOCTYPE %s' % self.doctype.name)
79
+ if self.doctype.publicId is not None or self.doctype.systemId is not None:
80
+ buf.append(' PUBLIC "%s" "%s"' % (self.doctype.publicId,
81
+ self.doctype.systemId))
82
+ buf.append('>')
83
+ buf.append('<html></html>')
84
+ root = html.fromstring(''.join(buf))
85
+
86
+ # Append the initial comments:
87
+ for comment in self.initialComments:
88
+ root.addprevious(etree.Comment(comment))
89
+
90
+ # Create the root document and add the ElementTree to it
91
+ self.document = self.documentClass()
92
+ self.document._elementTree = root.getroottree()
93
+
94
+ # Add the root element to the internal child/open data structures
95
+ root_element = self.elementClass(name)
96
+ root_element._element = root
97
+ self.document.childNodes.append(root_element)
98
+ self.openElements.append(root_element)
99
+
100
+ self.rootInserted = True
venv/lib/python3.10/site-packages/lxml/html/_setmixin.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ try:
2
+ from collections.abc import MutableSet
3
+ except ImportError:
4
+ from collections.abc import MutableSet
5
+
6
+
7
+ class SetMixin(MutableSet):
8
+
9
+ """
10
+ Mix-in for sets. You must define __iter__, add, remove
11
+ """
12
+
13
+ def __len__(self):
14
+ length = 0
15
+ for item in self:
16
+ length += 1
17
+ return length
18
+
19
+ def __contains__(self, item):
20
+ for has_item in self:
21
+ if item == has_item:
22
+ return True
23
+ return False
24
+
25
+ issubset = MutableSet.__le__
26
+ issuperset = MutableSet.__ge__
27
+
28
+ union = MutableSet.__or__
29
+ intersection = MutableSet.__and__
30
+ difference = MutableSet.__sub__
31
+ symmetric_difference = MutableSet.__xor__
32
+
33
+ def copy(self):
34
+ return set(self)
35
+
36
+ def update(self, other):
37
+ self |= other
38
+
39
+ def intersection_update(self, other):
40
+ self &= other
41
+
42
+ def difference_update(self, other):
43
+ self -= other
44
+
45
+ def symmetric_difference_update(self, other):
46
+ self ^= other
47
+
48
+ def discard(self, item):
49
+ try:
50
+ self.remove(item)
51
+ except KeyError:
52
+ pass
53
+
54
+ @classmethod
55
+ def _from_iterable(cls, it):
56
+ return set(it)
venv/lib/python3.10/site-packages/lxml/html/builder.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # --------------------------------------------------------------------
2
+ # The ElementTree toolkit is
3
+ # Copyright (c) 1999-2004 by Fredrik Lundh
4
+ # --------------------------------------------------------------------
5
+
6
+ """
7
+ A set of HTML generator tags for building HTML documents.
8
+
9
+ Usage::
10
+
11
+ >>> from lxml.html.builder import *
12
+ >>> html = HTML(
13
+ ... HEAD( TITLE("Hello World") ),
14
+ ... BODY( CLASS("main"),
15
+ ... H1("Hello World !")
16
+ ... )
17
+ ... )
18
+
19
+ >>> import lxml.etree
20
+ >>> print lxml.etree.tostring(html, pretty_print=True)
21
+ <html>
22
+ <head>
23
+ <title>Hello World</title>
24
+ </head>
25
+ <body class="main">
26
+ <h1>Hello World !</h1>
27
+ </body>
28
+ </html>
29
+
30
+ """
31
+
32
+ from lxml.builder import ElementMaker
33
+ from lxml.html import html_parser
34
+
35
+ E = ElementMaker(makeelement=html_parser.makeelement)
36
+
37
+ # elements
38
+ A = E.a #: anchor
39
+ ABBR = E.abbr #: abbreviated form (e.g., WWW, HTTP, etc.)
40
+ ACRONYM = E.acronym #:
41
+ ADDRESS = E.address #: information on author
42
+ APPLET = E.applet #: Java applet (DEPRECATED)
43
+ AREA = E.area #: client-side image map area
44
+ B = E.b #: bold text style
45
+ BASE = E.base #: document base URI
46
+ BASEFONT = E.basefont #: base font size (DEPRECATED)
47
+ BDO = E.bdo #: I18N BiDi over-ride
48
+ BIG = E.big #: large text style
49
+ BLOCKQUOTE = E.blockquote #: long quotation
50
+ BODY = E.body #: document body
51
+ BR = E.br #: forced line break
52
+ BUTTON = E.button #: push button
53
+ CAPTION = E.caption #: table caption
54
+ CENTER = E.center #: shorthand for DIV align=center (DEPRECATED)
55
+ CITE = E.cite #: citation
56
+ CODE = E.code #: computer code fragment
57
+ COL = E.col #: table column
58
+ COLGROUP = E.colgroup #: table column group
59
+ DD = E.dd #: definition description
60
+ DEL = getattr(E, 'del') #: deleted text
61
+ DFN = E.dfn #: instance definition
62
+ DIR = E.dir #: directory list (DEPRECATED)
63
+ DIV = E.div #: generic language/style container
64
+ DL = E.dl #: definition list
65
+ DT = E.dt #: definition term
66
+ EM = E.em #: emphasis
67
+ FIELDSET = E.fieldset #: form control group
68
+ FONT = E.font #: local change to font (DEPRECATED)
69
+ FORM = E.form #: interactive form
70
+ FRAME = E.frame #: subwindow
71
+ FRAMESET = E.frameset #: window subdivision
72
+ H1 = E.h1 #: heading
73
+ H2 = E.h2 #: heading
74
+ H3 = E.h3 #: heading
75
+ H4 = E.h4 #: heading
76
+ H5 = E.h5 #: heading
77
+ H6 = E.h6 #: heading
78
+ HEAD = E.head #: document head
79
+ HR = E.hr #: horizontal rule
80
+ HTML = E.html #: document root element
81
+ I = E.i #: italic text style
82
+ IFRAME = E.iframe #: inline subwindow
83
+ IMG = E.img #: Embedded image
84
+ INPUT = E.input #: form control
85
+ INS = E.ins #: inserted text
86
+ ISINDEX = E.isindex #: single line prompt (DEPRECATED)
87
+ KBD = E.kbd #: text to be entered by the user
88
+ LABEL = E.label #: form field label text
89
+ LEGEND = E.legend #: fieldset legend
90
+ LI = E.li #: list item
91
+ LINK = E.link #: a media-independent link
92
+ MAP = E.map #: client-side image map
93
+ MENU = E.menu #: menu list (DEPRECATED)
94
+ META = E.meta #: generic metainformation
95
+ NOFRAMES = E.noframes #: alternate content container for non frame-based rendering
96
+ NOSCRIPT = E.noscript #: alternate content container for non script-based rendering
97
+ OBJECT = E.object #: generic embedded object
98
+ OL = E.ol #: ordered list
99
+ OPTGROUP = E.optgroup #: option group
100
+ OPTION = E.option #: selectable choice
101
+ P = E.p #: paragraph
102
+ PARAM = E.param #: named property value
103
+ PRE = E.pre #: preformatted text
104
+ Q = E.q #: short inline quotation
105
+ S = E.s #: strike-through text style (DEPRECATED)
106
+ SAMP = E.samp #: sample program output, scripts, etc.
107
+ SCRIPT = E.script #: script statements
108
+ SELECT = E.select #: option selector
109
+ SMALL = E.small #: small text style
110
+ SPAN = E.span #: generic language/style container
111
+ STRIKE = E.strike #: strike-through text (DEPRECATED)
112
+ STRONG = E.strong #: strong emphasis
113
+ STYLE = E.style #: style info
114
+ SUB = E.sub #: subscript
115
+ SUP = E.sup #: superscript
116
+ TABLE = E.table #:
117
+ TBODY = E.tbody #: table body
118
+ TD = E.td #: table data cell
119
+ TEXTAREA = E.textarea #: multi-line text field
120
+ TFOOT = E.tfoot #: table footer
121
+ TH = E.th #: table header cell
122
+ THEAD = E.thead #: table header
123
+ TITLE = E.title #: document title
124
+ TR = E.tr #: table row
125
+ TT = E.tt #: teletype or monospaced text style
126
+ U = E.u #: underlined text style (DEPRECATED)
127
+ UL = E.ul #: unordered list
128
+ VAR = E.var #: instance of a variable or program argument
129
+
130
+ # attributes (only reserved words are included here)
131
+ ATTR = dict
132
+ def CLASS(v): return {'class': v}
133
+ def FOR(v): return {'for': v}
venv/lib/python3.10/site-packages/lxml/html/clean.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cython: language_level=3str
2
+
3
+ """Backward-compatibility module for lxml_html_clean"""
4
+
5
+ try:
6
+ from lxml_html_clean import *
7
+
8
+ __all__ = [
9
+ "clean_html",
10
+ "clean",
11
+ "Cleaner",
12
+ "autolink",
13
+ "autolink_html",
14
+ "word_break",
15
+ "word_break_html",
16
+ ]
17
+ except ImportError:
18
+ raise ImportError(
19
+ "lxml.html.clean module is now a separate project lxml_html_clean.\n"
20
+ "Install lxml[html_clean] or lxml_html_clean directly."
21
+ ) from None
venv/lib/python3.10/site-packages/lxml/html/defs.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # FIXME: this should all be confirmed against what a DTD says
2
+ # (probably in a test; this may not match the DTD exactly, but we
3
+ # should document just how it differs).
4
+
5
+ """
6
+ Data taken from https://www.w3.org/TR/html401/index/elements.html
7
+ and https://www.w3.org/community/webed/wiki/HTML/New_HTML5_Elements
8
+ for html5_tags.
9
+ """
10
+
11
+ empty_tags = frozenset([
12
+ 'area', 'base', 'basefont', 'br', 'col', 'frame', 'hr',
13
+ 'img', 'input', 'isindex', 'link', 'meta', 'param', 'source', 'track'])
14
+
15
+ deprecated_tags = frozenset([
16
+ 'applet', 'basefont', 'center', 'dir', 'font', 'isindex',
17
+ 'menu', 's', 'strike', 'u'])
18
+
19
+ # archive actually takes a space-separated list of URIs
20
+ link_attrs = frozenset([
21
+ 'action', 'archive', 'background', 'cite', 'classid',
22
+ 'codebase', 'data', 'href', 'longdesc', 'profile', 'src',
23
+ 'usemap',
24
+ # Not standard:
25
+ 'dynsrc', 'lowsrc',
26
+ # HTML5 formaction
27
+ 'formaction'
28
+ ])
29
+
30
+ # Not in the HTML 4 spec:
31
+ # onerror, onresize
32
+ event_attrs = frozenset([
33
+ 'onblur', 'onchange', 'onclick', 'ondblclick', 'onerror',
34
+ 'onfocus', 'onkeydown', 'onkeypress', 'onkeyup', 'onload',
35
+ 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover',
36
+ 'onmouseup', 'onreset', 'onresize', 'onselect', 'onsubmit',
37
+ 'onunload',
38
+ ])
39
+
40
+ safe_attrs = frozenset([
41
+ 'abbr', 'accept', 'accept-charset', 'accesskey', 'action', 'align',
42
+ 'alt', 'axis', 'border', 'cellpadding', 'cellspacing', 'char', 'charoff',
43
+ 'charset', 'checked', 'cite', 'class', 'clear', 'cols', 'colspan',
44
+ 'color', 'compact', 'coords', 'datetime', 'dir', 'disabled', 'enctype',
45
+ 'for', 'frame', 'headers', 'height', 'href', 'hreflang', 'hspace', 'id',
46
+ 'ismap', 'label', 'lang', 'longdesc', 'maxlength', 'media', 'method',
47
+ 'multiple', 'name', 'nohref', 'noshade', 'nowrap', 'prompt', 'readonly',
48
+ 'rel', 'rev', 'rows', 'rowspan', 'rules', 'scope', 'selected', 'shape',
49
+ 'size', 'span', 'src', 'start', 'summary', 'tabindex', 'target', 'title',
50
+ 'type', 'usemap', 'valign', 'value', 'vspace', 'width'])
51
+
52
+ # From http://htmlhelp.com/reference/html40/olist.html
53
+ top_level_tags = frozenset([
54
+ 'html', 'head', 'body', 'frameset',
55
+ ])
56
+
57
+ head_tags = frozenset([
58
+ 'base', 'isindex', 'link', 'meta', 'script', 'style', 'title',
59
+ ])
60
+
61
+ general_block_tags = frozenset([
62
+ 'address',
63
+ 'blockquote',
64
+ 'center',
65
+ 'del',
66
+ 'div',
67
+ 'h1',
68
+ 'h2',
69
+ 'h3',
70
+ 'h4',
71
+ 'h5',
72
+ 'h6',
73
+ 'hr',
74
+ 'ins',
75
+ 'isindex',
76
+ 'noscript',
77
+ 'p',
78
+ 'pre',
79
+ ])
80
+
81
+ list_tags = frozenset([
82
+ 'dir', 'dl', 'dt', 'dd', 'li', 'menu', 'ol', 'ul',
83
+ ])
84
+
85
+ table_tags = frozenset([
86
+ 'table', 'caption', 'colgroup', 'col',
87
+ 'thead', 'tfoot', 'tbody', 'tr', 'td', 'th',
88
+ ])
89
+
90
+ # just this one from
91
+ # http://www.georgehernandez.com/h/XComputers/HTML/2BlockLevel.htm
92
+ block_tags = general_block_tags | list_tags | table_tags | frozenset([
93
+ # Partial form tags
94
+ 'fieldset', 'form', 'legend', 'optgroup', 'option',
95
+ ])
96
+
97
+ form_tags = frozenset([
98
+ 'form', 'button', 'fieldset', 'legend', 'input', 'label',
99
+ 'select', 'optgroup', 'option', 'textarea',
100
+ ])
101
+
102
+ special_inline_tags = frozenset([
103
+ 'a', 'applet', 'basefont', 'bdo', 'br', 'embed', 'font', 'iframe',
104
+ 'img', 'map', 'area', 'object', 'param', 'q', 'script',
105
+ 'span', 'sub', 'sup',
106
+ ])
107
+
108
+ phrase_tags = frozenset([
109
+ 'abbr', 'acronym', 'cite', 'code', 'del', 'dfn', 'em',
110
+ 'ins', 'kbd', 'samp', 'strong', 'var',
111
+ ])
112
+
113
+ font_style_tags = frozenset([
114
+ 'b', 'big', 'i', 's', 'small', 'strike', 'tt', 'u',
115
+ ])
116
+
117
+ frame_tags = frozenset([
118
+ 'frameset', 'frame', 'noframes',
119
+ ])
120
+
121
+ html5_tags = frozenset([
122
+ 'article', 'aside', 'audio', 'canvas', 'command', 'datalist',
123
+ 'details', 'embed', 'figcaption', 'figure', 'footer', 'header',
124
+ 'hgroup', 'keygen', 'mark', 'math', 'meter', 'nav', 'output',
125
+ 'progress', 'rp', 'rt', 'ruby', 'section', 'source', 'summary',
126
+ 'svg', 'time', 'track', 'video', 'wbr'
127
+ ])
128
+
129
+ # These tags aren't standard
130
+ nonstandard_tags = frozenset(['blink', 'marquee'])
131
+
132
+
133
+ tags = (top_level_tags | head_tags | general_block_tags | list_tags
134
+ | table_tags | form_tags | special_inline_tags | phrase_tags
135
+ | font_style_tags | nonstandard_tags | html5_tags)
venv/lib/python3.10/site-packages/lxml/html/diff.cpython-310-x86_64-linux-gnu.so ADDED
Binary file (373 kB). View file
 
venv/lib/python3.10/site-packages/lxml/html/diff.py ADDED
@@ -0,0 +1,878 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # cython: language_level=3
2
+
3
+
4
+ import difflib
5
+ from lxml import etree
6
+ from lxml.html import fragment_fromstring
7
+ import re
8
+
9
+ __all__ = ['html_annotate', 'htmldiff']
10
+
11
+ try:
12
+ from html import escape as html_escape
13
+ except ImportError:
14
+ from cgi import escape as html_escape
15
+ try:
16
+ _unicode = unicode
17
+ except NameError:
18
+ # Python 3
19
+ _unicode = str
20
+ try:
21
+ basestring
22
+ except NameError:
23
+ # Python 3
24
+ basestring = str
25
+
26
+ ############################################################
27
+ ## Annotation
28
+ ############################################################
29
+
30
+ def default_markup(text, version):
31
+ return '<span title="%s">%s</span>' % (
32
+ html_escape(_unicode(version), 1), text)
33
+
34
+ def html_annotate(doclist, markup=default_markup):
35
+ """
36
+ doclist should be ordered from oldest to newest, like::
37
+
38
+ >>> version1 = 'Hello World'
39
+ >>> version2 = 'Goodbye World'
40
+ >>> print(html_annotate([(version1, 'version 1'),
41
+ ... (version2, 'version 2')]))
42
+ <span title="version 2">Goodbye</span> <span title="version 1">World</span>
43
+
44
+ The documents must be *fragments* (str/UTF8 or unicode), not
45
+ complete documents
46
+
47
+ The markup argument is a function to markup the spans of words.
48
+ This function is called like markup('Hello', 'version 2'), and
49
+ returns HTML. The first argument is text and never includes any
50
+ markup. The default uses a span with a title:
51
+
52
+ >>> print(default_markup('Some Text', 'by Joe'))
53
+ <span title="by Joe">Some Text</span>
54
+ """
55
+ # The basic strategy we have is to split the documents up into
56
+ # logical tokens (which are words with attached markup). We then
57
+ # do diffs of each of the versions to track when a token first
58
+ # appeared in the document; the annotation attached to the token
59
+ # is the version where it first appeared.
60
+ tokenlist = [tokenize_annotated(doc, version)
61
+ for doc, version in doclist]
62
+ cur_tokens = tokenlist[0]
63
+ for tokens in tokenlist[1:]:
64
+ html_annotate_merge_annotations(cur_tokens, tokens)
65
+ cur_tokens = tokens
66
+
67
+ # After we've tracked all the tokens, we can combine spans of text
68
+ # that are adjacent and have the same annotation
69
+ cur_tokens = compress_tokens(cur_tokens)
70
+ # And finally add markup
71
+ result = markup_serialize_tokens(cur_tokens, markup)
72
+ return ''.join(result).strip()
73
+
74
+ def tokenize_annotated(doc, annotation):
75
+ """Tokenize a document and add an annotation attribute to each token
76
+ """
77
+ tokens = tokenize(doc, include_hrefs=False)
78
+ for tok in tokens:
79
+ tok.annotation = annotation
80
+ return tokens
81
+
82
+ def html_annotate_merge_annotations(tokens_old, tokens_new):
83
+ """Merge the annotations from tokens_old into tokens_new, when the
84
+ tokens in the new document already existed in the old document.
85
+ """
86
+ s = InsensitiveSequenceMatcher(a=tokens_old, b=tokens_new)
87
+ commands = s.get_opcodes()
88
+
89
+ for command, i1, i2, j1, j2 in commands:
90
+ if command == 'equal':
91
+ eq_old = tokens_old[i1:i2]
92
+ eq_new = tokens_new[j1:j2]
93
+ copy_annotations(eq_old, eq_new)
94
+
95
+ def copy_annotations(src, dest):
96
+ """
97
+ Copy annotations from the tokens listed in src to the tokens in dest
98
+ """
99
+ assert len(src) == len(dest)
100
+ for src_tok, dest_tok in zip(src, dest):
101
+ dest_tok.annotation = src_tok.annotation
102
+
103
+ def compress_tokens(tokens):
104
+ """
105
+ Combine adjacent tokens when there is no HTML between the tokens,
106
+ and they share an annotation
107
+ """
108
+ result = [tokens[0]]
109
+ for tok in tokens[1:]:
110
+ if (not result[-1].post_tags and
111
+ not tok.pre_tags and
112
+ result[-1].annotation == tok.annotation):
113
+ compress_merge_back(result, tok)
114
+ else:
115
+ result.append(tok)
116
+ return result
117
+
118
+ def compress_merge_back(tokens, tok):
119
+ """ Merge tok into the last element of tokens (modifying the list of
120
+ tokens in-place). """
121
+ last = tokens[-1]
122
+ if type(last) is not token or type(tok) is not token:
123
+ tokens.append(tok)
124
+ else:
125
+ text = _unicode(last)
126
+ if last.trailing_whitespace:
127
+ text += last.trailing_whitespace
128
+ text += tok
129
+ merged = token(text,
130
+ pre_tags=last.pre_tags,
131
+ post_tags=tok.post_tags,
132
+ trailing_whitespace=tok.trailing_whitespace)
133
+ merged.annotation = last.annotation
134
+ tokens[-1] = merged
135
+
136
+ def markup_serialize_tokens(tokens, markup_func):
137
+ """
138
+ Serialize the list of tokens into a list of text chunks, calling
139
+ markup_func around text to add annotations.
140
+ """
141
+ for token in tokens:
142
+ yield from token.pre_tags
143
+ html = token.html()
144
+ html = markup_func(html, token.annotation)
145
+ if token.trailing_whitespace:
146
+ html += token.trailing_whitespace
147
+ yield html
148
+ yield from token.post_tags
149
+
150
+
151
+ ############################################################
152
+ ## HTML Diffs
153
+ ############################################################
154
+
155
+ def htmldiff(old_html, new_html):
156
+ ## FIXME: this should take parsed documents too, and use their body
157
+ ## or other content.
158
+ """ Do a diff of the old and new document. The documents are HTML
159
+ *fragments* (str/UTF8 or unicode), they are not complete documents
160
+ (i.e., no <html> tag).
161
+
162
+ Returns HTML with <ins> and <del> tags added around the
163
+ appropriate text.
164
+
165
+ Markup is generally ignored, with the markup from new_html
166
+ preserved, and possibly some markup from old_html (though it is
167
+ considered acceptable to lose some of the old markup). Only the
168
+ words in the HTML are diffed. The exception is <img> tags, which
169
+ are treated like words, and the href attribute of <a> tags, which
170
+ are noted inside the tag itself when there are changes.
171
+ """
172
+ old_html_tokens = tokenize(old_html)
173
+ new_html_tokens = tokenize(new_html)
174
+ result = htmldiff_tokens(old_html_tokens, new_html_tokens)
175
+ result = ''.join(result).strip()
176
+ return fixup_ins_del_tags(result)
177
+
178
+ def htmldiff_tokens(html1_tokens, html2_tokens):
179
+ """ Does a diff on the tokens themselves, returning a list of text
180
+ chunks (not tokens).
181
+ """
182
+ # There are several passes as we do the differences. The tokens
183
+ # isolate the portion of the content we care to diff; difflib does
184
+ # all the actual hard work at that point.
185
+ #
186
+ # Then we must create a valid document from pieces of both the old
187
+ # document and the new document. We generally prefer to take
188
+ # markup from the new document, and only do a best effort attempt
189
+ # to keep markup from the old document; anything that we can't
190
+ # resolve we throw away. Also we try to put the deletes as close
191
+ # to the location where we think they would have been -- because
192
+ # we are only keeping the markup from the new document, it can be
193
+ # fuzzy where in the new document the old text would have gone.
194
+ # Again we just do a best effort attempt.
195
+ s = InsensitiveSequenceMatcher(a=html1_tokens, b=html2_tokens)
196
+ commands = s.get_opcodes()
197
+ result = []
198
+ for command, i1, i2, j1, j2 in commands:
199
+ if command == 'equal':
200
+ result.extend(expand_tokens(html2_tokens[j1:j2], equal=True))
201
+ continue
202
+ if command == 'insert' or command == 'replace':
203
+ ins_tokens = expand_tokens(html2_tokens[j1:j2])
204
+ merge_insert(ins_tokens, result)
205
+ if command == 'delete' or command == 'replace':
206
+ del_tokens = expand_tokens(html1_tokens[i1:i2])
207
+ merge_delete(del_tokens, result)
208
+ # If deletes were inserted directly as <del> then we'd have an
209
+ # invalid document at this point. Instead we put in special
210
+ # markers, and when the complete diffed document has been created
211
+ # we try to move the deletes around and resolve any problems.
212
+ result = cleanup_delete(result)
213
+
214
+ return result
215
+
216
+ def expand_tokens(tokens, equal=False):
217
+ """Given a list of tokens, return a generator of the chunks of
218
+ text for the data in the tokens.
219
+ """
220
+ for token in tokens:
221
+ yield from token.pre_tags
222
+ if not equal or not token.hide_when_equal:
223
+ if token.trailing_whitespace:
224
+ yield token.html() + token.trailing_whitespace
225
+ else:
226
+ yield token.html()
227
+ yield from token.post_tags
228
+
229
+ def merge_insert(ins_chunks, doc):
230
+ """ doc is the already-handled document (as a list of text chunks);
231
+ here we add <ins>ins_chunks</ins> to the end of that. """
232
+ # Though we don't throw away unbalanced_start or unbalanced_end
233
+ # (we assume there is accompanying markup later or earlier in the
234
+ # document), we only put <ins> around the balanced portion.
235
+ unbalanced_start, balanced, unbalanced_end = split_unbalanced(ins_chunks)
236
+ doc.extend(unbalanced_start)
237
+ if doc and not doc[-1].endswith(' '):
238
+ # Fix up the case where the word before the insert didn't end with
239
+ # a space
240
+ doc[-1] += ' '
241
+ doc.append('<ins>')
242
+ if balanced and balanced[-1].endswith(' '):
243
+ # We move space outside of </ins>
244
+ balanced[-1] = balanced[-1][:-1]
245
+ doc.extend(balanced)
246
+ doc.append('</ins> ')
247
+ doc.extend(unbalanced_end)
248
+
249
+ # These are sentinels to represent the start and end of a <del>
250
+ # segment, until we do the cleanup phase to turn them into proper
251
+ # markup:
252
+ class DEL_START:
253
+ pass
254
+ class DEL_END:
255
+ pass
256
+
257
+ class NoDeletes(Exception):
258
+ """ Raised when the document no longer contains any pending deletes
259
+ (DEL_START/DEL_END) """
260
+
261
+ def merge_delete(del_chunks, doc):
262
+ """ Adds the text chunks in del_chunks to the document doc (another
263
+ list of text chunks) with marker to show it is a delete.
264
+ cleanup_delete later resolves these markers into <del> tags."""
265
+ doc.append(DEL_START)
266
+ doc.extend(del_chunks)
267
+ doc.append(DEL_END)
268
+
269
+ def cleanup_delete(chunks):
270
+ """ Cleans up any DEL_START/DEL_END markers in the document, replacing
271
+ them with <del></del>. To do this while keeping the document
272
+ valid, it may need to drop some tags (either start or end tags).
273
+
274
+ It may also move the del into adjacent tags to try to move it to a
275
+ similar location where it was originally located (e.g., moving a
276
+ delete into preceding <div> tag, if the del looks like (DEL_START,
277
+ 'Text</div>', DEL_END)"""
278
+ while 1:
279
+ # Find a pending DEL_START/DEL_END, splitting the document
280
+ # into stuff-preceding-DEL_START, stuff-inside, and
281
+ # stuff-following-DEL_END
282
+ try:
283
+ pre_delete, delete, post_delete = split_delete(chunks)
284
+ except NoDeletes:
285
+ # Nothing found, we've cleaned up the entire doc
286
+ break
287
+ # The stuff-inside-DEL_START/END may not be well balanced
288
+ # markup. First we figure out what unbalanced portions there are:
289
+ unbalanced_start, balanced, unbalanced_end = split_unbalanced(delete)
290
+ # Then we move the span forward and/or backward based on these
291
+ # unbalanced portions:
292
+ locate_unbalanced_start(unbalanced_start, pre_delete, post_delete)
293
+ locate_unbalanced_end(unbalanced_end, pre_delete, post_delete)
294
+ doc = pre_delete
295
+ if doc and not doc[-1].endswith(' '):
296
+ # Fix up case where the word before us didn't have a trailing space
297
+ doc[-1] += ' '
298
+ doc.append('<del>')
299
+ if balanced and balanced[-1].endswith(' '):
300
+ # We move space outside of </del>
301
+ balanced[-1] = balanced[-1][:-1]
302
+ doc.extend(balanced)
303
+ doc.append('</del> ')
304
+ doc.extend(post_delete)
305
+ chunks = doc
306
+ return chunks
307
+
308
+ def split_unbalanced(chunks):
309
+ """Return (unbalanced_start, balanced, unbalanced_end), where each is
310
+ a list of text and tag chunks.
311
+
312
+ unbalanced_start is a list of all the tags that are opened, but
313
+ not closed in this span. Similarly, unbalanced_end is a list of
314
+ tags that are closed but were not opened. Extracting these might
315
+ mean some reordering of the chunks."""
316
+ start = []
317
+ end = []
318
+ tag_stack = []
319
+ balanced = []
320
+ for chunk in chunks:
321
+ if not chunk.startswith('<'):
322
+ balanced.append(chunk)
323
+ continue
324
+ endtag = chunk[1] == '/'
325
+ name = chunk.split()[0].strip('<>/')
326
+ if name in empty_tags:
327
+ balanced.append(chunk)
328
+ continue
329
+ if endtag:
330
+ if tag_stack and tag_stack[-1][0] == name:
331
+ balanced.append(chunk)
332
+ name, pos, tag = tag_stack.pop()
333
+ balanced[pos] = tag
334
+ elif tag_stack:
335
+ start.extend([tag for name, pos, tag in tag_stack])
336
+ tag_stack = []
337
+ end.append(chunk)
338
+ else:
339
+ end.append(chunk)
340
+ else:
341
+ tag_stack.append((name, len(balanced), chunk))
342
+ balanced.append(None)
343
+ start.extend(
344
+ [chunk for name, pos, chunk in tag_stack])
345
+ balanced = [chunk for chunk in balanced if chunk is not None]
346
+ return start, balanced, end
347
+
348
+ def split_delete(chunks):
349
+ """ Returns (stuff_before_DEL_START, stuff_inside_DEL_START_END,
350
+ stuff_after_DEL_END). Returns the first case found (there may be
351
+ more DEL_STARTs in stuff_after_DEL_END). Raises NoDeletes if
352
+ there's no DEL_START found. """
353
+ try:
354
+ pos = chunks.index(DEL_START)
355
+ except ValueError:
356
+ raise NoDeletes
357
+ pos2 = chunks.index(DEL_END)
358
+ return chunks[:pos], chunks[pos+1:pos2], chunks[pos2+1:]
359
+
360
+ def locate_unbalanced_start(unbalanced_start, pre_delete, post_delete):
361
+ """ pre_delete and post_delete implicitly point to a place in the
362
+ document (where the two were split). This moves that point (by
363
+ popping items from one and pushing them onto the other). It moves
364
+ the point to try to find a place where unbalanced_start applies.
365
+
366
+ As an example::
367
+
368
+ >>> unbalanced_start = ['<div>']
369
+ >>> doc = ['<p>', 'Text', '</p>', '<div>', 'More Text', '</div>']
370
+ >>> pre, post = doc[:3], doc[3:]
371
+ >>> pre, post
372
+ (['<p>', 'Text', '</p>'], ['<div>', 'More Text', '</div>'])
373
+ >>> locate_unbalanced_start(unbalanced_start, pre, post)
374
+ >>> pre, post
375
+ (['<p>', 'Text', '</p>', '<div>'], ['More Text', '</div>'])
376
+
377
+ As you can see, we moved the point so that the dangling <div> that
378
+ we found will be effectively replaced by the div in the original
379
+ document. If this doesn't work out, we just throw away
380
+ unbalanced_start without doing anything.
381
+ """
382
+ while 1:
383
+ if not unbalanced_start:
384
+ # We have totally succeeded in finding the position
385
+ break
386
+ finding = unbalanced_start[0]
387
+ finding_name = finding.split()[0].strip('<>')
388
+ if not post_delete:
389
+ break
390
+ next = post_delete[0]
391
+ if next is DEL_START or not next.startswith('<'):
392
+ # Reached a word, we can't move the delete text forward
393
+ break
394
+ if next[1] == '/':
395
+ # Reached a closing tag, can we go further? Maybe not...
396
+ break
397
+ name = next.split()[0].strip('<>')
398
+ if name == 'ins':
399
+ # Can't move into an insert
400
+ break
401
+ assert name != 'del', (
402
+ "Unexpected delete tag: %r" % next)
403
+ if name == finding_name:
404
+ unbalanced_start.pop(0)
405
+ pre_delete.append(post_delete.pop(0))
406
+ else:
407
+ # Found a tag that doesn't match
408
+ break
409
+
410
+ def locate_unbalanced_end(unbalanced_end, pre_delete, post_delete):
411
+ """ like locate_unbalanced_start, except handling end tags and
412
+ possibly moving the point earlier in the document. """
413
+ while 1:
414
+ if not unbalanced_end:
415
+ # Success
416
+ break
417
+ finding = unbalanced_end[-1]
418
+ finding_name = finding.split()[0].strip('<>/')
419
+ if not pre_delete:
420
+ break
421
+ next = pre_delete[-1]
422
+ if next is DEL_END or not next.startswith('</'):
423
+ # A word or a start tag
424
+ break
425
+ name = next.split()[0].strip('<>/')
426
+ if name == 'ins' or name == 'del':
427
+ # Can't move into an insert or delete
428
+ break
429
+ if name == finding_name:
430
+ unbalanced_end.pop()
431
+ post_delete.insert(0, pre_delete.pop())
432
+ else:
433
+ # Found a tag that doesn't match
434
+ break
435
+
436
+ class token(_unicode):
437
+ """ Represents a diffable token, generally a word that is displayed to
438
+ the user. Opening tags are attached to this token when they are
439
+ adjacent (pre_tags) and closing tags that follow the word
440
+ (post_tags). Some exceptions occur when there are empty tags
441
+ adjacent to a word, so there may be close tags in pre_tags, or
442
+ open tags in post_tags.
443
+
444
+ We also keep track of whether the word was originally followed by
445
+ whitespace, even though we do not want to treat the word as
446
+ equivalent to a similar word that does not have a trailing
447
+ space."""
448
+
449
+ # When this is true, the token will be eliminated from the
450
+ # displayed diff if no change has occurred:
451
+ hide_when_equal = False
452
+
453
+ def __new__(cls, text, pre_tags=None, post_tags=None, trailing_whitespace=""):
454
+ obj = _unicode.__new__(cls, text)
455
+
456
+ if pre_tags is not None:
457
+ obj.pre_tags = pre_tags
458
+ else:
459
+ obj.pre_tags = []
460
+
461
+ if post_tags is not None:
462
+ obj.post_tags = post_tags
463
+ else:
464
+ obj.post_tags = []
465
+
466
+ obj.trailing_whitespace = trailing_whitespace
467
+
468
+ return obj
469
+
470
+ def __repr__(self):
471
+ return 'token(%s, %r, %r, %r)' % (_unicode.__repr__(self), self.pre_tags,
472
+ self.post_tags, self.trailing_whitespace)
473
+
474
+ def html(self):
475
+ return _unicode(self)
476
+
477
+ class tag_token(token):
478
+
479
+ """ Represents a token that is actually a tag. Currently this is just
480
+ the <img> tag, which takes up visible space just like a word but
481
+ is only represented in a document by a tag. """
482
+
483
+ def __new__(cls, tag, data, html_repr, pre_tags=None,
484
+ post_tags=None, trailing_whitespace=""):
485
+ obj = token.__new__(cls, "%s: %s" % (type, data),
486
+ pre_tags=pre_tags,
487
+ post_tags=post_tags,
488
+ trailing_whitespace=trailing_whitespace)
489
+ obj.tag = tag
490
+ obj.data = data
491
+ obj.html_repr = html_repr
492
+ return obj
493
+
494
+ def __repr__(self):
495
+ return 'tag_token(%s, %s, html_repr=%s, post_tags=%r, pre_tags=%r, trailing_whitespace=%r)' % (
496
+ self.tag,
497
+ self.data,
498
+ self.html_repr,
499
+ self.pre_tags,
500
+ self.post_tags,
501
+ self.trailing_whitespace)
502
+ def html(self):
503
+ return self.html_repr
504
+
505
+ class href_token(token):
506
+
507
+ """ Represents the href in an anchor tag. Unlike other words, we only
508
+ show the href when it changes. """
509
+
510
+ hide_when_equal = True
511
+
512
+ def html(self):
513
+ return ' Link: %s' % self
514
+
515
+ def tokenize(html, include_hrefs=True):
516
+ """
517
+ Parse the given HTML and returns token objects (words with attached tags).
518
+
519
+ This parses only the content of a page; anything in the head is
520
+ ignored, and the <head> and <body> elements are themselves
521
+ optional. The content is then parsed by lxml, which ensures the
522
+ validity of the resulting parsed document (though lxml may make
523
+ incorrect guesses when the markup is particular bad).
524
+
525
+ <ins> and <del> tags are also eliminated from the document, as
526
+ that gets confusing.
527
+
528
+ If include_hrefs is true, then the href attribute of <a> tags is
529
+ included as a special kind of diffable token."""
530
+ if etree.iselement(html):
531
+ body_el = html
532
+ else:
533
+ body_el = parse_html(html, cleanup=True)
534
+ # Then we split the document into text chunks for each tag, word, and end tag:
535
+ chunks = flatten_el(body_el, skip_tag=True, include_hrefs=include_hrefs)
536
+ # Finally re-joining them into token objects:
537
+ return fixup_chunks(chunks)
538
+
539
+ def parse_html(html, cleanup=True):
540
+ """
541
+ Parses an HTML fragment, returning an lxml element. Note that the HTML will be
542
+ wrapped in a <div> tag that was not in the original document.
543
+
544
+ If cleanup is true, make sure there's no <head> or <body>, and get
545
+ rid of any <ins> and <del> tags.
546
+ """
547
+ if cleanup:
548
+ # This removes any extra markup or structure like <head>:
549
+ html = cleanup_html(html)
550
+ return fragment_fromstring(html, create_parent=True)
551
+
552
+ _body_re = re.compile(r'<body.*?>', re.I|re.S)
553
+ _end_body_re = re.compile(r'</body.*?>', re.I|re.S)
554
+ _ins_del_re = re.compile(r'</?(ins|del).*?>', re.I|re.S)
555
+
556
+ def cleanup_html(html):
557
+ """ This 'cleans' the HTML, meaning that any page structure is removed
558
+ (only the contents of <body> are used, if there is any <body).
559
+ Also <ins> and <del> tags are removed. """
560
+ match = _body_re.search(html)
561
+ if match:
562
+ html = html[match.end():]
563
+ match = _end_body_re.search(html)
564
+ if match:
565
+ html = html[:match.start()]
566
+ html = _ins_del_re.sub('', html)
567
+ return html
568
+
569
+
570
+ end_whitespace_re = re.compile(r'[ \t\n\r]$')
571
+
572
+ def split_trailing_whitespace(word):
573
+ """
574
+ This function takes a word, such as 'test\n\n' and returns ('test','\n\n')
575
+ """
576
+ stripped_length = len(word.rstrip())
577
+ return word[0:stripped_length], word[stripped_length:]
578
+
579
+
580
+ def fixup_chunks(chunks):
581
+ """
582
+ This function takes a list of chunks and produces a list of tokens.
583
+ """
584
+ tag_accum = []
585
+ cur_word = None
586
+ result = []
587
+ for chunk in chunks:
588
+ if isinstance(chunk, tuple):
589
+ if chunk[0] == 'img':
590
+ src = chunk[1]
591
+ tag, trailing_whitespace = split_trailing_whitespace(chunk[2])
592
+ cur_word = tag_token('img', src, html_repr=tag,
593
+ pre_tags=tag_accum,
594
+ trailing_whitespace=trailing_whitespace)
595
+ tag_accum = []
596
+ result.append(cur_word)
597
+
598
+ elif chunk[0] == 'href':
599
+ href = chunk[1]
600
+ cur_word = href_token(href, pre_tags=tag_accum, trailing_whitespace=" ")
601
+ tag_accum = []
602
+ result.append(cur_word)
603
+ continue
604
+
605
+ if is_word(chunk):
606
+ chunk, trailing_whitespace = split_trailing_whitespace(chunk)
607
+ cur_word = token(chunk, pre_tags=tag_accum, trailing_whitespace=trailing_whitespace)
608
+ tag_accum = []
609
+ result.append(cur_word)
610
+
611
+ elif is_start_tag(chunk):
612
+ tag_accum.append(chunk)
613
+
614
+ elif is_end_tag(chunk):
615
+ if tag_accum:
616
+ tag_accum.append(chunk)
617
+ else:
618
+ assert cur_word, (
619
+ "Weird state, cur_word=%r, result=%r, chunks=%r of %r"
620
+ % (cur_word, result, chunk, chunks))
621
+ cur_word.post_tags.append(chunk)
622
+ else:
623
+ assert False
624
+
625
+ if not result:
626
+ return [token('', pre_tags=tag_accum)]
627
+ else:
628
+ result[-1].post_tags.extend(tag_accum)
629
+
630
+ return result
631
+
632
+
633
+ # All the tags in HTML that don't require end tags:
634
+ empty_tags = (
635
+ 'param', 'img', 'area', 'br', 'basefont', 'input',
636
+ 'base', 'meta', 'link', 'col')
637
+
638
+ block_level_tags = (
639
+ 'address',
640
+ 'blockquote',
641
+ 'center',
642
+ 'dir',
643
+ 'div',
644
+ 'dl',
645
+ 'fieldset',
646
+ 'form',
647
+ 'h1',
648
+ 'h2',
649
+ 'h3',
650
+ 'h4',
651
+ 'h5',
652
+ 'h6',
653
+ 'hr',
654
+ 'isindex',
655
+ 'menu',
656
+ 'noframes',
657
+ 'noscript',
658
+ 'ol',
659
+ 'p',
660
+ 'pre',
661
+ 'table',
662
+ 'ul',
663
+ )
664
+
665
+ block_level_container_tags = (
666
+ 'dd',
667
+ 'dt',
668
+ 'frameset',
669
+ 'li',
670
+ 'tbody',
671
+ 'td',
672
+ 'tfoot',
673
+ 'th',
674
+ 'thead',
675
+ 'tr',
676
+ )
677
+
678
+
679
+ def flatten_el(el, include_hrefs, skip_tag=False):
680
+ """ Takes an lxml element el, and generates all the text chunks for
681
+ that tag. Each start tag is a chunk, each word is a chunk, and each
682
+ end tag is a chunk.
683
+
684
+ If skip_tag is true, then the outermost container tag is
685
+ not returned (just its contents)."""
686
+ if not skip_tag:
687
+ if el.tag == 'img':
688
+ yield ('img', el.get('src'), start_tag(el))
689
+ else:
690
+ yield start_tag(el)
691
+ if el.tag in empty_tags and not el.text and not len(el) and not el.tail:
692
+ return
693
+ start_words = split_words(el.text)
694
+ for word in start_words:
695
+ yield html_escape(word)
696
+ for child in el:
697
+ yield from flatten_el(child, include_hrefs=include_hrefs)
698
+ if el.tag == 'a' and el.get('href') and include_hrefs:
699
+ yield ('href', el.get('href'))
700
+ if not skip_tag:
701
+ yield end_tag(el)
702
+ end_words = split_words(el.tail)
703
+ for word in end_words:
704
+ yield html_escape(word)
705
+
706
+ split_words_re = re.compile(r'\S+(?:\s+|$)', re.U)
707
+
708
+ def split_words(text):
709
+ """ Splits some text into words. Includes trailing whitespace
710
+ on each word when appropriate. """
711
+ if not text or not text.strip():
712
+ return []
713
+
714
+ words = split_words_re.findall(text)
715
+ return words
716
+
717
+ start_whitespace_re = re.compile(r'^[ \t\n\r]')
718
+
719
+ def start_tag(el):
720
+ """
721
+ The text representation of the start tag for a tag.
722
+ """
723
+ return '<%s%s>' % (
724
+ el.tag, ''.join([' %s="%s"' % (name, html_escape(value, True))
725
+ for name, value in el.attrib.items()]))
726
+
727
+ def end_tag(el):
728
+ """ The text representation of an end tag for a tag. Includes
729
+ trailing whitespace when appropriate. """
730
+ if el.tail and start_whitespace_re.search(el.tail):
731
+ extra = ' '
732
+ else:
733
+ extra = ''
734
+ return '</%s>%s' % (el.tag, extra)
735
+
736
+ def is_word(tok):
737
+ return not tok.startswith('<')
738
+
739
+ def is_end_tag(tok):
740
+ return tok.startswith('</')
741
+
742
+ def is_start_tag(tok):
743
+ return tok.startswith('<') and not tok.startswith('</')
744
+
745
+ def fixup_ins_del_tags(html):
746
+ """ Given an html string, move any <ins> or <del> tags inside of any
747
+ block-level elements, e.g. transform <ins><p>word</p></ins> to
748
+ <p><ins>word</ins></p> """
749
+ doc = parse_html(html, cleanup=False)
750
+ _fixup_ins_del_tags(doc)
751
+ html = serialize_html_fragment(doc, skip_outer=True)
752
+ return html
753
+
754
+ def serialize_html_fragment(el, skip_outer=False):
755
+ """ Serialize a single lxml element as HTML. The serialized form
756
+ includes the elements tail.
757
+
758
+ If skip_outer is true, then don't serialize the outermost tag
759
+ """
760
+ assert not isinstance(el, basestring), (
761
+ "You should pass in an element, not a string like %r" % el)
762
+ html = etree.tostring(el, method="html", encoding=_unicode)
763
+ if skip_outer:
764
+ # Get rid of the extra starting tag:
765
+ html = html[html.find('>')+1:]
766
+ # Get rid of the extra end tag:
767
+ html = html[:html.rfind('<')]
768
+ return html.strip()
769
+ else:
770
+ return html
771
+
772
+ def _fixup_ins_del_tags(doc):
773
+ """fixup_ins_del_tags that works on an lxml document in-place
774
+ """
775
+ for tag in ['ins', 'del']:
776
+ for el in doc.xpath('descendant-or-self::%s' % tag):
777
+ if not _contains_block_level_tag(el):
778
+ continue
779
+ _move_el_inside_block(el, tag=tag)
780
+ el.drop_tag()
781
+ #_merge_element_contents(el)
782
+
783
+ def _contains_block_level_tag(el):
784
+ """True if the element contains any block-level elements, like <p>, <td>, etc.
785
+ """
786
+ if el.tag in block_level_tags or el.tag in block_level_container_tags:
787
+ return True
788
+ for child in el:
789
+ if _contains_block_level_tag(child):
790
+ return True
791
+ return False
792
+
793
+ def _move_el_inside_block(el, tag):
794
+ """ helper for _fixup_ins_del_tags; actually takes the <ins> etc tags
795
+ and moves them inside any block-level tags. """
796
+ for child in el:
797
+ if _contains_block_level_tag(child):
798
+ break
799
+ else:
800
+ # No block-level tags in any child
801
+ children_tag = etree.Element(tag)
802
+ children_tag.text = el.text
803
+ el.text = None
804
+ children_tag.extend(list(el))
805
+ el[:] = [children_tag]
806
+ return
807
+ for child in list(el):
808
+ if _contains_block_level_tag(child):
809
+ _move_el_inside_block(child, tag)
810
+ if child.tail:
811
+ tail_tag = etree.Element(tag)
812
+ tail_tag.text = child.tail
813
+ child.tail = None
814
+ el.insert(el.index(child)+1, tail_tag)
815
+ else:
816
+ child_tag = etree.Element(tag)
817
+ el.replace(child, child_tag)
818
+ child_tag.append(child)
819
+ if el.text:
820
+ text_tag = etree.Element(tag)
821
+ text_tag.text = el.text
822
+ el.text = None
823
+ el.insert(0, text_tag)
824
+
825
+ def _merge_element_contents(el):
826
+ """
827
+ Removes an element, but merges its contents into its place, e.g.,
828
+ given <p>Hi <i>there!</i></p>, if you remove the <i> element you get
829
+ <p>Hi there!</p>
830
+ """
831
+ parent = el.getparent()
832
+ text = el.text or ''
833
+ if el.tail:
834
+ if not len(el):
835
+ text += el.tail
836
+ else:
837
+ if el[-1].tail:
838
+ el[-1].tail += el.tail
839
+ else:
840
+ el[-1].tail = el.tail
841
+ index = parent.index(el)
842
+ if text:
843
+ if index == 0:
844
+ previous = None
845
+ else:
846
+ previous = parent[index-1]
847
+ if previous is None:
848
+ if parent.text:
849
+ parent.text += text
850
+ else:
851
+ parent.text = text
852
+ else:
853
+ if previous.tail:
854
+ previous.tail += text
855
+ else:
856
+ previous.tail = text
857
+ parent[index:index+1] = el.getchildren()
858
+
859
+ class InsensitiveSequenceMatcher(difflib.SequenceMatcher):
860
+ """
861
+ Acts like SequenceMatcher, but tries not to find very small equal
862
+ blocks amidst large spans of changes
863
+ """
864
+
865
+ threshold = 2
866
+
867
+ def get_matching_blocks(self):
868
+ size = min(len(self.b), len(self.b))
869
+ threshold = min(self.threshold, size / 4)
870
+ actual = difflib.SequenceMatcher.get_matching_blocks(self)
871
+ return [item for item in actual
872
+ if item[2] > threshold
873
+ or not item[2]]
874
+
875
+ if __name__ == '__main__':
876
+ from lxml.html import _diffcommand
877
+ _diffcommand.main()
878
+
venv/lib/python3.10/site-packages/lxml/html/formfill.py ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from lxml.etree import XPath, ElementBase
2
+ from lxml.html import fromstring, XHTML_NAMESPACE
3
+ from lxml.html import _forms_xpath, _options_xpath, _nons, _transform_result
4
+ from lxml.html import defs
5
+ import copy
6
+
7
+ try:
8
+ basestring
9
+ except NameError:
10
+ # Python 3
11
+ basestring = str
12
+
13
+ __all__ = ['FormNotFound', 'fill_form', 'fill_form_html',
14
+ 'insert_errors', 'insert_errors_html',
15
+ 'DefaultErrorCreator']
16
+
17
+ class FormNotFound(LookupError):
18
+ """
19
+ Raised when no form can be found
20
+ """
21
+
22
+ _form_name_xpath = XPath('descendant-or-self::form[name=$name]|descendant-or-self::x:form[name=$name]', namespaces={'x':XHTML_NAMESPACE})
23
+ _input_xpath = XPath('|'.join(['descendant-or-self::'+_tag for _tag in ('input','select','textarea','x:input','x:select','x:textarea')]),
24
+ namespaces={'x':XHTML_NAMESPACE})
25
+ _label_for_xpath = XPath('//label[@for=$for_id]|//x:label[@for=$for_id]',
26
+ namespaces={'x':XHTML_NAMESPACE})
27
+ _name_xpath = XPath('descendant-or-self::*[@name=$name]')
28
+
29
+ def fill_form(
30
+ el,
31
+ values,
32
+ form_id=None,
33
+ form_index=None,
34
+ ):
35
+ el = _find_form(el, form_id=form_id, form_index=form_index)
36
+ _fill_form(el, values)
37
+
38
+ def fill_form_html(html, values, form_id=None, form_index=None):
39
+ result_type = type(html)
40
+ if isinstance(html, basestring):
41
+ doc = fromstring(html)
42
+ else:
43
+ doc = copy.deepcopy(html)
44
+ fill_form(doc, values, form_id=form_id, form_index=form_index)
45
+ return _transform_result(result_type, doc)
46
+
47
+ def _fill_form(el, values):
48
+ counts = {}
49
+ if hasattr(values, 'mixed'):
50
+ # For Paste request parameters
51
+ values = values.mixed()
52
+ inputs = _input_xpath(el)
53
+ for input in inputs:
54
+ name = input.get('name')
55
+ if not name:
56
+ continue
57
+ if _takes_multiple(input):
58
+ value = values.get(name, [])
59
+ if not isinstance(value, (list, tuple)):
60
+ value = [value]
61
+ _fill_multiple(input, value)
62
+ elif name not in values:
63
+ continue
64
+ else:
65
+ index = counts.get(name, 0)
66
+ counts[name] = index + 1
67
+ value = values[name]
68
+ if isinstance(value, (list, tuple)):
69
+ try:
70
+ value = value[index]
71
+ except IndexError:
72
+ continue
73
+ elif index > 0:
74
+ continue
75
+ _fill_single(input, value)
76
+
77
+ def _takes_multiple(input):
78
+ if _nons(input.tag) == 'select' and input.get('multiple'):
79
+ # FIXME: multiple="0"?
80
+ return True
81
+ type = input.get('type', '').lower()
82
+ if type in ('radio', 'checkbox'):
83
+ return True
84
+ return False
85
+
86
+ def _fill_multiple(input, value):
87
+ type = input.get('type', '').lower()
88
+ if type == 'checkbox':
89
+ v = input.get('value')
90
+ if v is None:
91
+ if not value:
92
+ result = False
93
+ else:
94
+ result = value[0]
95
+ if isinstance(value, basestring):
96
+ # The only valid "on" value for an unnamed checkbox is 'on'
97
+ result = result == 'on'
98
+ _check(input, result)
99
+ else:
100
+ _check(input, v in value)
101
+ elif type == 'radio':
102
+ v = input.get('value')
103
+ _check(input, v in value)
104
+ else:
105
+ assert _nons(input.tag) == 'select'
106
+ for option in _options_xpath(input):
107
+ v = option.get('value')
108
+ if v is None:
109
+ # This seems to be the default, at least on IE
110
+ # FIXME: but I'm not sure
111
+ v = option.text_content()
112
+ _select(option, v in value)
113
+
114
+ def _check(el, check):
115
+ if check:
116
+ el.set('checked', '')
117
+ else:
118
+ if 'checked' in el.attrib:
119
+ del el.attrib['checked']
120
+
121
+ def _select(el, select):
122
+ if select:
123
+ el.set('selected', '')
124
+ else:
125
+ if 'selected' in el.attrib:
126
+ del el.attrib['selected']
127
+
128
+ def _fill_single(input, value):
129
+ if _nons(input.tag) == 'textarea':
130
+ input.text = value
131
+ else:
132
+ input.set('value', value)
133
+
134
+ def _find_form(el, form_id=None, form_index=None):
135
+ if form_id is None and form_index is None:
136
+ forms = _forms_xpath(el)
137
+ for form in forms:
138
+ return form
139
+ raise FormNotFound(
140
+ "No forms in page")
141
+ if form_id is not None:
142
+ form = el.get_element_by_id(form_id)
143
+ if form is not None:
144
+ return form
145
+ forms = _form_name_xpath(el, name=form_id)
146
+ if forms:
147
+ return forms[0]
148
+ else:
149
+ raise FormNotFound(
150
+ "No form with the name or id of %r (forms: %s)"
151
+ % (id, ', '.join(_find_form_ids(el))))
152
+ if form_index is not None:
153
+ forms = _forms_xpath(el)
154
+ try:
155
+ return forms[form_index]
156
+ except IndexError:
157
+ raise FormNotFound(
158
+ "There is no form with the index %r (%i forms found)"
159
+ % (form_index, len(forms)))
160
+
161
+ def _find_form_ids(el):
162
+ forms = _forms_xpath(el)
163
+ if not forms:
164
+ yield '(no forms)'
165
+ return
166
+ for index, form in enumerate(forms):
167
+ if form.get('id'):
168
+ if form.get('name'):
169
+ yield '%s or %s' % (form.get('id'),
170
+ form.get('name'))
171
+ else:
172
+ yield form.get('id')
173
+ elif form.get('name'):
174
+ yield form.get('name')
175
+ else:
176
+ yield '(unnamed form %s)' % index
177
+
178
+ ############################################################
179
+ ## Error filling
180
+ ############################################################
181
+
182
+ class DefaultErrorCreator:
183
+ insert_before = True
184
+ block_inside = True
185
+ error_container_tag = 'div'
186
+ error_message_class = 'error-message'
187
+ error_block_class = 'error-block'
188
+ default_message = "Invalid"
189
+
190
+ def __init__(self, **kw):
191
+ for name, value in kw.items():
192
+ if not hasattr(self, name):
193
+ raise TypeError(
194
+ "Unexpected keyword argument: %s" % name)
195
+ setattr(self, name, value)
196
+
197
+ def __call__(self, el, is_block, message):
198
+ error_el = el.makeelement(self.error_container_tag)
199
+ if self.error_message_class:
200
+ error_el.set('class', self.error_message_class)
201
+ if is_block and self.error_block_class:
202
+ error_el.set('class', error_el.get('class', '')+' '+self.error_block_class)
203
+ if message is None or message == '':
204
+ message = self.default_message
205
+ if isinstance(message, ElementBase):
206
+ error_el.append(message)
207
+ else:
208
+ assert isinstance(message, basestring), (
209
+ "Bad message; should be a string or element: %r" % message)
210
+ error_el.text = message or self.default_message
211
+ if is_block and self.block_inside:
212
+ if self.insert_before:
213
+ error_el.tail = el.text
214
+ el.text = None
215
+ el.insert(0, error_el)
216
+ else:
217
+ el.append(error_el)
218
+ else:
219
+ parent = el.getparent()
220
+ pos = parent.index(el)
221
+ if self.insert_before:
222
+ parent.insert(pos, error_el)
223
+ else:
224
+ error_el.tail = el.tail
225
+ el.tail = None
226
+ parent.insert(pos+1, error_el)
227
+
228
+ default_error_creator = DefaultErrorCreator()
229
+
230
+
231
+ def insert_errors(
232
+ el,
233
+ errors,
234
+ form_id=None,
235
+ form_index=None,
236
+ error_class="error",
237
+ error_creator=default_error_creator,
238
+ ):
239
+ el = _find_form(el, form_id=form_id, form_index=form_index)
240
+ for name, error in errors.items():
241
+ if error is None:
242
+ continue
243
+ for error_el, message in _find_elements_for_name(el, name, error):
244
+ assert isinstance(message, (basestring, type(None), ElementBase)), (
245
+ "Bad message: %r" % message)
246
+ _insert_error(error_el, message, error_class, error_creator)
247
+
248
+ def insert_errors_html(html, values, **kw):
249
+ result_type = type(html)
250
+ if isinstance(html, basestring):
251
+ doc = fromstring(html)
252
+ else:
253
+ doc = copy.deepcopy(html)
254
+ insert_errors(doc, values, **kw)
255
+ return _transform_result(result_type, doc)
256
+
257
+ def _insert_error(el, error, error_class, error_creator):
258
+ if _nons(el.tag) in defs.empty_tags or _nons(el.tag) == 'textarea':
259
+ is_block = False
260
+ else:
261
+ is_block = True
262
+ if _nons(el.tag) != 'form' and error_class:
263
+ _add_class(el, error_class)
264
+ if el.get('id'):
265
+ labels = _label_for_xpath(el, for_id=el.get('id'))
266
+ if labels:
267
+ for label in labels:
268
+ _add_class(label, error_class)
269
+ error_creator(el, is_block, error)
270
+
271
+ def _add_class(el, class_name):
272
+ if el.get('class'):
273
+ el.set('class', el.get('class')+' '+class_name)
274
+ else:
275
+ el.set('class', class_name)
276
+
277
+ def _find_elements_for_name(form, name, error):
278
+ if name is None:
279
+ # An error for the entire form
280
+ yield form, error
281
+ return
282
+ if name.startswith('#'):
283
+ # By id
284
+ el = form.get_element_by_id(name[1:])
285
+ if el is not None:
286
+ yield el, error
287
+ return
288
+ els = _name_xpath(form, name=name)
289
+ if not els:
290
+ # FIXME: should this raise an exception?
291
+ return
292
+ if not isinstance(error, (list, tuple)):
293
+ yield els[0], error
294
+ return
295
+ # FIXME: if error is longer than els, should it raise an error?
296
+ for el, err in zip(els, error):
297
+ if err is None:
298
+ continue
299
+ yield el, err
venv/lib/python3.10/site-packages/lxml/html/html5parser.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ An interface to html5lib that mimics the lxml.html interface.
3
+ """
4
+ import sys
5
+ import string
6
+
7
+ from html5lib import HTMLParser as _HTMLParser
8
+ from html5lib.treebuilders.etree_lxml import TreeBuilder
9
+ from lxml import etree
10
+ from lxml.html import Element, XHTML_NAMESPACE, _contains_block_level_tag
11
+
12
+ # python3 compatibility
13
+ try:
14
+ _strings = basestring
15
+ except NameError:
16
+ _strings = (bytes, str)
17
+ try:
18
+ from urllib2 import urlopen
19
+ except ImportError:
20
+ from urllib.request import urlopen
21
+ try:
22
+ from urlparse import urlparse
23
+ except ImportError:
24
+ from urllib.parse import urlparse
25
+
26
+
27
+ class HTMLParser(_HTMLParser):
28
+ """An html5lib HTML parser with lxml as tree."""
29
+
30
+ def __init__(self, strict=False, **kwargs):
31
+ _HTMLParser.__init__(self, strict=strict, tree=TreeBuilder, **kwargs)
32
+
33
+
34
+ try:
35
+ from html5lib import XHTMLParser as _XHTMLParser
36
+ except ImportError:
37
+ pass
38
+ else:
39
+ class XHTMLParser(_XHTMLParser):
40
+ """An html5lib XHTML Parser with lxml as tree."""
41
+
42
+ def __init__(self, strict=False, **kwargs):
43
+ _XHTMLParser.__init__(self, strict=strict, tree=TreeBuilder, **kwargs)
44
+
45
+ xhtml_parser = XHTMLParser()
46
+
47
+
48
+ def _find_tag(tree, tag):
49
+ elem = tree.find(tag)
50
+ if elem is not None:
51
+ return elem
52
+ return tree.find('{%s}%s' % (XHTML_NAMESPACE, tag))
53
+
54
+
55
+ def document_fromstring(html, guess_charset=None, parser=None):
56
+ """
57
+ Parse a whole document into a string.
58
+
59
+ If `guess_charset` is true, or if the input is not Unicode but a
60
+ byte string, the `chardet` library will perform charset guessing
61
+ on the string.
62
+ """
63
+ if not isinstance(html, _strings):
64
+ raise TypeError('string required')
65
+
66
+ if parser is None:
67
+ parser = html_parser
68
+
69
+ options = {}
70
+ if guess_charset is None and isinstance(html, bytes):
71
+ # html5lib does not accept useChardet as an argument, if it
72
+ # detected the html argument would produce unicode objects.
73
+ guess_charset = True
74
+ if guess_charset is not None:
75
+ options['useChardet'] = guess_charset
76
+ return parser.parse(html, **options).getroot()
77
+
78
+
79
+ def fragments_fromstring(html, no_leading_text=False,
80
+ guess_charset=None, parser=None):
81
+ """Parses several HTML elements, returning a list of elements.
82
+
83
+ The first item in the list may be a string. If no_leading_text is true,
84
+ then it will be an error if there is leading text, and it will always be
85
+ a list of only elements.
86
+
87
+ If `guess_charset` is true, the `chardet` library will perform charset
88
+ guessing on the string.
89
+ """
90
+ if not isinstance(html, _strings):
91
+ raise TypeError('string required')
92
+
93
+ if parser is None:
94
+ parser = html_parser
95
+
96
+ options = {}
97
+ if guess_charset is None and isinstance(html, bytes):
98
+ # html5lib does not accept useChardet as an argument, if it
99
+ # detected the html argument would produce unicode objects.
100
+ guess_charset = False
101
+ if guess_charset is not None:
102
+ options['useChardet'] = guess_charset
103
+ children = parser.parseFragment(html, 'div', **options)
104
+ if children and isinstance(children[0], _strings):
105
+ if no_leading_text:
106
+ if children[0].strip():
107
+ raise etree.ParserError('There is leading text: %r' %
108
+ children[0])
109
+ del children[0]
110
+ return children
111
+
112
+
113
+ def fragment_fromstring(html, create_parent=False,
114
+ guess_charset=None, parser=None):
115
+ """Parses a single HTML element; it is an error if there is more than
116
+ one element, or if anything but whitespace precedes or follows the
117
+ element.
118
+
119
+ If 'create_parent' is true (or is a tag name) then a parent node
120
+ will be created to encapsulate the HTML in a single element. In
121
+ this case, leading or trailing text is allowed.
122
+
123
+ If `guess_charset` is true, the `chardet` library will perform charset
124
+ guessing on the string.
125
+ """
126
+ if not isinstance(html, _strings):
127
+ raise TypeError('string required')
128
+
129
+ accept_leading_text = bool(create_parent)
130
+
131
+ elements = fragments_fromstring(
132
+ html, guess_charset=guess_charset, parser=parser,
133
+ no_leading_text=not accept_leading_text)
134
+
135
+ if create_parent:
136
+ if not isinstance(create_parent, _strings):
137
+ create_parent = 'div'
138
+ new_root = Element(create_parent)
139
+ if elements:
140
+ if isinstance(elements[0], _strings):
141
+ new_root.text = elements[0]
142
+ del elements[0]
143
+ new_root.extend(elements)
144
+ return new_root
145
+
146
+ if not elements:
147
+ raise etree.ParserError('No elements found')
148
+ if len(elements) > 1:
149
+ raise etree.ParserError('Multiple elements found')
150
+ result = elements[0]
151
+ if result.tail and result.tail.strip():
152
+ raise etree.ParserError('Element followed by text: %r' % result.tail)
153
+ result.tail = None
154
+ return result
155
+
156
+
157
+ def fromstring(html, guess_charset=None, parser=None):
158
+ """Parse the html, returning a single element/document.
159
+
160
+ This tries to minimally parse the chunk of text, without knowing if it
161
+ is a fragment or a document.
162
+
163
+ 'base_url' will set the document's base_url attribute (and the tree's
164
+ docinfo.URL)
165
+
166
+ If `guess_charset` is true, or if the input is not Unicode but a
167
+ byte string, the `chardet` library will perform charset guessing
168
+ on the string.
169
+ """
170
+ if not isinstance(html, _strings):
171
+ raise TypeError('string required')
172
+ doc = document_fromstring(html, parser=parser,
173
+ guess_charset=guess_charset)
174
+
175
+ # document starts with doctype or <html>, full document!
176
+ start = html[:50]
177
+ if isinstance(start, bytes):
178
+ # Allow text comparison in python3.
179
+ # Decode as ascii, that also covers latin-1 and utf-8 for the
180
+ # characters we need.
181
+ start = start.decode('ascii', 'replace')
182
+
183
+ start = start.lstrip().lower()
184
+ if start.startswith('<html') or start.startswith('<!doctype'):
185
+ return doc
186
+
187
+ head = _find_tag(doc, 'head')
188
+
189
+ # if the head is not empty we have a full document
190
+ if len(head):
191
+ return doc
192
+
193
+ body = _find_tag(doc, 'body')
194
+
195
+ # The body has just one element, so it was probably a single
196
+ # element passed in
197
+ if (len(body) == 1 and (not body.text or not body.text.strip())
198
+ and (not body[-1].tail or not body[-1].tail.strip())):
199
+ return body[0]
200
+
201
+ # Now we have a body which represents a bunch of tags which have the
202
+ # content that was passed in. We will create a fake container, which
203
+ # is the body tag, except <body> implies too much structure.
204
+ if _contains_block_level_tag(body):
205
+ body.tag = 'div'
206
+ else:
207
+ body.tag = 'span'
208
+ return body
209
+
210
+
211
+ def parse(filename_url_or_file, guess_charset=None, parser=None):
212
+ """Parse a filename, URL, or file-like object into an HTML document
213
+ tree. Note: this returns a tree, not an element. Use
214
+ ``parse(...).getroot()`` to get the document root.
215
+
216
+ If ``guess_charset`` is true, the ``useChardet`` option is passed into
217
+ html5lib to enable character detection. This option is on by default
218
+ when parsing from URLs, off by default when parsing from file(-like)
219
+ objects (which tend to return Unicode more often than not), and on by
220
+ default when parsing from a file path (which is read in binary mode).
221
+ """
222
+ if parser is None:
223
+ parser = html_parser
224
+ if not isinstance(filename_url_or_file, _strings):
225
+ fp = filename_url_or_file
226
+ if guess_charset is None:
227
+ # assume that file-like objects return Unicode more often than bytes
228
+ guess_charset = False
229
+ elif _looks_like_url(filename_url_or_file):
230
+ fp = urlopen(filename_url_or_file)
231
+ if guess_charset is None:
232
+ # assume that URLs return bytes
233
+ guess_charset = True
234
+ else:
235
+ fp = open(filename_url_or_file, 'rb')
236
+ if guess_charset is None:
237
+ guess_charset = True
238
+
239
+ options = {}
240
+ # html5lib does not accept useChardet as an argument, if it
241
+ # detected the html argument would produce unicode objects.
242
+ if guess_charset:
243
+ options['useChardet'] = guess_charset
244
+ return parser.parse(fp, **options)
245
+
246
+
247
+ def _looks_like_url(str):
248
+ scheme = urlparse(str)[0]
249
+ if not scheme:
250
+ return False
251
+ elif (sys.platform == 'win32' and
252
+ scheme in string.ascii_letters
253
+ and len(scheme) == 1):
254
+ # looks like a 'normal' absolute path
255
+ return False
256
+ else:
257
+ return True
258
+
259
+
260
+ html_parser = HTMLParser()
venv/lib/python3.10/site-packages/lxml/html/soupparser.py ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """External interface to the BeautifulSoup HTML parser.
2
+ """
3
+
4
+ __all__ = ["fromstring", "parse", "convert_tree"]
5
+
6
+ import re
7
+ from lxml import etree, html
8
+
9
+ try:
10
+ from bs4 import (
11
+ BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString,
12
+ Declaration, Doctype)
13
+ _DECLARATION_OR_DOCTYPE = (Declaration, Doctype)
14
+ except ImportError:
15
+ from BeautifulSoup import (
16
+ BeautifulSoup, Tag, Comment, ProcessingInstruction, NavigableString,
17
+ Declaration)
18
+ _DECLARATION_OR_DOCTYPE = Declaration
19
+
20
+
21
+ def fromstring(data, beautifulsoup=None, makeelement=None, **bsargs):
22
+ """Parse a string of HTML data into an Element tree using the
23
+ BeautifulSoup parser.
24
+
25
+ Returns the root ``<html>`` Element of the tree.
26
+
27
+ You can pass a different BeautifulSoup parser through the
28
+ `beautifulsoup` keyword, and a diffent Element factory function
29
+ through the `makeelement` keyword. By default, the standard
30
+ ``BeautifulSoup`` class and the default factory of `lxml.html` are
31
+ used.
32
+ """
33
+ return _parse(data, beautifulsoup, makeelement, **bsargs)
34
+
35
+
36
+ def parse(file, beautifulsoup=None, makeelement=None, **bsargs):
37
+ """Parse a file into an ElemenTree using the BeautifulSoup parser.
38
+
39
+ You can pass a different BeautifulSoup parser through the
40
+ `beautifulsoup` keyword, and a diffent Element factory function
41
+ through the `makeelement` keyword. By default, the standard
42
+ ``BeautifulSoup`` class and the default factory of `lxml.html` are
43
+ used.
44
+ """
45
+ if not hasattr(file, 'read'):
46
+ file = open(file)
47
+ root = _parse(file, beautifulsoup, makeelement, **bsargs)
48
+ return etree.ElementTree(root)
49
+
50
+
51
+ def convert_tree(beautiful_soup_tree, makeelement=None):
52
+ """Convert a BeautifulSoup tree to a list of Element trees.
53
+
54
+ Returns a list instead of a single root Element to support
55
+ HTML-like soup with more than one root element.
56
+
57
+ You can pass a different Element factory through the `makeelement`
58
+ keyword.
59
+ """
60
+ root = _convert_tree(beautiful_soup_tree, makeelement)
61
+ children = root.getchildren()
62
+ for child in children:
63
+ root.remove(child)
64
+ return children
65
+
66
+
67
+ # helpers
68
+
69
+ def _parse(source, beautifulsoup, makeelement, **bsargs):
70
+ if beautifulsoup is None:
71
+ beautifulsoup = BeautifulSoup
72
+ if hasattr(beautifulsoup, "HTML_ENTITIES"): # bs3
73
+ if 'convertEntities' not in bsargs:
74
+ bsargs['convertEntities'] = 'html'
75
+ if hasattr(beautifulsoup, "DEFAULT_BUILDER_FEATURES"): # bs4
76
+ if 'features' not in bsargs:
77
+ bsargs['features'] = 'html.parser' # use Python html parser
78
+ tree = beautifulsoup(source, **bsargs)
79
+ root = _convert_tree(tree, makeelement)
80
+ # from ET: wrap the document in a html root element, if necessary
81
+ if len(root) == 1 and root[0].tag == "html":
82
+ return root[0]
83
+ root.tag = "html"
84
+ return root
85
+
86
+
87
+ _parse_doctype_declaration = re.compile(
88
+ r'(?:\s|[<!])*DOCTYPE\s*HTML'
89
+ r'(?:\s+PUBLIC)?(?:\s+(\'[^\']*\'|"[^"]*"))?'
90
+ r'(?:\s+(\'[^\']*\'|"[^"]*"))?',
91
+ re.IGNORECASE).match
92
+
93
+
94
+ class _PseudoTag:
95
+ # Minimal imitation of BeautifulSoup.Tag
96
+ def __init__(self, contents):
97
+ self.name = 'html'
98
+ self.attrs = []
99
+ self.contents = contents
100
+
101
+ def __iter__(self):
102
+ return self.contents.__iter__()
103
+
104
+
105
+ def _convert_tree(beautiful_soup_tree, makeelement):
106
+ if makeelement is None:
107
+ makeelement = html.html_parser.makeelement
108
+
109
+ # Split the tree into three parts:
110
+ # i) everything before the root element: document type
111
+ # declaration, comments, processing instructions, whitespace
112
+ # ii) the root(s),
113
+ # iii) everything after the root: comments, processing
114
+ # instructions, whitespace
115
+ first_element_idx = last_element_idx = None
116
+ html_root = declaration = None
117
+ for i, e in enumerate(beautiful_soup_tree):
118
+ if isinstance(e, Tag):
119
+ if first_element_idx is None:
120
+ first_element_idx = i
121
+ last_element_idx = i
122
+ if html_root is None and e.name and e.name.lower() == 'html':
123
+ html_root = e
124
+ elif declaration is None and isinstance(e, _DECLARATION_OR_DOCTYPE):
125
+ declaration = e
126
+
127
+ # For a nice, well-formatted document, the variable roots below is
128
+ # a list consisting of a single <html> element. However, the document
129
+ # may be a soup like '<meta><head><title>Hello</head><body>Hi
130
+ # all<\p>'. In this example roots is a list containing meta, head
131
+ # and body elements.
132
+ if first_element_idx is None:
133
+ pre_root = post_root = []
134
+ roots = beautiful_soup_tree.contents
135
+ else:
136
+ pre_root = beautiful_soup_tree.contents[:first_element_idx]
137
+ roots = beautiful_soup_tree.contents[first_element_idx:last_element_idx+1]
138
+ post_root = beautiful_soup_tree.contents[last_element_idx+1:]
139
+
140
+ # Reorganize so that there is one <html> root...
141
+ if html_root is not None:
142
+ # ... use existing one if possible, ...
143
+ i = roots.index(html_root)
144
+ html_root.contents = roots[:i] + html_root.contents + roots[i+1:]
145
+ else:
146
+ # ... otherwise create a new one.
147
+ html_root = _PseudoTag(roots)
148
+
149
+ convert_node = _init_node_converters(makeelement)
150
+
151
+ # Process pre_root
152
+ res_root = convert_node(html_root)
153
+ prev = res_root
154
+ for e in reversed(pre_root):
155
+ converted = convert_node(e)
156
+ if converted is not None:
157
+ prev.addprevious(converted)
158
+ prev = converted
159
+
160
+ # ditto for post_root
161
+ prev = res_root
162
+ for e in post_root:
163
+ converted = convert_node(e)
164
+ if converted is not None:
165
+ prev.addnext(converted)
166
+ prev = converted
167
+
168
+ if declaration is not None:
169
+ try:
170
+ # bs4 provides full Doctype string
171
+ doctype_string = declaration.output_ready()
172
+ except AttributeError:
173
+ doctype_string = declaration.string
174
+
175
+ match = _parse_doctype_declaration(doctype_string)
176
+ if not match:
177
+ # Something is wrong if we end up in here. Since soupparser should
178
+ # tolerate errors, do not raise Exception, just let it pass.
179
+ pass
180
+ else:
181
+ external_id, sys_uri = match.groups()
182
+ docinfo = res_root.getroottree().docinfo
183
+ # strip quotes and update DOCTYPE values (any of None, '', '...')
184
+ docinfo.public_id = external_id and external_id[1:-1]
185
+ docinfo.system_url = sys_uri and sys_uri[1:-1]
186
+
187
+ return res_root
188
+
189
+
190
+ def _init_node_converters(makeelement):
191
+ converters = {}
192
+ ordered_node_types = []
193
+
194
+ def converter(*types):
195
+ def add(handler):
196
+ for t in types:
197
+ converters[t] = handler
198
+ ordered_node_types.append(t)
199
+ return handler
200
+ return add
201
+
202
+ def find_best_converter(node):
203
+ for t in ordered_node_types:
204
+ if isinstance(node, t):
205
+ return converters[t]
206
+ return None
207
+
208
+ def convert_node(bs_node, parent=None):
209
+ # duplicated in convert_tag() below
210
+ try:
211
+ handler = converters[type(bs_node)]
212
+ except KeyError:
213
+ handler = converters[type(bs_node)] = find_best_converter(bs_node)
214
+ if handler is None:
215
+ return None
216
+ return handler(bs_node, parent)
217
+
218
+ def map_attrs(bs_attrs):
219
+ if isinstance(bs_attrs, dict): # bs4
220
+ attribs = {}
221
+ for k, v in bs_attrs.items():
222
+ if isinstance(v, list):
223
+ v = " ".join(v)
224
+ attribs[k] = unescape(v)
225
+ else:
226
+ attribs = {k: unescape(v) for k, v in bs_attrs}
227
+ return attribs
228
+
229
+ def append_text(parent, text):
230
+ if len(parent) == 0:
231
+ parent.text = (parent.text or '') + text
232
+ else:
233
+ parent[-1].tail = (parent[-1].tail or '') + text
234
+
235
+ # converters are tried in order of their definition
236
+
237
+ @converter(Tag, _PseudoTag)
238
+ def convert_tag(bs_node, parent):
239
+ attrs = bs_node.attrs
240
+ if parent is not None:
241
+ attribs = map_attrs(attrs) if attrs else None
242
+ res = etree.SubElement(parent, bs_node.name, attrib=attribs)
243
+ else:
244
+ attribs = map_attrs(attrs) if attrs else {}
245
+ res = makeelement(bs_node.name, attrib=attribs)
246
+
247
+ for child in bs_node:
248
+ # avoid double recursion by inlining convert_node(), see above
249
+ try:
250
+ handler = converters[type(child)]
251
+ except KeyError:
252
+ pass
253
+ else:
254
+ if handler is not None:
255
+ handler(child, res)
256
+ continue
257
+ convert_node(child, res)
258
+ return res
259
+
260
+ @converter(Comment)
261
+ def convert_comment(bs_node, parent):
262
+ res = html.HtmlComment(bs_node)
263
+ if parent is not None:
264
+ parent.append(res)
265
+ return res
266
+
267
+ @converter(ProcessingInstruction)
268
+ def convert_pi(bs_node, parent):
269
+ if bs_node.endswith('?'):
270
+ # The PI is of XML style (<?as df?>) but BeautifulSoup
271
+ # interpreted it as being SGML style (<?as df>). Fix.
272
+ bs_node = bs_node[:-1]
273
+ res = etree.ProcessingInstruction(*bs_node.split(' ', 1))
274
+ if parent is not None:
275
+ parent.append(res)
276
+ return res
277
+
278
+ @converter(NavigableString)
279
+ def convert_text(bs_node, parent):
280
+ if parent is not None:
281
+ append_text(parent, unescape(bs_node))
282
+ return None
283
+
284
+ return convert_node
285
+
286
+
287
+ # copied from ET's ElementSoup
288
+
289
+ try:
290
+ from html.entities import name2codepoint # Python 3
291
+ except ImportError:
292
+ from htmlentitydefs import name2codepoint
293
+
294
+
295
+ handle_entities = re.compile(r"&(\w+);").sub
296
+
297
+
298
+ try:
299
+ unichr
300
+ except NameError:
301
+ # Python 3
302
+ unichr = chr
303
+
304
+
305
+ def unescape(string):
306
+ if not string:
307
+ return ''
308
+ # work around oddities in BeautifulSoup's entity handling
309
+ def unescape_entity(m):
310
+ try:
311
+ return unichr(name2codepoint[m.group(1)])
312
+ except KeyError:
313
+ return m.group(0) # use as is
314
+ return handle_entities(unescape_entity, string)
venv/lib/python3.10/site-packages/lxml/html/usedoctest.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Doctest module for HTML comparison.
2
+
3
+ Usage::
4
+
5
+ >>> import lxml.html.usedoctest
6
+ >>> # now do your HTML doctests ...
7
+
8
+ See `lxml.doctestcompare`.
9
+ """
10
+
11
+ from lxml import doctestcompare
12
+
13
+ doctestcompare.temp_install(html=True, del_module=__name__)
venv/lib/python3.10/site-packages/lxml/includes/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (181 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/includes/libexslt/__init__.py ADDED
File without changes
venv/lib/python3.10/site-packages/lxml/includes/libexslt/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (190 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/includes/libexslt/exslt.h ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: main header file
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ */
6
+
7
+
8
+ #ifndef __EXSLT_H__
9
+ #define __EXSLT_H__
10
+
11
+ #include <libxml/tree.h>
12
+ #include <libxml/xpath.h>
13
+ #include "exsltexports.h"
14
+ #include <libexslt/exsltconfig.h>
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ EXSLTPUBVAR const char *exsltLibraryVersion;
21
+ EXSLTPUBVAR const int exsltLibexsltVersion;
22
+ EXSLTPUBVAR const int exsltLibxsltVersion;
23
+ EXSLTPUBVAR const int exsltLibxmlVersion;
24
+
25
+ /**
26
+ * EXSLT_COMMON_NAMESPACE:
27
+ *
28
+ * Namespace for EXSLT common functions
29
+ */
30
+ #define EXSLT_COMMON_NAMESPACE ((const xmlChar *) "http://exslt.org/common")
31
+ /**
32
+ * EXSLT_CRYPTO_NAMESPACE:
33
+ *
34
+ * Namespace for EXSLT crypto functions
35
+ */
36
+ #define EXSLT_CRYPTO_NAMESPACE ((const xmlChar *) "http://exslt.org/crypto")
37
+ /**
38
+ * EXSLT_MATH_NAMESPACE:
39
+ *
40
+ * Namespace for EXSLT math functions
41
+ */
42
+ #define EXSLT_MATH_NAMESPACE ((const xmlChar *) "http://exslt.org/math")
43
+ /**
44
+ * EXSLT_SETS_NAMESPACE:
45
+ *
46
+ * Namespace for EXSLT set functions
47
+ */
48
+ #define EXSLT_SETS_NAMESPACE ((const xmlChar *) "http://exslt.org/sets")
49
+ /**
50
+ * EXSLT_FUNCTIONS_NAMESPACE:
51
+ *
52
+ * Namespace for EXSLT functions extension functions
53
+ */
54
+ #define EXSLT_FUNCTIONS_NAMESPACE ((const xmlChar *) "http://exslt.org/functions")
55
+ /**
56
+ * EXSLT_STRINGS_NAMESPACE:
57
+ *
58
+ * Namespace for EXSLT strings functions
59
+ */
60
+ #define EXSLT_STRINGS_NAMESPACE ((const xmlChar *) "http://exslt.org/strings")
61
+ /**
62
+ * EXSLT_DATE_NAMESPACE:
63
+ *
64
+ * Namespace for EXSLT date functions
65
+ */
66
+ #define EXSLT_DATE_NAMESPACE ((const xmlChar *) "http://exslt.org/dates-and-times")
67
+ /**
68
+ * EXSLT_DYNAMIC_NAMESPACE:
69
+ *
70
+ * Namespace for EXSLT dynamic functions
71
+ */
72
+ #define EXSLT_DYNAMIC_NAMESPACE ((const xmlChar *) "http://exslt.org/dynamic")
73
+
74
+ /**
75
+ * SAXON_NAMESPACE:
76
+ *
77
+ * Namespace for SAXON extensions functions
78
+ */
79
+ #define SAXON_NAMESPACE ((const xmlChar *) "http://icl.com/saxon")
80
+
81
+ EXSLTPUBFUN void EXSLTCALL exsltCommonRegister (void);
82
+ #ifdef EXSLT_CRYPTO_ENABLED
83
+ EXSLTPUBFUN void EXSLTCALL exsltCryptoRegister (void);
84
+ #endif
85
+ EXSLTPUBFUN void EXSLTCALL exsltMathRegister (void);
86
+ EXSLTPUBFUN void EXSLTCALL exsltSetsRegister (void);
87
+ EXSLTPUBFUN void EXSLTCALL exsltFuncRegister (void);
88
+ EXSLTPUBFUN void EXSLTCALL exsltStrRegister (void);
89
+ EXSLTPUBFUN void EXSLTCALL exsltDateRegister (void);
90
+ EXSLTPUBFUN void EXSLTCALL exsltSaxonRegister (void);
91
+ EXSLTPUBFUN void EXSLTCALL exsltDynRegister(void);
92
+
93
+ EXSLTPUBFUN void EXSLTCALL exsltRegisterAll (void);
94
+
95
+ EXSLTPUBFUN int EXSLTCALL exsltDateXpathCtxtRegister (xmlXPathContextPtr ctxt,
96
+ const xmlChar *prefix);
97
+ EXSLTPUBFUN int EXSLTCALL exsltMathXpathCtxtRegister (xmlXPathContextPtr ctxt,
98
+ const xmlChar *prefix);
99
+ EXSLTPUBFUN int EXSLTCALL exsltSetsXpathCtxtRegister (xmlXPathContextPtr ctxt,
100
+ const xmlChar *prefix);
101
+ EXSLTPUBFUN int EXSLTCALL exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt,
102
+ const xmlChar *prefix);
103
+
104
+ #ifdef __cplusplus
105
+ }
106
+ #endif
107
+ #endif /* __EXSLT_H__ */
108
+
venv/lib/python3.10/site-packages/lxml/includes/libexslt/exsltconfig.h ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * exsltconfig.h: compile-time version information for the EXSLT library
3
+ *
4
+ * See Copyright for the status of this software.
5
+ *
6
7
+ */
8
+
9
+ #ifndef __XML_EXSLTCONFIG_H__
10
+ #define __XML_EXSLTCONFIG_H__
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ /**
17
+ * LIBEXSLT_DOTTED_VERSION:
18
+ *
19
+ * the version string like "1.2.3"
20
+ */
21
+ #define LIBEXSLT_DOTTED_VERSION "0.8.21"
22
+
23
+ /**
24
+ * LIBEXSLT_VERSION:
25
+ *
26
+ * the version number: 1.2.3 value is 10203
27
+ */
28
+ #define LIBEXSLT_VERSION 821
29
+
30
+ /**
31
+ * LIBEXSLT_VERSION_STRING:
32
+ *
33
+ * the version number string, 1.2.3 value is "10203"
34
+ */
35
+ #define LIBEXSLT_VERSION_STRING "821"
36
+
37
+ /**
38
+ * LIBEXSLT_VERSION_EXTRA:
39
+ *
40
+ * extra version information, used to show a Git commit description
41
+ */
42
+ #define LIBEXSLT_VERSION_EXTRA ""
43
+
44
+ /**
45
+ * WITH_CRYPTO:
46
+ *
47
+ * Whether crypto support is configured into exslt
48
+ */
49
+ #if 0
50
+ #define EXSLT_CRYPTO_ENABLED
51
+ #endif
52
+
53
+ /**
54
+ * ATTRIBUTE_UNUSED:
55
+ *
56
+ * This macro is used to flag unused function parameters to GCC
57
+ */
58
+ #ifdef __GNUC__
59
+ #ifndef ATTRIBUTE_UNUSED
60
+ #define ATTRIBUTE_UNUSED __attribute__((unused))
61
+ #endif
62
+ #else
63
+ #define ATTRIBUTE_UNUSED
64
+ #endif
65
+
66
+ #ifdef __cplusplus
67
+ }
68
+ #endif
69
+
70
+ #endif /* __XML_EXSLTCONFIG_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libexslt/exsltexports.h ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: macros for marking symbols as exportable/importable.
3
+ *
4
+ * Copy: See Copyright for the status of this software.
5
+ */
6
+
7
+ #ifndef __EXSLT_EXPORTS_H__
8
+ #define __EXSLT_EXPORTS_H__
9
+
10
+ #if defined(_WIN32) || defined(__CYGWIN__)
11
+ /** DOC_DISABLE */
12
+
13
+ #ifdef LIBEXSLT_STATIC
14
+ #define EXSLTPUBLIC
15
+ #elif defined(IN_LIBEXSLT)
16
+ #define EXSLTPUBLIC __declspec(dllexport)
17
+ #else
18
+ #define EXSLTPUBLIC __declspec(dllimport)
19
+ #endif
20
+
21
+ #define EXSLTCALL __cdecl
22
+
23
+ /** DOC_ENABLE */
24
+ #else /* not Windows */
25
+
26
+ /**
27
+ * EXSLTPUBLIC:
28
+ *
29
+ * Macro which declares a public symbol
30
+ */
31
+ #define EXSLTPUBLIC
32
+
33
+ /**
34
+ * EXSLTCALL:
35
+ *
36
+ * Macro which declares the calling convention for exported functions
37
+ */
38
+ #define EXSLTCALL
39
+
40
+ #endif /* platform switch */
41
+
42
+ /*
43
+ * EXSLTPUBFUN:
44
+ *
45
+ * Macro which declares an exportable function
46
+ */
47
+ #define EXSLTPUBFUN EXSLTPUBLIC
48
+
49
+ /**
50
+ * EXSLTPUBVAR:
51
+ *
52
+ * Macro which declares an exportable variable
53
+ */
54
+ #define EXSLTPUBVAR EXSLTPUBLIC extern
55
+
56
+ /* Compatibility */
57
+ #if !defined(LIBEXSLT_PUBLIC)
58
+ #define LIBEXSLT_PUBLIC EXSLTPUBVAR
59
+ #endif
60
+
61
+ #endif /* __EXSLT_EXPORTS_H__ */
62
+
63
+
venv/lib/python3.10/site-packages/lxml/includes/libxml/HTMLparser.h ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: interface for an HTML 4.0 non-verifying parser
3
+ * Description: this module implements an HTML 4.0 non-verifying parser
4
+ * with API compatible with the XML parser ones. It should
5
+ * be able to parse "real world" HTML, even if severely
6
+ * broken from a specification point of view.
7
+ *
8
+ * Copy: See Copyright for the status of this software.
9
+ *
10
+ * Author: Daniel Veillard
11
+ */
12
+
13
+ #ifndef __HTML_PARSER_H__
14
+ #define __HTML_PARSER_H__
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/parser.h>
17
+
18
+ #ifdef LIBXML_HTML_ENABLED
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ /*
25
+ * Most of the back-end structures from XML and HTML are shared.
26
+ */
27
+ typedef xmlParserCtxt htmlParserCtxt;
28
+ typedef xmlParserCtxtPtr htmlParserCtxtPtr;
29
+ typedef xmlParserNodeInfo htmlParserNodeInfo;
30
+ typedef xmlSAXHandler htmlSAXHandler;
31
+ typedef xmlSAXHandlerPtr htmlSAXHandlerPtr;
32
+ typedef xmlParserInput htmlParserInput;
33
+ typedef xmlParserInputPtr htmlParserInputPtr;
34
+ typedef xmlDocPtr htmlDocPtr;
35
+ typedef xmlNodePtr htmlNodePtr;
36
+
37
+ /*
38
+ * Internal description of an HTML element, representing HTML 4.01
39
+ * and XHTML 1.0 (which share the same structure).
40
+ */
41
+ typedef struct _htmlElemDesc htmlElemDesc;
42
+ typedef htmlElemDesc *htmlElemDescPtr;
43
+ struct _htmlElemDesc {
44
+ const char *name; /* The tag name */
45
+ char startTag; /* Whether the start tag can be implied */
46
+ char endTag; /* Whether the end tag can be implied */
47
+ char saveEndTag; /* Whether the end tag should be saved */
48
+ char empty; /* Is this an empty element ? */
49
+ char depr; /* Is this a deprecated element ? */
50
+ char dtd; /* 1: only in Loose DTD, 2: only Frameset one */
51
+ char isinline; /* is this a block 0 or inline 1 element */
52
+ const char *desc; /* the description */
53
+
54
+ /* NRK Jan.2003
55
+ * New fields encapsulating HTML structure
56
+ *
57
+ * Bugs:
58
+ * This is a very limited representation. It fails to tell us when
59
+ * an element *requires* subelements (we only have whether they're
60
+ * allowed or not), and it doesn't tell us where CDATA and PCDATA
61
+ * are allowed. Some element relationships are not fully represented:
62
+ * these are flagged with the word MODIFIER
63
+ */
64
+ const char** subelts; /* allowed sub-elements of this element */
65
+ const char* defaultsubelt; /* subelement for suggested auto-repair
66
+ if necessary or NULL */
67
+ const char** attrs_opt; /* Optional Attributes */
68
+ const char** attrs_depr; /* Additional deprecated attributes */
69
+ const char** attrs_req; /* Required attributes */
70
+ };
71
+
72
+ /*
73
+ * Internal description of an HTML entity.
74
+ */
75
+ typedef struct _htmlEntityDesc htmlEntityDesc;
76
+ typedef htmlEntityDesc *htmlEntityDescPtr;
77
+ struct _htmlEntityDesc {
78
+ unsigned int value; /* the UNICODE value for the character */
79
+ const char *name; /* The entity name */
80
+ const char *desc; /* the description */
81
+ };
82
+
83
+ /** DOC_DISABLE */
84
+ #ifdef LIBXML_SAX1_ENABLED
85
+ #define XML_GLOBALS_HTML \
86
+ XML_OP(htmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED)
87
+ #else
88
+ #define XML_GLOBALS_HTML
89
+ #endif
90
+
91
+ #define XML_OP XML_DECLARE_GLOBAL
92
+ XML_GLOBALS_HTML
93
+ #undef XML_OP
94
+
95
+ #if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION)
96
+ #define htmlDefaultSAXHandler XML_GLOBAL_MACRO(htmlDefaultSAXHandler)
97
+ #endif
98
+ /** DOC_ENABLE */
99
+
100
+ /*
101
+ * There is only few public functions.
102
+ */
103
+ XML_DEPRECATED
104
+ XMLPUBFUN void
105
+ htmlInitAutoClose (void);
106
+ XMLPUBFUN const htmlElemDesc *
107
+ htmlTagLookup (const xmlChar *tag);
108
+ XMLPUBFUN const htmlEntityDesc *
109
+ htmlEntityLookup(const xmlChar *name);
110
+ XMLPUBFUN const htmlEntityDesc *
111
+ htmlEntityValueLookup(unsigned int value);
112
+
113
+ XMLPUBFUN int
114
+ htmlIsAutoClosed(htmlDocPtr doc,
115
+ htmlNodePtr elem);
116
+ XMLPUBFUN int
117
+ htmlAutoCloseTag(htmlDocPtr doc,
118
+ const xmlChar *name,
119
+ htmlNodePtr elem);
120
+ XML_DEPRECATED
121
+ XMLPUBFUN const htmlEntityDesc *
122
+ htmlParseEntityRef(htmlParserCtxtPtr ctxt,
123
+ const xmlChar **str);
124
+ XML_DEPRECATED
125
+ XMLPUBFUN int
126
+ htmlParseCharRef(htmlParserCtxtPtr ctxt);
127
+ XML_DEPRECATED
128
+ XMLPUBFUN void
129
+ htmlParseElement(htmlParserCtxtPtr ctxt);
130
+
131
+ XMLPUBFUN htmlParserCtxtPtr
132
+ htmlNewParserCtxt(void);
133
+ XMLPUBFUN htmlParserCtxtPtr
134
+ htmlNewSAXParserCtxt(const htmlSAXHandler *sax,
135
+ void *userData);
136
+
137
+ XMLPUBFUN htmlParserCtxtPtr
138
+ htmlCreateMemoryParserCtxt(const char *buffer,
139
+ int size);
140
+
141
+ XMLPUBFUN int
142
+ htmlParseDocument(htmlParserCtxtPtr ctxt);
143
+ XML_DEPRECATED
144
+ XMLPUBFUN htmlDocPtr
145
+ htmlSAXParseDoc (const xmlChar *cur,
146
+ const char *encoding,
147
+ htmlSAXHandlerPtr sax,
148
+ void *userData);
149
+ XMLPUBFUN htmlDocPtr
150
+ htmlParseDoc (const xmlChar *cur,
151
+ const char *encoding);
152
+ XMLPUBFUN htmlParserCtxtPtr
153
+ htmlCreateFileParserCtxt(const char *filename,
154
+ const char *encoding);
155
+ XML_DEPRECATED
156
+ XMLPUBFUN htmlDocPtr
157
+ htmlSAXParseFile(const char *filename,
158
+ const char *encoding,
159
+ htmlSAXHandlerPtr sax,
160
+ void *userData);
161
+ XMLPUBFUN htmlDocPtr
162
+ htmlParseFile (const char *filename,
163
+ const char *encoding);
164
+ XMLPUBFUN int
165
+ UTF8ToHtml (unsigned char *out,
166
+ int *outlen,
167
+ const unsigned char *in,
168
+ int *inlen);
169
+ XMLPUBFUN int
170
+ htmlEncodeEntities(unsigned char *out,
171
+ int *outlen,
172
+ const unsigned char *in,
173
+ int *inlen, int quoteChar);
174
+ XMLPUBFUN int
175
+ htmlIsScriptAttribute(const xmlChar *name);
176
+ XMLPUBFUN int
177
+ htmlHandleOmittedElem(int val);
178
+
179
+ #ifdef LIBXML_PUSH_ENABLED
180
+ /**
181
+ * Interfaces for the Push mode.
182
+ */
183
+ XMLPUBFUN htmlParserCtxtPtr
184
+ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax,
185
+ void *user_data,
186
+ const char *chunk,
187
+ int size,
188
+ const char *filename,
189
+ xmlCharEncoding enc);
190
+ XMLPUBFUN int
191
+ htmlParseChunk (htmlParserCtxtPtr ctxt,
192
+ const char *chunk,
193
+ int size,
194
+ int terminate);
195
+ #endif /* LIBXML_PUSH_ENABLED */
196
+
197
+ XMLPUBFUN void
198
+ htmlFreeParserCtxt (htmlParserCtxtPtr ctxt);
199
+
200
+ /*
201
+ * New set of simpler/more flexible APIs
202
+ */
203
+ /**
204
+ * xmlParserOption:
205
+ *
206
+ * This is the set of XML parser options that can be passed down
207
+ * to the xmlReadDoc() and similar calls.
208
+ */
209
+ typedef enum {
210
+ HTML_PARSE_RECOVER = 1<<0, /* Relaxed parsing */
211
+ HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */
212
+ HTML_PARSE_NOERROR = 1<<5, /* suppress error reports */
213
+ HTML_PARSE_NOWARNING= 1<<6, /* suppress warning reports */
214
+ HTML_PARSE_PEDANTIC = 1<<7, /* pedantic error reporting */
215
+ HTML_PARSE_NOBLANKS = 1<<8, /* remove blank nodes */
216
+ HTML_PARSE_NONET = 1<<11,/* Forbid network access */
217
+ HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body... elements */
218
+ HTML_PARSE_COMPACT = 1<<16,/* compact small text nodes */
219
+ HTML_PARSE_IGNORE_ENC=1<<21 /* ignore internal document encoding hint */
220
+ } htmlParserOption;
221
+
222
+ XMLPUBFUN void
223
+ htmlCtxtReset (htmlParserCtxtPtr ctxt);
224
+ XMLPUBFUN int
225
+ htmlCtxtUseOptions (htmlParserCtxtPtr ctxt,
226
+ int options);
227
+ XMLPUBFUN htmlDocPtr
228
+ htmlReadDoc (const xmlChar *cur,
229
+ const char *URL,
230
+ const char *encoding,
231
+ int options);
232
+ XMLPUBFUN htmlDocPtr
233
+ htmlReadFile (const char *URL,
234
+ const char *encoding,
235
+ int options);
236
+ XMLPUBFUN htmlDocPtr
237
+ htmlReadMemory (const char *buffer,
238
+ int size,
239
+ const char *URL,
240
+ const char *encoding,
241
+ int options);
242
+ XMLPUBFUN htmlDocPtr
243
+ htmlReadFd (int fd,
244
+ const char *URL,
245
+ const char *encoding,
246
+ int options);
247
+ XMLPUBFUN htmlDocPtr
248
+ htmlReadIO (xmlInputReadCallback ioread,
249
+ xmlInputCloseCallback ioclose,
250
+ void *ioctx,
251
+ const char *URL,
252
+ const char *encoding,
253
+ int options);
254
+ XMLPUBFUN htmlDocPtr
255
+ htmlCtxtReadDoc (xmlParserCtxtPtr ctxt,
256
+ const xmlChar *cur,
257
+ const char *URL,
258
+ const char *encoding,
259
+ int options);
260
+ XMLPUBFUN htmlDocPtr
261
+ htmlCtxtReadFile (xmlParserCtxtPtr ctxt,
262
+ const char *filename,
263
+ const char *encoding,
264
+ int options);
265
+ XMLPUBFUN htmlDocPtr
266
+ htmlCtxtReadMemory (xmlParserCtxtPtr ctxt,
267
+ const char *buffer,
268
+ int size,
269
+ const char *URL,
270
+ const char *encoding,
271
+ int options);
272
+ XMLPUBFUN htmlDocPtr
273
+ htmlCtxtReadFd (xmlParserCtxtPtr ctxt,
274
+ int fd,
275
+ const char *URL,
276
+ const char *encoding,
277
+ int options);
278
+ XMLPUBFUN htmlDocPtr
279
+ htmlCtxtReadIO (xmlParserCtxtPtr ctxt,
280
+ xmlInputReadCallback ioread,
281
+ xmlInputCloseCallback ioclose,
282
+ void *ioctx,
283
+ const char *URL,
284
+ const char *encoding,
285
+ int options);
286
+
287
+ /* NRK/Jan2003: further knowledge of HTML structure
288
+ */
289
+ typedef enum {
290
+ HTML_NA = 0 , /* something we don't check at all */
291
+ HTML_INVALID = 0x1 ,
292
+ HTML_DEPRECATED = 0x2 ,
293
+ HTML_VALID = 0x4 ,
294
+ HTML_REQUIRED = 0xc /* VALID bit set so ( & HTML_VALID ) is TRUE */
295
+ } htmlStatus ;
296
+
297
+ /* Using htmlElemDesc rather than name here, to emphasise the fact
298
+ that otherwise there's a lookup overhead
299
+ */
300
+ XMLPUBFUN htmlStatus htmlAttrAllowed(const htmlElemDesc*, const xmlChar*, int) ;
301
+ XMLPUBFUN int htmlElementAllowedHere(const htmlElemDesc*, const xmlChar*) ;
302
+ XMLPUBFUN htmlStatus htmlElementStatusHere(const htmlElemDesc*, const htmlElemDesc*) ;
303
+ XMLPUBFUN htmlStatus htmlNodeStatus(const htmlNodePtr, int) ;
304
+ /**
305
+ * htmlDefaultSubelement:
306
+ * @elt: HTML element
307
+ *
308
+ * Returns the default subelement for this element
309
+ */
310
+ #define htmlDefaultSubelement(elt) elt->defaultsubelt
311
+ /**
312
+ * htmlElementAllowedHereDesc:
313
+ * @parent: HTML parent element
314
+ * @elt: HTML element
315
+ *
316
+ * Checks whether an HTML element description may be a
317
+ * direct child of the specified element.
318
+ *
319
+ * Returns 1 if allowed; 0 otherwise.
320
+ */
321
+ #define htmlElementAllowedHereDesc(parent,elt) \
322
+ htmlElementAllowedHere((parent), (elt)->name)
323
+ /**
324
+ * htmlRequiredAttrs:
325
+ * @elt: HTML element
326
+ *
327
+ * Returns the attributes required for the specified element.
328
+ */
329
+ #define htmlRequiredAttrs(elt) (elt)->attrs_req
330
+
331
+
332
+ #ifdef __cplusplus
333
+ }
334
+ #endif
335
+
336
+ #else /* LIBXML_HTML_ENABLED */
337
+
338
+ /** DOC_DISABLE */
339
+ #define XML_GLOBALS_HTML
340
+ /** DOC_ENABLE */
341
+
342
+ #endif /* LIBXML_HTML_ENABLED */
343
+ #endif /* __HTML_PARSER_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/HTMLtree.h ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: specific APIs to process HTML tree, especially serialization
3
+ * Description: this module implements a few function needed to process
4
+ * tree in an HTML specific way.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __HTML_TREE_H__
12
+ #define __HTML_TREE_H__
13
+
14
+ #include <stdio.h>
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/tree.h>
17
+ #include <libxml/HTMLparser.h>
18
+
19
+ #ifdef LIBXML_HTML_ENABLED
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+
26
+ /**
27
+ * HTML_TEXT_NODE:
28
+ *
29
+ * Macro. A text node in a HTML document is really implemented
30
+ * the same way as a text node in an XML document.
31
+ */
32
+ #define HTML_TEXT_NODE XML_TEXT_NODE
33
+ /**
34
+ * HTML_ENTITY_REF_NODE:
35
+ *
36
+ * Macro. An entity reference in a HTML document is really implemented
37
+ * the same way as an entity reference in an XML document.
38
+ */
39
+ #define HTML_ENTITY_REF_NODE XML_ENTITY_REF_NODE
40
+ /**
41
+ * HTML_COMMENT_NODE:
42
+ *
43
+ * Macro. A comment in a HTML document is really implemented
44
+ * the same way as a comment in an XML document.
45
+ */
46
+ #define HTML_COMMENT_NODE XML_COMMENT_NODE
47
+ /**
48
+ * HTML_PRESERVE_NODE:
49
+ *
50
+ * Macro. A preserved node in a HTML document is really implemented
51
+ * the same way as a CDATA section in an XML document.
52
+ */
53
+ #define HTML_PRESERVE_NODE XML_CDATA_SECTION_NODE
54
+ /**
55
+ * HTML_PI_NODE:
56
+ *
57
+ * Macro. A processing instruction in a HTML document is really implemented
58
+ * the same way as a processing instruction in an XML document.
59
+ */
60
+ #define HTML_PI_NODE XML_PI_NODE
61
+
62
+ XMLPUBFUN htmlDocPtr
63
+ htmlNewDoc (const xmlChar *URI,
64
+ const xmlChar *ExternalID);
65
+ XMLPUBFUN htmlDocPtr
66
+ htmlNewDocNoDtD (const xmlChar *URI,
67
+ const xmlChar *ExternalID);
68
+ XMLPUBFUN const xmlChar *
69
+ htmlGetMetaEncoding (htmlDocPtr doc);
70
+ XMLPUBFUN int
71
+ htmlSetMetaEncoding (htmlDocPtr doc,
72
+ const xmlChar *encoding);
73
+ #ifdef LIBXML_OUTPUT_ENABLED
74
+ XMLPUBFUN void
75
+ htmlDocDumpMemory (xmlDocPtr cur,
76
+ xmlChar **mem,
77
+ int *size);
78
+ XMLPUBFUN void
79
+ htmlDocDumpMemoryFormat (xmlDocPtr cur,
80
+ xmlChar **mem,
81
+ int *size,
82
+ int format);
83
+ XMLPUBFUN int
84
+ htmlDocDump (FILE *f,
85
+ xmlDocPtr cur);
86
+ XMLPUBFUN int
87
+ htmlSaveFile (const char *filename,
88
+ xmlDocPtr cur);
89
+ XMLPUBFUN int
90
+ htmlNodeDump (xmlBufferPtr buf,
91
+ xmlDocPtr doc,
92
+ xmlNodePtr cur);
93
+ XMLPUBFUN void
94
+ htmlNodeDumpFile (FILE *out,
95
+ xmlDocPtr doc,
96
+ xmlNodePtr cur);
97
+ XMLPUBFUN int
98
+ htmlNodeDumpFileFormat (FILE *out,
99
+ xmlDocPtr doc,
100
+ xmlNodePtr cur,
101
+ const char *encoding,
102
+ int format);
103
+ XMLPUBFUN int
104
+ htmlSaveFileEnc (const char *filename,
105
+ xmlDocPtr cur,
106
+ const char *encoding);
107
+ XMLPUBFUN int
108
+ htmlSaveFileFormat (const char *filename,
109
+ xmlDocPtr cur,
110
+ const char *encoding,
111
+ int format);
112
+
113
+ XMLPUBFUN void
114
+ htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf,
115
+ xmlDocPtr doc,
116
+ xmlNodePtr cur,
117
+ const char *encoding,
118
+ int format);
119
+ XMLPUBFUN void
120
+ htmlDocContentDumpOutput(xmlOutputBufferPtr buf,
121
+ xmlDocPtr cur,
122
+ const char *encoding);
123
+ XMLPUBFUN void
124
+ htmlDocContentDumpFormatOutput(xmlOutputBufferPtr buf,
125
+ xmlDocPtr cur,
126
+ const char *encoding,
127
+ int format);
128
+ XMLPUBFUN void
129
+ htmlNodeDumpOutput (xmlOutputBufferPtr buf,
130
+ xmlDocPtr doc,
131
+ xmlNodePtr cur,
132
+ const char *encoding);
133
+
134
+ #endif /* LIBXML_OUTPUT_ENABLED */
135
+
136
+ XMLPUBFUN int
137
+ htmlIsBooleanAttr (const xmlChar *name);
138
+
139
+
140
+ #ifdef __cplusplus
141
+ }
142
+ #endif
143
+
144
+ #endif /* LIBXML_HTML_ENABLED */
145
+
146
+ #endif /* __HTML_TREE_H__ */
147
+
venv/lib/python3.10/site-packages/lxml/includes/libxml/__init__.py ADDED
File without changes
venv/lib/python3.10/site-packages/lxml/includes/libxml/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (188 Bytes). View file
 
venv/lib/python3.10/site-packages/lxml/includes/libxml/catalog.h ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Summary: interfaces to the Catalog handling system
3
+ * Description: the catalog module implements the support for
4
+ * XML Catalogs and SGML catalogs
5
+ *
6
+ * SGML Open Technical Resolution TR9401:1997.
7
+ * http://www.jclark.com/sp/catalog.htm
8
+ *
9
+ * XML Catalogs Working Draft 06 August 2001
10
+ * http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
11
+ *
12
+ * Copy: See Copyright for the status of this software.
13
+ *
14
+ * Author: Daniel Veillard
15
+ */
16
+
17
+ #ifndef __XML_CATALOG_H__
18
+ #define __XML_CATALOG_H__
19
+
20
+ #include <stdio.h>
21
+
22
+ #include <libxml/xmlversion.h>
23
+ #include <libxml/xmlstring.h>
24
+ #include <libxml/tree.h>
25
+
26
+ #ifdef LIBXML_CATALOG_ENABLED
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif
31
+
32
+ /**
33
+ * XML_CATALOGS_NAMESPACE:
34
+ *
35
+ * The namespace for the XML Catalogs elements.
36
+ */
37
+ #define XML_CATALOGS_NAMESPACE \
38
+ (const xmlChar *) "urn:oasis:names:tc:entity:xmlns:xml:catalog"
39
+ /**
40
+ * XML_CATALOG_PI:
41
+ *
42
+ * The specific XML Catalog Processing Instruction name.
43
+ */
44
+ #define XML_CATALOG_PI \
45
+ (const xmlChar *) "oasis-xml-catalog"
46
+
47
+ /*
48
+ * The API is voluntarily limited to general cataloging.
49
+ */
50
+ typedef enum {
51
+ XML_CATA_PREFER_NONE = 0,
52
+ XML_CATA_PREFER_PUBLIC = 1,
53
+ XML_CATA_PREFER_SYSTEM
54
+ } xmlCatalogPrefer;
55
+
56
+ typedef enum {
57
+ XML_CATA_ALLOW_NONE = 0,
58
+ XML_CATA_ALLOW_GLOBAL = 1,
59
+ XML_CATA_ALLOW_DOCUMENT = 2,
60
+ XML_CATA_ALLOW_ALL = 3
61
+ } xmlCatalogAllow;
62
+
63
+ typedef struct _xmlCatalog xmlCatalog;
64
+ typedef xmlCatalog *xmlCatalogPtr;
65
+
66
+ /*
67
+ * Operations on a given catalog.
68
+ */
69
+ XMLPUBFUN xmlCatalogPtr
70
+ xmlNewCatalog (int sgml);
71
+ XMLPUBFUN xmlCatalogPtr
72
+ xmlLoadACatalog (const char *filename);
73
+ XMLPUBFUN xmlCatalogPtr
74
+ xmlLoadSGMLSuperCatalog (const char *filename);
75
+ XMLPUBFUN int
76
+ xmlConvertSGMLCatalog (xmlCatalogPtr catal);
77
+ XMLPUBFUN int
78
+ xmlACatalogAdd (xmlCatalogPtr catal,
79
+ const xmlChar *type,
80
+ const xmlChar *orig,
81
+ const xmlChar *replace);
82
+ XMLPUBFUN int
83
+ xmlACatalogRemove (xmlCatalogPtr catal,
84
+ const xmlChar *value);
85
+ XMLPUBFUN xmlChar *
86
+ xmlACatalogResolve (xmlCatalogPtr catal,
87
+ const xmlChar *pubID,
88
+ const xmlChar *sysID);
89
+ XMLPUBFUN xmlChar *
90
+ xmlACatalogResolveSystem(xmlCatalogPtr catal,
91
+ const xmlChar *sysID);
92
+ XMLPUBFUN xmlChar *
93
+ xmlACatalogResolvePublic(xmlCatalogPtr catal,
94
+ const xmlChar *pubID);
95
+ XMLPUBFUN xmlChar *
96
+ xmlACatalogResolveURI (xmlCatalogPtr catal,
97
+ const xmlChar *URI);
98
+ #ifdef LIBXML_OUTPUT_ENABLED
99
+ XMLPUBFUN void
100
+ xmlACatalogDump (xmlCatalogPtr catal,
101
+ FILE *out);
102
+ #endif /* LIBXML_OUTPUT_ENABLED */
103
+ XMLPUBFUN void
104
+ xmlFreeCatalog (xmlCatalogPtr catal);
105
+ XMLPUBFUN int
106
+ xmlCatalogIsEmpty (xmlCatalogPtr catal);
107
+
108
+ /*
109
+ * Global operations.
110
+ */
111
+ XMLPUBFUN void
112
+ xmlInitializeCatalog (void);
113
+ XMLPUBFUN int
114
+ xmlLoadCatalog (const char *filename);
115
+ XMLPUBFUN void
116
+ xmlLoadCatalogs (const char *paths);
117
+ XMLPUBFUN void
118
+ xmlCatalogCleanup (void);
119
+ #ifdef LIBXML_OUTPUT_ENABLED
120
+ XMLPUBFUN void
121
+ xmlCatalogDump (FILE *out);
122
+ #endif /* LIBXML_OUTPUT_ENABLED */
123
+ XMLPUBFUN xmlChar *
124
+ xmlCatalogResolve (const xmlChar *pubID,
125
+ const xmlChar *sysID);
126
+ XMLPUBFUN xmlChar *
127
+ xmlCatalogResolveSystem (const xmlChar *sysID);
128
+ XMLPUBFUN xmlChar *
129
+ xmlCatalogResolvePublic (const xmlChar *pubID);
130
+ XMLPUBFUN xmlChar *
131
+ xmlCatalogResolveURI (const xmlChar *URI);
132
+ XMLPUBFUN int
133
+ xmlCatalogAdd (const xmlChar *type,
134
+ const xmlChar *orig,
135
+ const xmlChar *replace);
136
+ XMLPUBFUN int
137
+ xmlCatalogRemove (const xmlChar *value);
138
+ XMLPUBFUN xmlDocPtr
139
+ xmlParseCatalogFile (const char *filename);
140
+ XMLPUBFUN int
141
+ xmlCatalogConvert (void);
142
+
143
+ /*
144
+ * Strictly minimal interfaces for per-document catalogs used
145
+ * by the parser.
146
+ */
147
+ XMLPUBFUN void
148
+ xmlCatalogFreeLocal (void *catalogs);
149
+ XMLPUBFUN void *
150
+ xmlCatalogAddLocal (void *catalogs,
151
+ const xmlChar *URL);
152
+ XMLPUBFUN xmlChar *
153
+ xmlCatalogLocalResolve (void *catalogs,
154
+ const xmlChar *pubID,
155
+ const xmlChar *sysID);
156
+ XMLPUBFUN xmlChar *
157
+ xmlCatalogLocalResolveURI(void *catalogs,
158
+ const xmlChar *URI);
159
+ /*
160
+ * Preference settings.
161
+ */
162
+ XMLPUBFUN int
163
+ xmlCatalogSetDebug (int level);
164
+ XMLPUBFUN xmlCatalogPrefer
165
+ xmlCatalogSetDefaultPrefer(xmlCatalogPrefer prefer);
166
+ XMLPUBFUN void
167
+ xmlCatalogSetDefaults (xmlCatalogAllow allow);
168
+ XMLPUBFUN xmlCatalogAllow
169
+ xmlCatalogGetDefaults (void);
170
+
171
+
172
+ /* DEPRECATED interfaces */
173
+ XMLPUBFUN const xmlChar *
174
+ xmlCatalogGetSystem (const xmlChar *sysID);
175
+ XMLPUBFUN const xmlChar *
176
+ xmlCatalogGetPublic (const xmlChar *pubID);
177
+
178
+ #ifdef __cplusplus
179
+ }
180
+ #endif
181
+ #endif /* LIBXML_CATALOG_ENABLED */
182
+ #endif /* __XML_CATALOG_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/chvalid.h ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: Unicode character range checking
3
+ * Description: this module exports interfaces for the character
4
+ * range validation APIs
5
+ *
6
+ * This file is automatically generated from the cvs source
7
+ * definition files using the genChRanges.py Python script
8
+ *
9
+ * Generation date: Mon Mar 27 11:09:48 2006
10
+ * Sources: chvalid.def
11
+ * Author: William Brack <[email protected]>
12
+ */
13
+
14
+ #ifndef __XML_CHVALID_H__
15
+ #define __XML_CHVALID_H__
16
+
17
+ #include <libxml/xmlversion.h>
18
+ #include <libxml/xmlstring.h>
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ /*
25
+ * Define our typedefs and structures
26
+ *
27
+ */
28
+ typedef struct _xmlChSRange xmlChSRange;
29
+ typedef xmlChSRange *xmlChSRangePtr;
30
+ struct _xmlChSRange {
31
+ unsigned short low;
32
+ unsigned short high;
33
+ };
34
+
35
+ typedef struct _xmlChLRange xmlChLRange;
36
+ typedef xmlChLRange *xmlChLRangePtr;
37
+ struct _xmlChLRange {
38
+ unsigned int low;
39
+ unsigned int high;
40
+ };
41
+
42
+ typedef struct _xmlChRangeGroup xmlChRangeGroup;
43
+ typedef xmlChRangeGroup *xmlChRangeGroupPtr;
44
+ struct _xmlChRangeGroup {
45
+ int nbShortRange;
46
+ int nbLongRange;
47
+ const xmlChSRange *shortRange; /* points to an array of ranges */
48
+ const xmlChLRange *longRange;
49
+ };
50
+
51
+ /**
52
+ * Range checking routine
53
+ */
54
+ XMLPUBFUN int
55
+ xmlCharInRange(unsigned int val, const xmlChRangeGroup *group);
56
+
57
+
58
+ /**
59
+ * xmlIsBaseChar_ch:
60
+ * @c: char to validate
61
+ *
62
+ * Automatically generated by genChRanges.py
63
+ */
64
+ #define xmlIsBaseChar_ch(c) (((0x41 <= (c)) && ((c) <= 0x5a)) || \
65
+ ((0x61 <= (c)) && ((c) <= 0x7a)) || \
66
+ ((0xc0 <= (c)) && ((c) <= 0xd6)) || \
67
+ ((0xd8 <= (c)) && ((c) <= 0xf6)) || \
68
+ (0xf8 <= (c)))
69
+
70
+ /**
71
+ * xmlIsBaseCharQ:
72
+ * @c: char to validate
73
+ *
74
+ * Automatically generated by genChRanges.py
75
+ */
76
+ #define xmlIsBaseCharQ(c) (((c) < 0x100) ? \
77
+ xmlIsBaseChar_ch((c)) : \
78
+ xmlCharInRange((c), &xmlIsBaseCharGroup))
79
+
80
+ XMLPUBVAR const xmlChRangeGroup xmlIsBaseCharGroup;
81
+
82
+ /**
83
+ * xmlIsBlank_ch:
84
+ * @c: char to validate
85
+ *
86
+ * Automatically generated by genChRanges.py
87
+ */
88
+ #define xmlIsBlank_ch(c) (((c) == 0x20) || \
89
+ ((0x9 <= (c)) && ((c) <= 0xa)) || \
90
+ ((c) == 0xd))
91
+
92
+ /**
93
+ * xmlIsBlankQ:
94
+ * @c: char to validate
95
+ *
96
+ * Automatically generated by genChRanges.py
97
+ */
98
+ #define xmlIsBlankQ(c) (((c) < 0x100) ? \
99
+ xmlIsBlank_ch((c)) : 0)
100
+
101
+
102
+ /**
103
+ * xmlIsChar_ch:
104
+ * @c: char to validate
105
+ *
106
+ * Automatically generated by genChRanges.py
107
+ */
108
+ #define xmlIsChar_ch(c) (((0x9 <= (c)) && ((c) <= 0xa)) || \
109
+ ((c) == 0xd) || \
110
+ (0x20 <= (c)))
111
+
112
+ /**
113
+ * xmlIsCharQ:
114
+ * @c: char to validate
115
+ *
116
+ * Automatically generated by genChRanges.py
117
+ */
118
+ #define xmlIsCharQ(c) (((c) < 0x100) ? \
119
+ xmlIsChar_ch((c)) :\
120
+ (((0x100 <= (c)) && ((c) <= 0xd7ff)) || \
121
+ ((0xe000 <= (c)) && ((c) <= 0xfffd)) || \
122
+ ((0x10000 <= (c)) && ((c) <= 0x10ffff))))
123
+
124
+ XMLPUBVAR const xmlChRangeGroup xmlIsCharGroup;
125
+
126
+ /**
127
+ * xmlIsCombiningQ:
128
+ * @c: char to validate
129
+ *
130
+ * Automatically generated by genChRanges.py
131
+ */
132
+ #define xmlIsCombiningQ(c) (((c) < 0x100) ? \
133
+ 0 : \
134
+ xmlCharInRange((c), &xmlIsCombiningGroup))
135
+
136
+ XMLPUBVAR const xmlChRangeGroup xmlIsCombiningGroup;
137
+
138
+ /**
139
+ * xmlIsDigit_ch:
140
+ * @c: char to validate
141
+ *
142
+ * Automatically generated by genChRanges.py
143
+ */
144
+ #define xmlIsDigit_ch(c) (((0x30 <= (c)) && ((c) <= 0x39)))
145
+
146
+ /**
147
+ * xmlIsDigitQ:
148
+ * @c: char to validate
149
+ *
150
+ * Automatically generated by genChRanges.py
151
+ */
152
+ #define xmlIsDigitQ(c) (((c) < 0x100) ? \
153
+ xmlIsDigit_ch((c)) : \
154
+ xmlCharInRange((c), &xmlIsDigitGroup))
155
+
156
+ XMLPUBVAR const xmlChRangeGroup xmlIsDigitGroup;
157
+
158
+ /**
159
+ * xmlIsExtender_ch:
160
+ * @c: char to validate
161
+ *
162
+ * Automatically generated by genChRanges.py
163
+ */
164
+ #define xmlIsExtender_ch(c) (((c) == 0xb7))
165
+
166
+ /**
167
+ * xmlIsExtenderQ:
168
+ * @c: char to validate
169
+ *
170
+ * Automatically generated by genChRanges.py
171
+ */
172
+ #define xmlIsExtenderQ(c) (((c) < 0x100) ? \
173
+ xmlIsExtender_ch((c)) : \
174
+ xmlCharInRange((c), &xmlIsExtenderGroup))
175
+
176
+ XMLPUBVAR const xmlChRangeGroup xmlIsExtenderGroup;
177
+
178
+ /**
179
+ * xmlIsIdeographicQ:
180
+ * @c: char to validate
181
+ *
182
+ * Automatically generated by genChRanges.py
183
+ */
184
+ #define xmlIsIdeographicQ(c) (((c) < 0x100) ? \
185
+ 0 :\
186
+ (((0x4e00 <= (c)) && ((c) <= 0x9fa5)) || \
187
+ ((c) == 0x3007) || \
188
+ ((0x3021 <= (c)) && ((c) <= 0x3029))))
189
+
190
+ XMLPUBVAR const xmlChRangeGroup xmlIsIdeographicGroup;
191
+ XMLPUBVAR const unsigned char xmlIsPubidChar_tab[256];
192
+
193
+ /**
194
+ * xmlIsPubidChar_ch:
195
+ * @c: char to validate
196
+ *
197
+ * Automatically generated by genChRanges.py
198
+ */
199
+ #define xmlIsPubidChar_ch(c) (xmlIsPubidChar_tab[(c)])
200
+
201
+ /**
202
+ * xmlIsPubidCharQ:
203
+ * @c: char to validate
204
+ *
205
+ * Automatically generated by genChRanges.py
206
+ */
207
+ #define xmlIsPubidCharQ(c) (((c) < 0x100) ? \
208
+ xmlIsPubidChar_ch((c)) : 0)
209
+
210
+ XMLPUBFUN int
211
+ xmlIsBaseChar(unsigned int ch);
212
+ XMLPUBFUN int
213
+ xmlIsBlank(unsigned int ch);
214
+ XMLPUBFUN int
215
+ xmlIsChar(unsigned int ch);
216
+ XMLPUBFUN int
217
+ xmlIsCombining(unsigned int ch);
218
+ XMLPUBFUN int
219
+ xmlIsDigit(unsigned int ch);
220
+ XMLPUBFUN int
221
+ xmlIsExtender(unsigned int ch);
222
+ XMLPUBFUN int
223
+ xmlIsIdeographic(unsigned int ch);
224
+ XMLPUBFUN int
225
+ xmlIsPubidChar(unsigned int ch);
226
+
227
+ #ifdef __cplusplus
228
+ }
229
+ #endif
230
+ #endif /* __XML_CHVALID_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/debugXML.h ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: Tree debugging APIs
3
+ * Description: Interfaces to a set of routines used for debugging the tree
4
+ * produced by the XML parser.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __DEBUG_XML__
12
+ #define __DEBUG_XML__
13
+ #include <stdio.h>
14
+ #include <libxml/xmlversion.h>
15
+ #include <libxml/tree.h>
16
+
17
+ #ifdef LIBXML_DEBUG_ENABLED
18
+
19
+ #include <libxml/xpath.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /*
26
+ * The standard Dump routines.
27
+ */
28
+ XMLPUBFUN void
29
+ xmlDebugDumpString (FILE *output,
30
+ const xmlChar *str);
31
+ XMLPUBFUN void
32
+ xmlDebugDumpAttr (FILE *output,
33
+ xmlAttrPtr attr,
34
+ int depth);
35
+ XMLPUBFUN void
36
+ xmlDebugDumpAttrList (FILE *output,
37
+ xmlAttrPtr attr,
38
+ int depth);
39
+ XMLPUBFUN void
40
+ xmlDebugDumpOneNode (FILE *output,
41
+ xmlNodePtr node,
42
+ int depth);
43
+ XMLPUBFUN void
44
+ xmlDebugDumpNode (FILE *output,
45
+ xmlNodePtr node,
46
+ int depth);
47
+ XMLPUBFUN void
48
+ xmlDebugDumpNodeList (FILE *output,
49
+ xmlNodePtr node,
50
+ int depth);
51
+ XMLPUBFUN void
52
+ xmlDebugDumpDocumentHead(FILE *output,
53
+ xmlDocPtr doc);
54
+ XMLPUBFUN void
55
+ xmlDebugDumpDocument (FILE *output,
56
+ xmlDocPtr doc);
57
+ XMLPUBFUN void
58
+ xmlDebugDumpDTD (FILE *output,
59
+ xmlDtdPtr dtd);
60
+ XMLPUBFUN void
61
+ xmlDebugDumpEntities (FILE *output,
62
+ xmlDocPtr doc);
63
+
64
+ /****************************************************************
65
+ * *
66
+ * Checking routines *
67
+ * *
68
+ ****************************************************************/
69
+
70
+ XMLPUBFUN int
71
+ xmlDebugCheckDocument (FILE * output,
72
+ xmlDocPtr doc);
73
+
74
+ /****************************************************************
75
+ * *
76
+ * XML shell helpers *
77
+ * *
78
+ ****************************************************************/
79
+
80
+ XMLPUBFUN void
81
+ xmlLsOneNode (FILE *output, xmlNodePtr node);
82
+ XMLPUBFUN int
83
+ xmlLsCountNode (xmlNodePtr node);
84
+
85
+ XMLPUBFUN const char *
86
+ xmlBoolToText (int boolval);
87
+
88
+ /****************************************************************
89
+ * *
90
+ * The XML shell related structures and functions *
91
+ * *
92
+ ****************************************************************/
93
+
94
+ #ifdef LIBXML_XPATH_ENABLED
95
+ /**
96
+ * xmlShellReadlineFunc:
97
+ * @prompt: a string prompt
98
+ *
99
+ * This is a generic signature for the XML shell input function.
100
+ *
101
+ * Returns a string which will be freed by the Shell.
102
+ */
103
+ typedef char * (* xmlShellReadlineFunc)(char *prompt);
104
+
105
+ /**
106
+ * xmlShellCtxt:
107
+ *
108
+ * A debugging shell context.
109
+ * TODO: add the defined function tables.
110
+ */
111
+ typedef struct _xmlShellCtxt xmlShellCtxt;
112
+ typedef xmlShellCtxt *xmlShellCtxtPtr;
113
+ struct _xmlShellCtxt {
114
+ char *filename;
115
+ xmlDocPtr doc;
116
+ xmlNodePtr node;
117
+ xmlXPathContextPtr pctxt;
118
+ int loaded;
119
+ FILE *output;
120
+ xmlShellReadlineFunc input;
121
+ };
122
+
123
+ /**
124
+ * xmlShellCmd:
125
+ * @ctxt: a shell context
126
+ * @arg: a string argument
127
+ * @node: a first node
128
+ * @node2: a second node
129
+ *
130
+ * This is a generic signature for the XML shell functions.
131
+ *
132
+ * Returns an int, negative returns indicating errors.
133
+ */
134
+ typedef int (* xmlShellCmd) (xmlShellCtxtPtr ctxt,
135
+ char *arg,
136
+ xmlNodePtr node,
137
+ xmlNodePtr node2);
138
+
139
+ XMLPUBFUN void
140
+ xmlShellPrintXPathError (int errorType,
141
+ const char *arg);
142
+ XMLPUBFUN void
143
+ xmlShellPrintXPathResult(xmlXPathObjectPtr list);
144
+ XMLPUBFUN int
145
+ xmlShellList (xmlShellCtxtPtr ctxt,
146
+ char *arg,
147
+ xmlNodePtr node,
148
+ xmlNodePtr node2);
149
+ XMLPUBFUN int
150
+ xmlShellBase (xmlShellCtxtPtr ctxt,
151
+ char *arg,
152
+ xmlNodePtr node,
153
+ xmlNodePtr node2);
154
+ XMLPUBFUN int
155
+ xmlShellDir (xmlShellCtxtPtr ctxt,
156
+ char *arg,
157
+ xmlNodePtr node,
158
+ xmlNodePtr node2);
159
+ XMLPUBFUN int
160
+ xmlShellLoad (xmlShellCtxtPtr ctxt,
161
+ char *filename,
162
+ xmlNodePtr node,
163
+ xmlNodePtr node2);
164
+ #ifdef LIBXML_OUTPUT_ENABLED
165
+ XMLPUBFUN void
166
+ xmlShellPrintNode (xmlNodePtr node);
167
+ XMLPUBFUN int
168
+ xmlShellCat (xmlShellCtxtPtr ctxt,
169
+ char *arg,
170
+ xmlNodePtr node,
171
+ xmlNodePtr node2);
172
+ XMLPUBFUN int
173
+ xmlShellWrite (xmlShellCtxtPtr ctxt,
174
+ char *filename,
175
+ xmlNodePtr node,
176
+ xmlNodePtr node2);
177
+ XMLPUBFUN int
178
+ xmlShellSave (xmlShellCtxtPtr ctxt,
179
+ char *filename,
180
+ xmlNodePtr node,
181
+ xmlNodePtr node2);
182
+ #endif /* LIBXML_OUTPUT_ENABLED */
183
+ #ifdef LIBXML_VALID_ENABLED
184
+ XMLPUBFUN int
185
+ xmlShellValidate (xmlShellCtxtPtr ctxt,
186
+ char *dtd,
187
+ xmlNodePtr node,
188
+ xmlNodePtr node2);
189
+ #endif /* LIBXML_VALID_ENABLED */
190
+ XMLPUBFUN int
191
+ xmlShellDu (xmlShellCtxtPtr ctxt,
192
+ char *arg,
193
+ xmlNodePtr tree,
194
+ xmlNodePtr node2);
195
+ XMLPUBFUN int
196
+ xmlShellPwd (xmlShellCtxtPtr ctxt,
197
+ char *buffer,
198
+ xmlNodePtr node,
199
+ xmlNodePtr node2);
200
+
201
+ /*
202
+ * The Shell interface.
203
+ */
204
+ XMLPUBFUN void
205
+ xmlShell (xmlDocPtr doc,
206
+ char *filename,
207
+ xmlShellReadlineFunc input,
208
+ FILE *output);
209
+
210
+ #endif /* LIBXML_XPATH_ENABLED */
211
+
212
+ #ifdef __cplusplus
213
+ }
214
+ #endif
215
+
216
+ #endif /* LIBXML_DEBUG_ENABLED */
217
+ #endif /* __DEBUG_XML__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/dict.h ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: string dictionary
3
+ * Description: dictionary of reusable strings, just used to avoid allocation
4
+ * and freeing operations.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __XML_DICT_H__
12
+ #define __XML_DICT_H__
13
+
14
+ #include <stddef.h>
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/xmlstring.h>
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+
22
+ /*
23
+ * The dictionary.
24
+ */
25
+ typedef struct _xmlDict xmlDict;
26
+ typedef xmlDict *xmlDictPtr;
27
+
28
+ /*
29
+ * Initializer
30
+ */
31
+ XML_DEPRECATED
32
+ XMLPUBFUN int xmlInitializeDict(void);
33
+
34
+ /*
35
+ * Constructor and destructor.
36
+ */
37
+ XMLPUBFUN xmlDictPtr
38
+ xmlDictCreate (void);
39
+ XMLPUBFUN size_t
40
+ xmlDictSetLimit (xmlDictPtr dict,
41
+ size_t limit);
42
+ XMLPUBFUN size_t
43
+ xmlDictGetUsage (xmlDictPtr dict);
44
+ XMLPUBFUN xmlDictPtr
45
+ xmlDictCreateSub(xmlDictPtr sub);
46
+ XMLPUBFUN int
47
+ xmlDictReference(xmlDictPtr dict);
48
+ XMLPUBFUN void
49
+ xmlDictFree (xmlDictPtr dict);
50
+
51
+ /*
52
+ * Lookup of entry in the dictionary.
53
+ */
54
+ XMLPUBFUN const xmlChar *
55
+ xmlDictLookup (xmlDictPtr dict,
56
+ const xmlChar *name,
57
+ int len);
58
+ XMLPUBFUN const xmlChar *
59
+ xmlDictExists (xmlDictPtr dict,
60
+ const xmlChar *name,
61
+ int len);
62
+ XMLPUBFUN const xmlChar *
63
+ xmlDictQLookup (xmlDictPtr dict,
64
+ const xmlChar *prefix,
65
+ const xmlChar *name);
66
+ XMLPUBFUN int
67
+ xmlDictOwns (xmlDictPtr dict,
68
+ const xmlChar *str);
69
+ XMLPUBFUN int
70
+ xmlDictSize (xmlDictPtr dict);
71
+
72
+ /*
73
+ * Cleanup function
74
+ */
75
+ XML_DEPRECATED
76
+ XMLPUBFUN void
77
+ xmlDictCleanup (void);
78
+
79
+ #ifdef __cplusplus
80
+ }
81
+ #endif
82
+ #endif /* ! __XML_DICT_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/entities.h ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: interface for the XML entities handling
3
+ * Description: this module provides some of the entity API needed
4
+ * for the parser and applications.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __XML_ENTITIES_H__
12
+ #define __XML_ENTITIES_H__
13
+
14
+ #include <libxml/xmlversion.h>
15
+ #define XML_TREE_INTERNALS
16
+ #include <libxml/tree.h>
17
+ #undef XML_TREE_INTERNALS
18
+
19
+ #ifdef __cplusplus
20
+ extern "C" {
21
+ #endif
22
+
23
+ /*
24
+ * The different valid entity types.
25
+ */
26
+ typedef enum {
27
+ XML_INTERNAL_GENERAL_ENTITY = 1,
28
+ XML_EXTERNAL_GENERAL_PARSED_ENTITY = 2,
29
+ XML_EXTERNAL_GENERAL_UNPARSED_ENTITY = 3,
30
+ XML_INTERNAL_PARAMETER_ENTITY = 4,
31
+ XML_EXTERNAL_PARAMETER_ENTITY = 5,
32
+ XML_INTERNAL_PREDEFINED_ENTITY = 6
33
+ } xmlEntityType;
34
+
35
+ /*
36
+ * An unit of storage for an entity, contains the string, the value
37
+ * and the linkind data needed for the linking in the hash table.
38
+ */
39
+
40
+ struct _xmlEntity {
41
+ void *_private; /* application data */
42
+ xmlElementType type; /* XML_ENTITY_DECL, must be second ! */
43
+ const xmlChar *name; /* Entity name */
44
+ struct _xmlNode *children; /* First child link */
45
+ struct _xmlNode *last; /* Last child link */
46
+ struct _xmlDtd *parent; /* -> DTD */
47
+ struct _xmlNode *next; /* next sibling link */
48
+ struct _xmlNode *prev; /* previous sibling link */
49
+ struct _xmlDoc *doc; /* the containing document */
50
+
51
+ xmlChar *orig; /* content without ref substitution */
52
+ xmlChar *content; /* content or ndata if unparsed */
53
+ int length; /* the content length */
54
+ xmlEntityType etype; /* The entity type */
55
+ const xmlChar *ExternalID; /* External identifier for PUBLIC */
56
+ const xmlChar *SystemID; /* URI for a SYSTEM or PUBLIC Entity */
57
+
58
+ struct _xmlEntity *nexte; /* unused */
59
+ const xmlChar *URI; /* the full URI as computed */
60
+ int owner; /* does the entity own the childrens */
61
+ int flags; /* various flags */
62
+ unsigned long expandedSize; /* expanded size */
63
+ };
64
+
65
+ /*
66
+ * All entities are stored in an hash table.
67
+ * There is 2 separate hash tables for global and parameter entities.
68
+ */
69
+
70
+ typedef struct _xmlHashTable xmlEntitiesTable;
71
+ typedef xmlEntitiesTable *xmlEntitiesTablePtr;
72
+
73
+ /*
74
+ * External functions:
75
+ */
76
+
77
+ #ifdef LIBXML_LEGACY_ENABLED
78
+ XML_DEPRECATED
79
+ XMLPUBFUN void
80
+ xmlInitializePredefinedEntities (void);
81
+ #endif /* LIBXML_LEGACY_ENABLED */
82
+
83
+ XMLPUBFUN xmlEntityPtr
84
+ xmlNewEntity (xmlDocPtr doc,
85
+ const xmlChar *name,
86
+ int type,
87
+ const xmlChar *ExternalID,
88
+ const xmlChar *SystemID,
89
+ const xmlChar *content);
90
+ XMLPUBFUN void
91
+ xmlFreeEntity (xmlEntityPtr entity);
92
+ XMLPUBFUN xmlEntityPtr
93
+ xmlAddDocEntity (xmlDocPtr doc,
94
+ const xmlChar *name,
95
+ int type,
96
+ const xmlChar *ExternalID,
97
+ const xmlChar *SystemID,
98
+ const xmlChar *content);
99
+ XMLPUBFUN xmlEntityPtr
100
+ xmlAddDtdEntity (xmlDocPtr doc,
101
+ const xmlChar *name,
102
+ int type,
103
+ const xmlChar *ExternalID,
104
+ const xmlChar *SystemID,
105
+ const xmlChar *content);
106
+ XMLPUBFUN xmlEntityPtr
107
+ xmlGetPredefinedEntity (const xmlChar *name);
108
+ XMLPUBFUN xmlEntityPtr
109
+ xmlGetDocEntity (const xmlDoc *doc,
110
+ const xmlChar *name);
111
+ XMLPUBFUN xmlEntityPtr
112
+ xmlGetDtdEntity (xmlDocPtr doc,
113
+ const xmlChar *name);
114
+ XMLPUBFUN xmlEntityPtr
115
+ xmlGetParameterEntity (xmlDocPtr doc,
116
+ const xmlChar *name);
117
+ #ifdef LIBXML_LEGACY_ENABLED
118
+ XML_DEPRECATED
119
+ XMLPUBFUN const xmlChar *
120
+ xmlEncodeEntities (xmlDocPtr doc,
121
+ const xmlChar *input);
122
+ #endif /* LIBXML_LEGACY_ENABLED */
123
+ XMLPUBFUN xmlChar *
124
+ xmlEncodeEntitiesReentrant(xmlDocPtr doc,
125
+ const xmlChar *input);
126
+ XMLPUBFUN xmlChar *
127
+ xmlEncodeSpecialChars (const xmlDoc *doc,
128
+ const xmlChar *input);
129
+ XMLPUBFUN xmlEntitiesTablePtr
130
+ xmlCreateEntitiesTable (void);
131
+ #ifdef LIBXML_TREE_ENABLED
132
+ XMLPUBFUN xmlEntitiesTablePtr
133
+ xmlCopyEntitiesTable (xmlEntitiesTablePtr table);
134
+ #endif /* LIBXML_TREE_ENABLED */
135
+ XMLPUBFUN void
136
+ xmlFreeEntitiesTable (xmlEntitiesTablePtr table);
137
+ #ifdef LIBXML_OUTPUT_ENABLED
138
+ XMLPUBFUN void
139
+ xmlDumpEntitiesTable (xmlBufferPtr buf,
140
+ xmlEntitiesTablePtr table);
141
+ XMLPUBFUN void
142
+ xmlDumpEntityDecl (xmlBufferPtr buf,
143
+ xmlEntityPtr ent);
144
+ #endif /* LIBXML_OUTPUT_ENABLED */
145
+ #ifdef LIBXML_LEGACY_ENABLED
146
+ XMLPUBFUN void
147
+ xmlCleanupPredefinedEntities(void);
148
+ #endif /* LIBXML_LEGACY_ENABLED */
149
+
150
+
151
+ #ifdef __cplusplus
152
+ }
153
+ #endif
154
+
155
+ # endif /* __XML_ENTITIES_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/globals.h ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: interface for all global variables of the library
3
+ * Description: Deprecated, don't use
4
+ *
5
+ * Copy: See Copyright for the status of this software.
6
+ */
7
+
8
+ #ifndef __XML_GLOBALS_H
9
+ #define __XML_GLOBALS_H
10
+
11
+ #include <libxml/xmlversion.h>
12
+
13
+ /*
14
+ * This file was required to access global variables until version v2.12.0.
15
+ *
16
+ * These includes are for backward compatibility.
17
+ */
18
+ #include <libxml/HTMLparser.h>
19
+ #include <libxml/parser.h>
20
+ #include <libxml/xmlerror.h>
21
+ #include <libxml/xmlIO.h>
22
+ #include <libxml/xmlsave.h>
23
+ #include <libxml/threads.h>
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ typedef struct _xmlGlobalState xmlGlobalState;
30
+ typedef xmlGlobalState *xmlGlobalStatePtr;
31
+
32
+ XML_DEPRECATED XMLPUBFUN void
33
+ xmlInitializeGlobalState(xmlGlobalStatePtr gs);
34
+ XML_DEPRECATED XMLPUBFUN
35
+ xmlGlobalStatePtr xmlGetGlobalState(void);
36
+
37
+ #ifdef __cplusplus
38
+ }
39
+ #endif
40
+
41
+ #endif /* __XML_GLOBALS_H */
venv/lib/python3.10/site-packages/lxml/includes/libxml/list.h ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: lists interfaces
3
+ * Description: this module implement the list support used in
4
+ * various place in the library.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Gary Pennington <[email protected]>
9
+ */
10
+
11
+ #ifndef __XML_LINK_INCLUDE__
12
+ #define __XML_LINK_INCLUDE__
13
+
14
+ #include <libxml/xmlversion.h>
15
+
16
+ #ifdef __cplusplus
17
+ extern "C" {
18
+ #endif
19
+
20
+ typedef struct _xmlLink xmlLink;
21
+ typedef xmlLink *xmlLinkPtr;
22
+
23
+ typedef struct _xmlList xmlList;
24
+ typedef xmlList *xmlListPtr;
25
+
26
+ /**
27
+ * xmlListDeallocator:
28
+ * @lk: the data to deallocate
29
+ *
30
+ * Callback function used to free data from a list.
31
+ */
32
+ typedef void (*xmlListDeallocator) (xmlLinkPtr lk);
33
+ /**
34
+ * xmlListDataCompare:
35
+ * @data0: the first data
36
+ * @data1: the second data
37
+ *
38
+ * Callback function used to compare 2 data.
39
+ *
40
+ * Returns 0 is equality, -1 or 1 otherwise depending on the ordering.
41
+ */
42
+ typedef int (*xmlListDataCompare) (const void *data0, const void *data1);
43
+ /**
44
+ * xmlListWalker:
45
+ * @data: the data found in the list
46
+ * @user: extra user provided data to the walker
47
+ *
48
+ * Callback function used when walking a list with xmlListWalk().
49
+ *
50
+ * Returns 0 to stop walking the list, 1 otherwise.
51
+ */
52
+ typedef int (*xmlListWalker) (const void *data, void *user);
53
+
54
+ /* Creation/Deletion */
55
+ XMLPUBFUN xmlListPtr
56
+ xmlListCreate (xmlListDeallocator deallocator,
57
+ xmlListDataCompare compare);
58
+ XMLPUBFUN void
59
+ xmlListDelete (xmlListPtr l);
60
+
61
+ /* Basic Operators */
62
+ XMLPUBFUN void *
63
+ xmlListSearch (xmlListPtr l,
64
+ void *data);
65
+ XMLPUBFUN void *
66
+ xmlListReverseSearch (xmlListPtr l,
67
+ void *data);
68
+ XMLPUBFUN int
69
+ xmlListInsert (xmlListPtr l,
70
+ void *data) ;
71
+ XMLPUBFUN int
72
+ xmlListAppend (xmlListPtr l,
73
+ void *data) ;
74
+ XMLPUBFUN int
75
+ xmlListRemoveFirst (xmlListPtr l,
76
+ void *data);
77
+ XMLPUBFUN int
78
+ xmlListRemoveLast (xmlListPtr l,
79
+ void *data);
80
+ XMLPUBFUN int
81
+ xmlListRemoveAll (xmlListPtr l,
82
+ void *data);
83
+ XMLPUBFUN void
84
+ xmlListClear (xmlListPtr l);
85
+ XMLPUBFUN int
86
+ xmlListEmpty (xmlListPtr l);
87
+ XMLPUBFUN xmlLinkPtr
88
+ xmlListFront (xmlListPtr l);
89
+ XMLPUBFUN xmlLinkPtr
90
+ xmlListEnd (xmlListPtr l);
91
+ XMLPUBFUN int
92
+ xmlListSize (xmlListPtr l);
93
+
94
+ XMLPUBFUN void
95
+ xmlListPopFront (xmlListPtr l);
96
+ XMLPUBFUN void
97
+ xmlListPopBack (xmlListPtr l);
98
+ XMLPUBFUN int
99
+ xmlListPushFront (xmlListPtr l,
100
+ void *data);
101
+ XMLPUBFUN int
102
+ xmlListPushBack (xmlListPtr l,
103
+ void *data);
104
+
105
+ /* Advanced Operators */
106
+ XMLPUBFUN void
107
+ xmlListReverse (xmlListPtr l);
108
+ XMLPUBFUN void
109
+ xmlListSort (xmlListPtr l);
110
+ XMLPUBFUN void
111
+ xmlListWalk (xmlListPtr l,
112
+ xmlListWalker walker,
113
+ void *user);
114
+ XMLPUBFUN void
115
+ xmlListReverseWalk (xmlListPtr l,
116
+ xmlListWalker walker,
117
+ void *user);
118
+ XMLPUBFUN void
119
+ xmlListMerge (xmlListPtr l1,
120
+ xmlListPtr l2);
121
+ XMLPUBFUN xmlListPtr
122
+ xmlListDup (const xmlListPtr old);
123
+ XMLPUBFUN int
124
+ xmlListCopy (xmlListPtr cur,
125
+ const xmlListPtr old);
126
+ /* Link operators */
127
+ XMLPUBFUN void *
128
+ xmlLinkGetData (xmlLinkPtr lk);
129
+
130
+ /* xmlListUnique() */
131
+ /* xmlListSwap */
132
+
133
+ #ifdef __cplusplus
134
+ }
135
+ #endif
136
+
137
+ #endif /* __XML_LINK_INCLUDE__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/nanoftp.h ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: minimal FTP implementation
3
+ * Description: minimal FTP implementation allowing to fetch resources
4
+ * like external subset. This module is DEPRECATED, do not
5
+ * use any of its functions.
6
+ *
7
+ * Copy: See Copyright for the status of this software.
8
+ *
9
+ * Author: Daniel Veillard
10
+ */
11
+
12
+ #ifndef __NANO_FTP_H__
13
+ #define __NANO_FTP_H__
14
+
15
+ #include <libxml/xmlversion.h>
16
+
17
+ #if defined(LIBXML_FTP_ENABLED)
18
+
19
+ /* Needed for portability to Windows 64 bits */
20
+ #if defined(_WIN32)
21
+ #include <winsock2.h>
22
+ #else
23
+ /**
24
+ * SOCKET:
25
+ *
26
+ * macro used to provide portability of code to windows sockets
27
+ */
28
+ #define SOCKET int
29
+ /**
30
+ * INVALID_SOCKET:
31
+ *
32
+ * macro used to provide portability of code to windows sockets
33
+ * the value to be used when the socket is not valid
34
+ */
35
+ #undef INVALID_SOCKET
36
+ #define INVALID_SOCKET (-1)
37
+ #endif
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /**
44
+ * ftpListCallback:
45
+ * @userData: user provided data for the callback
46
+ * @filename: the file name (including "->" when links are shown)
47
+ * @attrib: the attribute string
48
+ * @owner: the owner string
49
+ * @group: the group string
50
+ * @size: the file size
51
+ * @links: the link count
52
+ * @year: the year
53
+ * @month: the month
54
+ * @day: the day
55
+ * @hour: the hour
56
+ * @minute: the minute
57
+ *
58
+ * A callback for the xmlNanoFTPList command.
59
+ * Note that only one of year and day:minute are specified.
60
+ */
61
+ typedef void (*ftpListCallback) (void *userData,
62
+ const char *filename, const char *attrib,
63
+ const char *owner, const char *group,
64
+ unsigned long size, int links, int year,
65
+ const char *month, int day, int hour,
66
+ int minute);
67
+ /**
68
+ * ftpDataCallback:
69
+ * @userData: the user provided context
70
+ * @data: the data received
71
+ * @len: its size in bytes
72
+ *
73
+ * A callback for the xmlNanoFTPGet command.
74
+ */
75
+ typedef void (*ftpDataCallback) (void *userData,
76
+ const char *data,
77
+ int len);
78
+
79
+ /*
80
+ * Init
81
+ */
82
+ XML_DEPRECATED
83
+ XMLPUBFUN void
84
+ xmlNanoFTPInit (void);
85
+ XML_DEPRECATED
86
+ XMLPUBFUN void
87
+ xmlNanoFTPCleanup (void);
88
+
89
+ /*
90
+ * Creating/freeing contexts.
91
+ */
92
+ XML_DEPRECATED
93
+ XMLPUBFUN void *
94
+ xmlNanoFTPNewCtxt (const char *URL);
95
+ XML_DEPRECATED
96
+ XMLPUBFUN void
97
+ xmlNanoFTPFreeCtxt (void * ctx);
98
+ XML_DEPRECATED
99
+ XMLPUBFUN void *
100
+ xmlNanoFTPConnectTo (const char *server,
101
+ int port);
102
+ /*
103
+ * Opening/closing session connections.
104
+ */
105
+ XML_DEPRECATED
106
+ XMLPUBFUN void *
107
+ xmlNanoFTPOpen (const char *URL);
108
+ XML_DEPRECATED
109
+ XMLPUBFUN int
110
+ xmlNanoFTPConnect (void *ctx);
111
+ XML_DEPRECATED
112
+ XMLPUBFUN int
113
+ xmlNanoFTPClose (void *ctx);
114
+ XML_DEPRECATED
115
+ XMLPUBFUN int
116
+ xmlNanoFTPQuit (void *ctx);
117
+ XML_DEPRECATED
118
+ XMLPUBFUN void
119
+ xmlNanoFTPScanProxy (const char *URL);
120
+ XML_DEPRECATED
121
+ XMLPUBFUN void
122
+ xmlNanoFTPProxy (const char *host,
123
+ int port,
124
+ const char *user,
125
+ const char *passwd,
126
+ int type);
127
+ XML_DEPRECATED
128
+ XMLPUBFUN int
129
+ xmlNanoFTPUpdateURL (void *ctx,
130
+ const char *URL);
131
+
132
+ /*
133
+ * Rather internal commands.
134
+ */
135
+ XML_DEPRECATED
136
+ XMLPUBFUN int
137
+ xmlNanoFTPGetResponse (void *ctx);
138
+ XML_DEPRECATED
139
+ XMLPUBFUN int
140
+ xmlNanoFTPCheckResponse (void *ctx);
141
+
142
+ /*
143
+ * CD/DIR/GET handlers.
144
+ */
145
+ XML_DEPRECATED
146
+ XMLPUBFUN int
147
+ xmlNanoFTPCwd (void *ctx,
148
+ const char *directory);
149
+ XML_DEPRECATED
150
+ XMLPUBFUN int
151
+ xmlNanoFTPDele (void *ctx,
152
+ const char *file);
153
+
154
+ XML_DEPRECATED
155
+ XMLPUBFUN SOCKET
156
+ xmlNanoFTPGetConnection (void *ctx);
157
+ XML_DEPRECATED
158
+ XMLPUBFUN int
159
+ xmlNanoFTPCloseConnection(void *ctx);
160
+ XML_DEPRECATED
161
+ XMLPUBFUN int
162
+ xmlNanoFTPList (void *ctx,
163
+ ftpListCallback callback,
164
+ void *userData,
165
+ const char *filename);
166
+ XML_DEPRECATED
167
+ XMLPUBFUN SOCKET
168
+ xmlNanoFTPGetSocket (void *ctx,
169
+ const char *filename);
170
+ XML_DEPRECATED
171
+ XMLPUBFUN int
172
+ xmlNanoFTPGet (void *ctx,
173
+ ftpDataCallback callback,
174
+ void *userData,
175
+ const char *filename);
176
+ XML_DEPRECATED
177
+ XMLPUBFUN int
178
+ xmlNanoFTPRead (void *ctx,
179
+ void *dest,
180
+ int len);
181
+
182
+ #ifdef __cplusplus
183
+ }
184
+ #endif
185
+ #endif /* defined(LIBXML_FTP_ENABLED) || defined(LIBXML_LEGACY_ENABLED) */
186
+ #endif /* __NANO_FTP_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/nanohttp.h ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: minimal HTTP implementation
3
+ * Description: minimal HTTP implementation allowing to fetch resources
4
+ * like external subset.
5
+ *
6
+ * Copy: See Copyright for the status of this software.
7
+ *
8
+ * Author: Daniel Veillard
9
+ */
10
+
11
+ #ifndef __NANO_HTTP_H__
12
+ #define __NANO_HTTP_H__
13
+
14
+ #include <libxml/xmlversion.h>
15
+
16
+ #ifdef LIBXML_HTTP_ENABLED
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #endif
21
+ XMLPUBFUN void
22
+ xmlNanoHTTPInit (void);
23
+ XMLPUBFUN void
24
+ xmlNanoHTTPCleanup (void);
25
+ XMLPUBFUN void
26
+ xmlNanoHTTPScanProxy (const char *URL);
27
+ XMLPUBFUN int
28
+ xmlNanoHTTPFetch (const char *URL,
29
+ const char *filename,
30
+ char **contentType);
31
+ XMLPUBFUN void *
32
+ xmlNanoHTTPMethod (const char *URL,
33
+ const char *method,
34
+ const char *input,
35
+ char **contentType,
36
+ const char *headers,
37
+ int ilen);
38
+ XMLPUBFUN void *
39
+ xmlNanoHTTPMethodRedir (const char *URL,
40
+ const char *method,
41
+ const char *input,
42
+ char **contentType,
43
+ char **redir,
44
+ const char *headers,
45
+ int ilen);
46
+ XMLPUBFUN void *
47
+ xmlNanoHTTPOpen (const char *URL,
48
+ char **contentType);
49
+ XMLPUBFUN void *
50
+ xmlNanoHTTPOpenRedir (const char *URL,
51
+ char **contentType,
52
+ char **redir);
53
+ XMLPUBFUN int
54
+ xmlNanoHTTPReturnCode (void *ctx);
55
+ XMLPUBFUN const char *
56
+ xmlNanoHTTPAuthHeader (void *ctx);
57
+ XMLPUBFUN const char *
58
+ xmlNanoHTTPRedir (void *ctx);
59
+ XMLPUBFUN int
60
+ xmlNanoHTTPContentLength( void * ctx );
61
+ XMLPUBFUN const char *
62
+ xmlNanoHTTPEncoding (void *ctx);
63
+ XMLPUBFUN const char *
64
+ xmlNanoHTTPMimeType (void *ctx);
65
+ XMLPUBFUN int
66
+ xmlNanoHTTPRead (void *ctx,
67
+ void *dest,
68
+ int len);
69
+ #ifdef LIBXML_OUTPUT_ENABLED
70
+ XMLPUBFUN int
71
+ xmlNanoHTTPSave (void *ctxt,
72
+ const char *filename);
73
+ #endif /* LIBXML_OUTPUT_ENABLED */
74
+ XMLPUBFUN void
75
+ xmlNanoHTTPClose (void *ctx);
76
+ #ifdef __cplusplus
77
+ }
78
+ #endif
79
+
80
+ #endif /* LIBXML_HTTP_ENABLED */
81
+ #endif /* __NANO_HTTP_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/parserInternals.h ADDED
@@ -0,0 +1,663 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: internals routines and limits exported by the parser.
3
+ * Description: this module exports a number of internal parsing routines
4
+ * they are not really all intended for applications but
5
+ * can prove useful doing low level processing.
6
+ *
7
+ * Copy: See Copyright for the status of this software.
8
+ *
9
+ * Author: Daniel Veillard
10
+ */
11
+
12
+ #ifndef __XML_PARSER_INTERNALS_H__
13
+ #define __XML_PARSER_INTERNALS_H__
14
+
15
+ #include <libxml/xmlversion.h>
16
+ #include <libxml/parser.h>
17
+ #include <libxml/HTMLparser.h>
18
+ #include <libxml/chvalid.h>
19
+ #include <libxml/SAX2.h>
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+ /**
26
+ * xmlParserMaxDepth:
27
+ *
28
+ * arbitrary depth limit for the XML documents that we allow to
29
+ * process. This is not a limitation of the parser but a safety
30
+ * boundary feature, use XML_PARSE_HUGE option to override it.
31
+ */
32
+ XMLPUBVAR unsigned int xmlParserMaxDepth;
33
+
34
+ /**
35
+ * XML_MAX_TEXT_LENGTH:
36
+ *
37
+ * Maximum size allowed for a single text node when building a tree.
38
+ * This is not a limitation of the parser but a safety boundary feature,
39
+ * use XML_PARSE_HUGE option to override it.
40
+ * Introduced in 2.9.0
41
+ */
42
+ #define XML_MAX_TEXT_LENGTH 10000000
43
+
44
+ /**
45
+ * XML_MAX_HUGE_LENGTH:
46
+ *
47
+ * Maximum size allowed when XML_PARSE_HUGE is set.
48
+ */
49
+ #define XML_MAX_HUGE_LENGTH 1000000000
50
+
51
+ /**
52
+ * XML_MAX_NAME_LENGTH:
53
+ *
54
+ * Maximum size allowed for a markup identifier.
55
+ * This is not a limitation of the parser but a safety boundary feature,
56
+ * use XML_PARSE_HUGE option to override it.
57
+ * Note that with the use of parsing dictionaries overriding the limit
58
+ * may result in more runtime memory usage in face of "unfriendly' content
59
+ * Introduced in 2.9.0
60
+ */
61
+ #define XML_MAX_NAME_LENGTH 50000
62
+
63
+ /**
64
+ * XML_MAX_DICTIONARY_LIMIT:
65
+ *
66
+ * Maximum size allowed by the parser for a dictionary by default
67
+ * This is not a limitation of the parser but a safety boundary feature,
68
+ * use XML_PARSE_HUGE option to override it.
69
+ * Introduced in 2.9.0
70
+ */
71
+ #define XML_MAX_DICTIONARY_LIMIT 10000000
72
+
73
+ /**
74
+ * XML_MAX_LOOKUP_LIMIT:
75
+ *
76
+ * Maximum size allowed by the parser for ahead lookup
77
+ * This is an upper boundary enforced by the parser to avoid bad
78
+ * behaviour on "unfriendly' content
79
+ * Introduced in 2.9.0
80
+ */
81
+ #define XML_MAX_LOOKUP_LIMIT 10000000
82
+
83
+ /**
84
+ * XML_MAX_NAMELEN:
85
+ *
86
+ * Identifiers can be longer, but this will be more costly
87
+ * at runtime.
88
+ */
89
+ #define XML_MAX_NAMELEN 100
90
+
91
+ /**
92
+ * INPUT_CHUNK:
93
+ *
94
+ * The parser tries to always have that amount of input ready.
95
+ * One of the point is providing context when reporting errors.
96
+ */
97
+ #define INPUT_CHUNK 250
98
+
99
+ /************************************************************************
100
+ * *
101
+ * UNICODE version of the macros. *
102
+ * *
103
+ ************************************************************************/
104
+ /**
105
+ * IS_BYTE_CHAR:
106
+ * @c: an byte value (int)
107
+ *
108
+ * Macro to check the following production in the XML spec:
109
+ *
110
+ * [2] Char ::= #x9 | #xA | #xD | [#x20...]
111
+ * any byte character in the accepted range
112
+ */
113
+ #define IS_BYTE_CHAR(c) xmlIsChar_ch(c)
114
+
115
+ /**
116
+ * IS_CHAR:
117
+ * @c: an UNICODE value (int)
118
+ *
119
+ * Macro to check the following production in the XML spec:
120
+ *
121
+ * [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD]
122
+ * | [#x10000-#x10FFFF]
123
+ * any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
124
+ */
125
+ #define IS_CHAR(c) xmlIsCharQ(c)
126
+
127
+ /**
128
+ * IS_CHAR_CH:
129
+ * @c: an xmlChar (usually an unsigned char)
130
+ *
131
+ * Behaves like IS_CHAR on single-byte value
132
+ */
133
+ #define IS_CHAR_CH(c) xmlIsChar_ch(c)
134
+
135
+ /**
136
+ * IS_BLANK:
137
+ * @c: an UNICODE value (int)
138
+ *
139
+ * Macro to check the following production in the XML spec:
140
+ *
141
+ * [3] S ::= (#x20 | #x9 | #xD | #xA)+
142
+ */
143
+ #define IS_BLANK(c) xmlIsBlankQ(c)
144
+
145
+ /**
146
+ * IS_BLANK_CH:
147
+ * @c: an xmlChar value (normally unsigned char)
148
+ *
149
+ * Behaviour same as IS_BLANK
150
+ */
151
+ #define IS_BLANK_CH(c) xmlIsBlank_ch(c)
152
+
153
+ /**
154
+ * IS_BASECHAR:
155
+ * @c: an UNICODE value (int)
156
+ *
157
+ * Macro to check the following production in the XML spec:
158
+ *
159
+ * [85] BaseChar ::= ... long list see REC ...
160
+ */
161
+ #define IS_BASECHAR(c) xmlIsBaseCharQ(c)
162
+
163
+ /**
164
+ * IS_DIGIT:
165
+ * @c: an UNICODE value (int)
166
+ *
167
+ * Macro to check the following production in the XML spec:
168
+ *
169
+ * [88] Digit ::= ... long list see REC ...
170
+ */
171
+ #define IS_DIGIT(c) xmlIsDigitQ(c)
172
+
173
+ /**
174
+ * IS_DIGIT_CH:
175
+ * @c: an xmlChar value (usually an unsigned char)
176
+ *
177
+ * Behaves like IS_DIGIT but with a single byte argument
178
+ */
179
+ #define IS_DIGIT_CH(c) xmlIsDigit_ch(c)
180
+
181
+ /**
182
+ * IS_COMBINING:
183
+ * @c: an UNICODE value (int)
184
+ *
185
+ * Macro to check the following production in the XML spec:
186
+ *
187
+ * [87] CombiningChar ::= ... long list see REC ...
188
+ */
189
+ #define IS_COMBINING(c) xmlIsCombiningQ(c)
190
+
191
+ /**
192
+ * IS_COMBINING_CH:
193
+ * @c: an xmlChar (usually an unsigned char)
194
+ *
195
+ * Always false (all combining chars > 0xff)
196
+ */
197
+ #define IS_COMBINING_CH(c) 0
198
+
199
+ /**
200
+ * IS_EXTENDER:
201
+ * @c: an UNICODE value (int)
202
+ *
203
+ * Macro to check the following production in the XML spec:
204
+ *
205
+ *
206
+ * [89] Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 |
207
+ * #x0E46 | #x0EC6 | #x3005 | [#x3031-#x3035] |
208
+ * [#x309D-#x309E] | [#x30FC-#x30FE]
209
+ */
210
+ #define IS_EXTENDER(c) xmlIsExtenderQ(c)
211
+
212
+ /**
213
+ * IS_EXTENDER_CH:
214
+ * @c: an xmlChar value (usually an unsigned char)
215
+ *
216
+ * Behaves like IS_EXTENDER but with a single-byte argument
217
+ */
218
+ #define IS_EXTENDER_CH(c) xmlIsExtender_ch(c)
219
+
220
+ /**
221
+ * IS_IDEOGRAPHIC:
222
+ * @c: an UNICODE value (int)
223
+ *
224
+ * Macro to check the following production in the XML spec:
225
+ *
226
+ *
227
+ * [86] Ideographic ::= [#x4E00-#x9FA5] | #x3007 | [#x3021-#x3029]
228
+ */
229
+ #define IS_IDEOGRAPHIC(c) xmlIsIdeographicQ(c)
230
+
231
+ /**
232
+ * IS_LETTER:
233
+ * @c: an UNICODE value (int)
234
+ *
235
+ * Macro to check the following production in the XML spec:
236
+ *
237
+ *
238
+ * [84] Letter ::= BaseChar | Ideographic
239
+ */
240
+ #define IS_LETTER(c) (IS_BASECHAR(c) || IS_IDEOGRAPHIC(c))
241
+
242
+ /**
243
+ * IS_LETTER_CH:
244
+ * @c: an xmlChar value (normally unsigned char)
245
+ *
246
+ * Macro behaves like IS_LETTER, but only check base chars
247
+ *
248
+ */
249
+ #define IS_LETTER_CH(c) xmlIsBaseChar_ch(c)
250
+
251
+ /**
252
+ * IS_ASCII_LETTER:
253
+ * @c: an xmlChar value
254
+ *
255
+ * Macro to check [a-zA-Z]
256
+ *
257
+ */
258
+ #define IS_ASCII_LETTER(c) (((0x41 <= (c)) && ((c) <= 0x5a)) || \
259
+ ((0x61 <= (c)) && ((c) <= 0x7a)))
260
+
261
+ /**
262
+ * IS_ASCII_DIGIT:
263
+ * @c: an xmlChar value
264
+ *
265
+ * Macro to check [0-9]
266
+ *
267
+ */
268
+ #define IS_ASCII_DIGIT(c) ((0x30 <= (c)) && ((c) <= 0x39))
269
+
270
+ /**
271
+ * IS_PUBIDCHAR:
272
+ * @c: an UNICODE value (int)
273
+ *
274
+ * Macro to check the following production in the XML spec:
275
+ *
276
+ *
277
+ * [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
278
+ */
279
+ #define IS_PUBIDCHAR(c) xmlIsPubidCharQ(c)
280
+
281
+ /**
282
+ * IS_PUBIDCHAR_CH:
283
+ * @c: an xmlChar value (normally unsigned char)
284
+ *
285
+ * Same as IS_PUBIDCHAR but for single-byte value
286
+ */
287
+ #define IS_PUBIDCHAR_CH(c) xmlIsPubidChar_ch(c)
288
+
289
+ /**
290
+ * Global variables used for predefined strings.
291
+ */
292
+ XMLPUBVAR const xmlChar xmlStringText[];
293
+ XMLPUBVAR const xmlChar xmlStringTextNoenc[];
294
+ XMLPUBVAR const xmlChar xmlStringComment[];
295
+
296
+ /*
297
+ * Function to finish the work of the macros where needed.
298
+ */
299
+ XMLPUBFUN int xmlIsLetter (int c);
300
+
301
+ /**
302
+ * Parser context.
303
+ */
304
+ XMLPUBFUN xmlParserCtxtPtr
305
+ xmlCreateFileParserCtxt (const char *filename);
306
+ XMLPUBFUN xmlParserCtxtPtr
307
+ xmlCreateURLParserCtxt (const char *filename,
308
+ int options);
309
+ XMLPUBFUN xmlParserCtxtPtr
310
+ xmlCreateMemoryParserCtxt(const char *buffer,
311
+ int size);
312
+ XMLPUBFUN xmlParserCtxtPtr
313
+ xmlCreateEntityParserCtxt(const xmlChar *URL,
314
+ const xmlChar *ID,
315
+ const xmlChar *base);
316
+ XMLPUBFUN int
317
+ xmlSwitchEncoding (xmlParserCtxtPtr ctxt,
318
+ xmlCharEncoding enc);
319
+ XMLPUBFUN int
320
+ xmlSwitchToEncoding (xmlParserCtxtPtr ctxt,
321
+ xmlCharEncodingHandlerPtr handler);
322
+ XML_DEPRECATED
323
+ XMLPUBFUN int
324
+ xmlSwitchInputEncoding (xmlParserCtxtPtr ctxt,
325
+ xmlParserInputPtr input,
326
+ xmlCharEncodingHandlerPtr handler);
327
+
328
+ /**
329
+ * Input Streams.
330
+ */
331
+ XMLPUBFUN xmlParserInputPtr
332
+ xmlNewStringInputStream (xmlParserCtxtPtr ctxt,
333
+ const xmlChar *buffer);
334
+ XML_DEPRECATED
335
+ XMLPUBFUN xmlParserInputPtr
336
+ xmlNewEntityInputStream (xmlParserCtxtPtr ctxt,
337
+ xmlEntityPtr entity);
338
+ XMLPUBFUN int
339
+ xmlPushInput (xmlParserCtxtPtr ctxt,
340
+ xmlParserInputPtr input);
341
+ XMLPUBFUN xmlChar
342
+ xmlPopInput (xmlParserCtxtPtr ctxt);
343
+ XMLPUBFUN void
344
+ xmlFreeInputStream (xmlParserInputPtr input);
345
+ XMLPUBFUN xmlParserInputPtr
346
+ xmlNewInputFromFile (xmlParserCtxtPtr ctxt,
347
+ const char *filename);
348
+ XMLPUBFUN xmlParserInputPtr
349
+ xmlNewInputStream (xmlParserCtxtPtr ctxt);
350
+
351
+ /**
352
+ * Namespaces.
353
+ */
354
+ XMLPUBFUN xmlChar *
355
+ xmlSplitQName (xmlParserCtxtPtr ctxt,
356
+ const xmlChar *name,
357
+ xmlChar **prefix);
358
+
359
+ /**
360
+ * Generic production rules.
361
+ */
362
+ XML_DEPRECATED
363
+ XMLPUBFUN const xmlChar *
364
+ xmlParseName (xmlParserCtxtPtr ctxt);
365
+ XML_DEPRECATED
366
+ XMLPUBFUN xmlChar *
367
+ xmlParseNmtoken (xmlParserCtxtPtr ctxt);
368
+ XML_DEPRECATED
369
+ XMLPUBFUN xmlChar *
370
+ xmlParseEntityValue (xmlParserCtxtPtr ctxt,
371
+ xmlChar **orig);
372
+ XML_DEPRECATED
373
+ XMLPUBFUN xmlChar *
374
+ xmlParseAttValue (xmlParserCtxtPtr ctxt);
375
+ XML_DEPRECATED
376
+ XMLPUBFUN xmlChar *
377
+ xmlParseSystemLiteral (xmlParserCtxtPtr ctxt);
378
+ XML_DEPRECATED
379
+ XMLPUBFUN xmlChar *
380
+ xmlParsePubidLiteral (xmlParserCtxtPtr ctxt);
381
+ XML_DEPRECATED
382
+ XMLPUBFUN void
383
+ xmlParseCharData (xmlParserCtxtPtr ctxt,
384
+ int cdata);
385
+ XML_DEPRECATED
386
+ XMLPUBFUN xmlChar *
387
+ xmlParseExternalID (xmlParserCtxtPtr ctxt,
388
+ xmlChar **publicID,
389
+ int strict);
390
+ XML_DEPRECATED
391
+ XMLPUBFUN void
392
+ xmlParseComment (xmlParserCtxtPtr ctxt);
393
+ XML_DEPRECATED
394
+ XMLPUBFUN const xmlChar *
395
+ xmlParsePITarget (xmlParserCtxtPtr ctxt);
396
+ XML_DEPRECATED
397
+ XMLPUBFUN void
398
+ xmlParsePI (xmlParserCtxtPtr ctxt);
399
+ XML_DEPRECATED
400
+ XMLPUBFUN void
401
+ xmlParseNotationDecl (xmlParserCtxtPtr ctxt);
402
+ XML_DEPRECATED
403
+ XMLPUBFUN void
404
+ xmlParseEntityDecl (xmlParserCtxtPtr ctxt);
405
+ XML_DEPRECATED
406
+ XMLPUBFUN int
407
+ xmlParseDefaultDecl (xmlParserCtxtPtr ctxt,
408
+ xmlChar **value);
409
+ XML_DEPRECATED
410
+ XMLPUBFUN xmlEnumerationPtr
411
+ xmlParseNotationType (xmlParserCtxtPtr ctxt);
412
+ XML_DEPRECATED
413
+ XMLPUBFUN xmlEnumerationPtr
414
+ xmlParseEnumerationType (xmlParserCtxtPtr ctxt);
415
+ XML_DEPRECATED
416
+ XMLPUBFUN int
417
+ xmlParseEnumeratedType (xmlParserCtxtPtr ctxt,
418
+ xmlEnumerationPtr *tree);
419
+ XML_DEPRECATED
420
+ XMLPUBFUN int
421
+ xmlParseAttributeType (xmlParserCtxtPtr ctxt,
422
+ xmlEnumerationPtr *tree);
423
+ XML_DEPRECATED
424
+ XMLPUBFUN void
425
+ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt);
426
+ XML_DEPRECATED
427
+ XMLPUBFUN xmlElementContentPtr
428
+ xmlParseElementMixedContentDecl
429
+ (xmlParserCtxtPtr ctxt,
430
+ int inputchk);
431
+ XML_DEPRECATED
432
+ XMLPUBFUN xmlElementContentPtr
433
+ xmlParseElementChildrenContentDecl
434
+ (xmlParserCtxtPtr ctxt,
435
+ int inputchk);
436
+ XML_DEPRECATED
437
+ XMLPUBFUN int
438
+ xmlParseElementContentDecl(xmlParserCtxtPtr ctxt,
439
+ const xmlChar *name,
440
+ xmlElementContentPtr *result);
441
+ XML_DEPRECATED
442
+ XMLPUBFUN int
443
+ xmlParseElementDecl (xmlParserCtxtPtr ctxt);
444
+ XML_DEPRECATED
445
+ XMLPUBFUN void
446
+ xmlParseMarkupDecl (xmlParserCtxtPtr ctxt);
447
+ XML_DEPRECATED
448
+ XMLPUBFUN int
449
+ xmlParseCharRef (xmlParserCtxtPtr ctxt);
450
+ XML_DEPRECATED
451
+ XMLPUBFUN xmlEntityPtr
452
+ xmlParseEntityRef (xmlParserCtxtPtr ctxt);
453
+ XML_DEPRECATED
454
+ XMLPUBFUN void
455
+ xmlParseReference (xmlParserCtxtPtr ctxt);
456
+ XML_DEPRECATED
457
+ XMLPUBFUN void
458
+ xmlParsePEReference (xmlParserCtxtPtr ctxt);
459
+ XML_DEPRECATED
460
+ XMLPUBFUN void
461
+ xmlParseDocTypeDecl (xmlParserCtxtPtr ctxt);
462
+ #ifdef LIBXML_SAX1_ENABLED
463
+ XML_DEPRECATED
464
+ XMLPUBFUN const xmlChar *
465
+ xmlParseAttribute (xmlParserCtxtPtr ctxt,
466
+ xmlChar **value);
467
+ XML_DEPRECATED
468
+ XMLPUBFUN const xmlChar *
469
+ xmlParseStartTag (xmlParserCtxtPtr ctxt);
470
+ XML_DEPRECATED
471
+ XMLPUBFUN void
472
+ xmlParseEndTag (xmlParserCtxtPtr ctxt);
473
+ #endif /* LIBXML_SAX1_ENABLED */
474
+ XML_DEPRECATED
475
+ XMLPUBFUN void
476
+ xmlParseCDSect (xmlParserCtxtPtr ctxt);
477
+ XMLPUBFUN void
478
+ xmlParseContent (xmlParserCtxtPtr ctxt);
479
+ XML_DEPRECATED
480
+ XMLPUBFUN void
481
+ xmlParseElement (xmlParserCtxtPtr ctxt);
482
+ XML_DEPRECATED
483
+ XMLPUBFUN xmlChar *
484
+ xmlParseVersionNum (xmlParserCtxtPtr ctxt);
485
+ XML_DEPRECATED
486
+ XMLPUBFUN xmlChar *
487
+ xmlParseVersionInfo (xmlParserCtxtPtr ctxt);
488
+ XML_DEPRECATED
489
+ XMLPUBFUN xmlChar *
490
+ xmlParseEncName (xmlParserCtxtPtr ctxt);
491
+ XML_DEPRECATED
492
+ XMLPUBFUN const xmlChar *
493
+ xmlParseEncodingDecl (xmlParserCtxtPtr ctxt);
494
+ XML_DEPRECATED
495
+ XMLPUBFUN int
496
+ xmlParseSDDecl (xmlParserCtxtPtr ctxt);
497
+ XML_DEPRECATED
498
+ XMLPUBFUN void
499
+ xmlParseXMLDecl (xmlParserCtxtPtr ctxt);
500
+ XML_DEPRECATED
501
+ XMLPUBFUN void
502
+ xmlParseTextDecl (xmlParserCtxtPtr ctxt);
503
+ XML_DEPRECATED
504
+ XMLPUBFUN void
505
+ xmlParseMisc (xmlParserCtxtPtr ctxt);
506
+ XMLPUBFUN void
507
+ xmlParseExternalSubset (xmlParserCtxtPtr ctxt,
508
+ const xmlChar *ExternalID,
509
+ const xmlChar *SystemID);
510
+ /**
511
+ * XML_SUBSTITUTE_NONE:
512
+ *
513
+ * If no entities need to be substituted.
514
+ */
515
+ #define XML_SUBSTITUTE_NONE 0
516
+ /**
517
+ * XML_SUBSTITUTE_REF:
518
+ *
519
+ * Whether general entities need to be substituted.
520
+ */
521
+ #define XML_SUBSTITUTE_REF 1
522
+ /**
523
+ * XML_SUBSTITUTE_PEREF:
524
+ *
525
+ * Whether parameter entities need to be substituted.
526
+ */
527
+ #define XML_SUBSTITUTE_PEREF 2
528
+ /**
529
+ * XML_SUBSTITUTE_BOTH:
530
+ *
531
+ * Both general and parameter entities need to be substituted.
532
+ */
533
+ #define XML_SUBSTITUTE_BOTH 3
534
+
535
+ XML_DEPRECATED
536
+ XMLPUBFUN xmlChar *
537
+ xmlStringDecodeEntities (xmlParserCtxtPtr ctxt,
538
+ const xmlChar *str,
539
+ int what,
540
+ xmlChar end,
541
+ xmlChar end2,
542
+ xmlChar end3);
543
+ XML_DEPRECATED
544
+ XMLPUBFUN xmlChar *
545
+ xmlStringLenDecodeEntities (xmlParserCtxtPtr ctxt,
546
+ const xmlChar *str,
547
+ int len,
548
+ int what,
549
+ xmlChar end,
550
+ xmlChar end2,
551
+ xmlChar end3);
552
+
553
+ /*
554
+ * Generated by MACROS on top of parser.c c.f. PUSH_AND_POP.
555
+ */
556
+ XML_DEPRECATED
557
+ XMLPUBFUN int nodePush (xmlParserCtxtPtr ctxt,
558
+ xmlNodePtr value);
559
+ XML_DEPRECATED
560
+ XMLPUBFUN xmlNodePtr nodePop (xmlParserCtxtPtr ctxt);
561
+ XMLPUBFUN int inputPush (xmlParserCtxtPtr ctxt,
562
+ xmlParserInputPtr value);
563
+ XMLPUBFUN xmlParserInputPtr inputPop (xmlParserCtxtPtr ctxt);
564
+ XML_DEPRECATED
565
+ XMLPUBFUN const xmlChar * namePop (xmlParserCtxtPtr ctxt);
566
+ XML_DEPRECATED
567
+ XMLPUBFUN int namePush (xmlParserCtxtPtr ctxt,
568
+ const xmlChar *value);
569
+
570
+ /*
571
+ * other commodities shared between parser.c and parserInternals.
572
+ */
573
+ XML_DEPRECATED
574
+ XMLPUBFUN int xmlSkipBlankChars (xmlParserCtxtPtr ctxt);
575
+ XML_DEPRECATED
576
+ XMLPUBFUN int xmlStringCurrentChar (xmlParserCtxtPtr ctxt,
577
+ const xmlChar *cur,
578
+ int *len);
579
+ XML_DEPRECATED
580
+ XMLPUBFUN void xmlParserHandlePEReference(xmlParserCtxtPtr ctxt);
581
+ XML_DEPRECATED
582
+ XMLPUBFUN int xmlCheckLanguageID (const xmlChar *lang);
583
+
584
+ /*
585
+ * Really core function shared with HTML parser.
586
+ */
587
+ XML_DEPRECATED
588
+ XMLPUBFUN int xmlCurrentChar (xmlParserCtxtPtr ctxt,
589
+ int *len);
590
+ XMLPUBFUN int xmlCopyCharMultiByte (xmlChar *out,
591
+ int val);
592
+ XMLPUBFUN int xmlCopyChar (int len,
593
+ xmlChar *out,
594
+ int val);
595
+ XML_DEPRECATED
596
+ XMLPUBFUN void xmlNextChar (xmlParserCtxtPtr ctxt);
597
+ XML_DEPRECATED
598
+ XMLPUBFUN void xmlParserInputShrink (xmlParserInputPtr in);
599
+
600
+ /*
601
+ * Specific function to keep track of entities references
602
+ * and used by the XSLT debugger.
603
+ */
604
+ #ifdef LIBXML_LEGACY_ENABLED
605
+ /**
606
+ * xmlEntityReferenceFunc:
607
+ * @ent: the entity
608
+ * @firstNode: the fist node in the chunk
609
+ * @lastNode: the last nod in the chunk
610
+ *
611
+ * Callback function used when one needs to be able to track back the
612
+ * provenance of a chunk of nodes inherited from an entity replacement.
613
+ */
614
+ typedef void (*xmlEntityReferenceFunc) (xmlEntityPtr ent,
615
+ xmlNodePtr firstNode,
616
+ xmlNodePtr lastNode);
617
+
618
+ XML_DEPRECATED
619
+ XMLPUBFUN void xmlSetEntityReferenceFunc (xmlEntityReferenceFunc func);
620
+
621
+ XML_DEPRECATED
622
+ XMLPUBFUN xmlChar *
623
+ xmlParseQuotedString (xmlParserCtxtPtr ctxt);
624
+ XML_DEPRECATED
625
+ XMLPUBFUN void
626
+ xmlParseNamespace (xmlParserCtxtPtr ctxt);
627
+ XML_DEPRECATED
628
+ XMLPUBFUN xmlChar *
629
+ xmlNamespaceParseNSDef (xmlParserCtxtPtr ctxt);
630
+ XML_DEPRECATED
631
+ XMLPUBFUN xmlChar *
632
+ xmlScanName (xmlParserCtxtPtr ctxt);
633
+ XML_DEPRECATED
634
+ XMLPUBFUN xmlChar *
635
+ xmlNamespaceParseNCName (xmlParserCtxtPtr ctxt);
636
+ XML_DEPRECATED
637
+ XMLPUBFUN void xmlParserHandleReference(xmlParserCtxtPtr ctxt);
638
+ XML_DEPRECATED
639
+ XMLPUBFUN xmlChar *
640
+ xmlNamespaceParseQName (xmlParserCtxtPtr ctxt,
641
+ xmlChar **prefix);
642
+ /**
643
+ * Entities
644
+ */
645
+ XML_DEPRECATED
646
+ XMLPUBFUN xmlChar *
647
+ xmlDecodeEntities (xmlParserCtxtPtr ctxt,
648
+ int len,
649
+ int what,
650
+ xmlChar end,
651
+ xmlChar end2,
652
+ xmlChar end3);
653
+ XML_DEPRECATED
654
+ XMLPUBFUN void
655
+ xmlHandleEntity (xmlParserCtxtPtr ctxt,
656
+ xmlEntityPtr entity);
657
+
658
+ #endif /* LIBXML_LEGACY_ENABLED */
659
+
660
+ #ifdef __cplusplus
661
+ }
662
+ #endif
663
+ #endif /* __XML_PARSER_INTERNALS_H__ */
venv/lib/python3.10/site-packages/lxml/includes/libxml/relaxng.h ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Summary: implementation of the Relax-NG validation
3
+ * Description: implementation of the Relax-NG validation
4
+ *
5
+ * Copy: See Copyright for the status of this software.
6
+ *
7
+ * Author: Daniel Veillard
8
+ */
9
+
10
+ #ifndef __XML_RELAX_NG__
11
+ #define __XML_RELAX_NG__
12
+
13
+ #include <libxml/xmlversion.h>
14
+ #include <libxml/xmlerror.h>
15
+ #include <libxml/xmlstring.h>
16
+ #include <libxml/tree.h>
17
+
18
+ #ifdef LIBXML_SCHEMAS_ENABLED
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ typedef struct _xmlRelaxNG xmlRelaxNG;
25
+ typedef xmlRelaxNG *xmlRelaxNGPtr;
26
+
27
+
28
+ /**
29
+ * xmlRelaxNGValidityErrorFunc:
30
+ * @ctx: the validation context
31
+ * @msg: the message
32
+ * @...: extra arguments
33
+ *
34
+ * Signature of an error callback from a Relax-NG validation
35
+ */
36
+ typedef void (*xmlRelaxNGValidityErrorFunc) (void *ctx,
37
+ const char *msg,
38
+ ...) LIBXML_ATTR_FORMAT(2,3);
39
+
40
+ /**
41
+ * xmlRelaxNGValidityWarningFunc:
42
+ * @ctx: the validation context
43
+ * @msg: the message
44
+ * @...: extra arguments
45
+ *
46
+ * Signature of a warning callback from a Relax-NG validation
47
+ */
48
+ typedef void (*xmlRelaxNGValidityWarningFunc) (void *ctx,
49
+ const char *msg,
50
+ ...) LIBXML_ATTR_FORMAT(2,3);
51
+
52
+ /**
53
+ * A schemas validation context
54
+ */
55
+ typedef struct _xmlRelaxNGParserCtxt xmlRelaxNGParserCtxt;
56
+ typedef xmlRelaxNGParserCtxt *xmlRelaxNGParserCtxtPtr;
57
+
58
+ typedef struct _xmlRelaxNGValidCtxt xmlRelaxNGValidCtxt;
59
+ typedef xmlRelaxNGValidCtxt *xmlRelaxNGValidCtxtPtr;
60
+
61
+ /*
62
+ * xmlRelaxNGValidErr:
63
+ *
64
+ * List of possible Relax NG validation errors
65
+ */
66
+ typedef enum {
67
+ XML_RELAXNG_OK = 0,
68
+ XML_RELAXNG_ERR_MEMORY,
69
+ XML_RELAXNG_ERR_TYPE,
70
+ XML_RELAXNG_ERR_TYPEVAL,
71
+ XML_RELAXNG_ERR_DUPID,
72
+ XML_RELAXNG_ERR_TYPECMP,
73
+ XML_RELAXNG_ERR_NOSTATE,
74
+ XML_RELAXNG_ERR_NODEFINE,
75
+ XML_RELAXNG_ERR_LISTEXTRA,
76
+ XML_RELAXNG_ERR_LISTEMPTY,
77
+ XML_RELAXNG_ERR_INTERNODATA,
78
+ XML_RELAXNG_ERR_INTERSEQ,
79
+ XML_RELAXNG_ERR_INTEREXTRA,
80
+ XML_RELAXNG_ERR_ELEMNAME,
81
+ XML_RELAXNG_ERR_ATTRNAME,
82
+ XML_RELAXNG_ERR_ELEMNONS,
83
+ XML_RELAXNG_ERR_ATTRNONS,
84
+ XML_RELAXNG_ERR_ELEMWRONGNS,
85
+ XML_RELAXNG_ERR_ATTRWRONGNS,
86
+ XML_RELAXNG_ERR_ELEMEXTRANS,
87
+ XML_RELAXNG_ERR_ATTREXTRANS,
88
+ XML_RELAXNG_ERR_ELEMNOTEMPTY,
89
+ XML_RELAXNG_ERR_NOELEM,
90
+ XML_RELAXNG_ERR_NOTELEM,
91
+ XML_RELAXNG_ERR_ATTRVALID,
92
+ XML_RELAXNG_ERR_CONTENTVALID,
93
+ XML_RELAXNG_ERR_EXTRACONTENT,
94
+ XML_RELAXNG_ERR_INVALIDATTR,
95
+ XML_RELAXNG_ERR_DATAELEM,
96
+ XML_RELAXNG_ERR_VALELEM,
97
+ XML_RELAXNG_ERR_LISTELEM,
98
+ XML_RELAXNG_ERR_DATATYPE,
99
+ XML_RELAXNG_ERR_VALUE,
100
+ XML_RELAXNG_ERR_LIST,
101
+ XML_RELAXNG_ERR_NOGRAMMAR,
102
+ XML_RELAXNG_ERR_EXTRADATA,
103
+ XML_RELAXNG_ERR_LACKDATA,
104
+ XML_RELAXNG_ERR_INTERNAL,
105
+ XML_RELAXNG_ERR_ELEMWRONG,
106
+ XML_RELAXNG_ERR_TEXTWRONG
107
+ } xmlRelaxNGValidErr;
108
+
109
+ /*
110
+ * xmlRelaxNGParserFlags:
111
+ *
112
+ * List of possible Relax NG Parser flags
113
+ */
114
+ typedef enum {
115
+ XML_RELAXNGP_NONE = 0,
116
+ XML_RELAXNGP_FREE_DOC = 1,
117
+ XML_RELAXNGP_CRNG = 2
118
+ } xmlRelaxNGParserFlag;
119
+
120
+ XMLPUBFUN int
121
+ xmlRelaxNGInitTypes (void);
122
+ XML_DEPRECATED
123
+ XMLPUBFUN void
124
+ xmlRelaxNGCleanupTypes (void);
125
+
126
+ /*
127
+ * Interfaces for parsing.
128
+ */
129
+ XMLPUBFUN xmlRelaxNGParserCtxtPtr
130
+ xmlRelaxNGNewParserCtxt (const char *URL);
131
+ XMLPUBFUN xmlRelaxNGParserCtxtPtr
132
+ xmlRelaxNGNewMemParserCtxt (const char *buffer,
133
+ int size);
134
+ XMLPUBFUN xmlRelaxNGParserCtxtPtr
135
+ xmlRelaxNGNewDocParserCtxt (xmlDocPtr doc);
136
+
137
+ XMLPUBFUN int
138
+ xmlRelaxParserSetFlag (xmlRelaxNGParserCtxtPtr ctxt,
139
+ int flag);
140
+
141
+ XMLPUBFUN void
142
+ xmlRelaxNGFreeParserCtxt (xmlRelaxNGParserCtxtPtr ctxt);
143
+ XMLPUBFUN void
144
+ xmlRelaxNGSetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
145
+ xmlRelaxNGValidityErrorFunc err,
146
+ xmlRelaxNGValidityWarningFunc warn,
147
+ void *ctx);
148
+ XMLPUBFUN int
149
+ xmlRelaxNGGetParserErrors(xmlRelaxNGParserCtxtPtr ctxt,
150
+ xmlRelaxNGValidityErrorFunc *err,
151
+ xmlRelaxNGValidityWarningFunc *warn,
152
+ void **ctx);
153
+ XMLPUBFUN void
154
+ xmlRelaxNGSetParserStructuredErrors(
155
+ xmlRelaxNGParserCtxtPtr ctxt,
156
+ xmlStructuredErrorFunc serror,
157
+ void *ctx);
158
+ XMLPUBFUN xmlRelaxNGPtr
159
+ xmlRelaxNGParse (xmlRelaxNGParserCtxtPtr ctxt);
160
+ XMLPUBFUN void
161
+ xmlRelaxNGFree (xmlRelaxNGPtr schema);
162
+ #ifdef LIBXML_OUTPUT_ENABLED
163
+ XMLPUBFUN void
164
+ xmlRelaxNGDump (FILE *output,
165
+ xmlRelaxNGPtr schema);
166
+ XMLPUBFUN void
167
+ xmlRelaxNGDumpTree (FILE * output,
168
+ xmlRelaxNGPtr schema);
169
+ #endif /* LIBXML_OUTPUT_ENABLED */
170
+ /*
171
+ * Interfaces for validating
172
+ */
173
+ XMLPUBFUN void
174
+ xmlRelaxNGSetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
175
+ xmlRelaxNGValidityErrorFunc err,
176
+ xmlRelaxNGValidityWarningFunc warn,
177
+ void *ctx);
178
+ XMLPUBFUN int
179
+ xmlRelaxNGGetValidErrors(xmlRelaxNGValidCtxtPtr ctxt,
180
+ xmlRelaxNGValidityErrorFunc *err,
181
+ xmlRelaxNGValidityWarningFunc *warn,
182
+ void **ctx);
183
+ XMLPUBFUN void
184
+ xmlRelaxNGSetValidStructuredErrors(xmlRelaxNGValidCtxtPtr ctxt,
185
+ xmlStructuredErrorFunc serror, void *ctx);
186
+ XMLPUBFUN xmlRelaxNGValidCtxtPtr
187
+ xmlRelaxNGNewValidCtxt (xmlRelaxNGPtr schema);
188
+ XMLPUBFUN void
189
+ xmlRelaxNGFreeValidCtxt (xmlRelaxNGValidCtxtPtr ctxt);
190
+ XMLPUBFUN int
191
+ xmlRelaxNGValidateDoc (xmlRelaxNGValidCtxtPtr ctxt,
192
+ xmlDocPtr doc);
193
+ /*
194
+ * Interfaces for progressive validation when possible
195
+ */
196
+ XMLPUBFUN int
197
+ xmlRelaxNGValidatePushElement (xmlRelaxNGValidCtxtPtr ctxt,
198
+ xmlDocPtr doc,
199
+ xmlNodePtr elem);
200
+ XMLPUBFUN int
201
+ xmlRelaxNGValidatePushCData (xmlRelaxNGValidCtxtPtr ctxt,
202
+ const xmlChar *data,
203
+ int len);
204
+ XMLPUBFUN int
205
+ xmlRelaxNGValidatePopElement (xmlRelaxNGValidCtxtPtr ctxt,
206
+ xmlDocPtr doc,
207
+ xmlNodePtr elem);
208
+ XMLPUBFUN int
209
+ xmlRelaxNGValidateFullElement (xmlRelaxNGValidCtxtPtr ctxt,
210
+ xmlDocPtr doc,
211
+ xmlNodePtr elem);
212
+
213
+ #ifdef __cplusplus
214
+ }
215
+ #endif
216
+
217
+ #endif /* LIBXML_SCHEMAS_ENABLED */
218
+
219
+ #endif /* __XML_RELAX_NG__ */