applied-ai-018 commited on
Commit
f3c8a4b
·
verified ·
1 Parent(s): bc9552a

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. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER +1 -0
  2. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst +28 -0
  3. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/METADATA +93 -0
  4. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/RECORD +14 -0
  5. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL +6 -0
  6. env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt +1 -0
  7. env-llmeval/lib/python3.10/site-packages/markupsafe/__init__.py +332 -0
  8. env-llmeval/lib/python3.10/site-packages/markupsafe/__pycache__/__init__.cpython-310.pyc +0 -0
  9. env-llmeval/lib/python3.10/site-packages/markupsafe/__pycache__/_native.cpython-310.pyc +0 -0
  10. env-llmeval/lib/python3.10/site-packages/markupsafe/_native.py +63 -0
  11. env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.c +320 -0
  12. env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.cpython-310-x86_64-linux-gnu.so +0 -0
  13. env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.pyi +9 -0
  14. env-llmeval/lib/python3.10/site-packages/markupsafe/py.typed +0 -0
  15. env-llmeval/lib/python3.10/site-packages/packaging/__init__.py +15 -0
  16. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/__init__.cpython-310.pyc +0 -0
  17. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_elffile.cpython-310.pyc +0 -0
  18. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_manylinux.cpython-310.pyc +0 -0
  19. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_musllinux.cpython-310.pyc +0 -0
  20. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_parser.cpython-310.pyc +0 -0
  21. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_structures.cpython-310.pyc +0 -0
  22. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_tokenizer.cpython-310.pyc +0 -0
  23. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/markers.cpython-310.pyc +0 -0
  24. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/metadata.cpython-310.pyc +0 -0
  25. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/requirements.cpython-310.pyc +0 -0
  26. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/specifiers.cpython-310.pyc +0 -0
  27. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/tags.cpython-310.pyc +0 -0
  28. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/utils.cpython-310.pyc +0 -0
  29. env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/version.cpython-310.pyc +0 -0
  30. env-llmeval/lib/python3.10/site-packages/packaging/_elffile.py +108 -0
  31. env-llmeval/lib/python3.10/site-packages/packaging/_manylinux.py +260 -0
  32. env-llmeval/lib/python3.10/site-packages/packaging/_musllinux.py +83 -0
  33. env-llmeval/lib/python3.10/site-packages/packaging/_structures.py +61 -0
  34. env-llmeval/lib/python3.10/site-packages/packaging/_tokenizer.py +192 -0
  35. env-llmeval/lib/python3.10/site-packages/packaging/markers.py +252 -0
  36. env-llmeval/lib/python3.10/site-packages/packaging/metadata.py +825 -0
  37. env-llmeval/lib/python3.10/site-packages/packaging/py.typed +0 -0
  38. env-llmeval/lib/python3.10/site-packages/packaging/requirements.py +90 -0
  39. env-llmeval/lib/python3.10/site-packages/packaging/specifiers.py +1017 -0
  40. env-llmeval/lib/python3.10/site-packages/packaging/tags.py +571 -0
  41. env-llmeval/lib/python3.10/site-packages/packaging/utils.py +172 -0
  42. env-llmeval/lib/python3.10/site-packages/packaging/version.py +563 -0
  43. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/INSTALLER +1 -0
  44. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/LICENSE +11 -0
  45. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/METADATA +255 -0
  46. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/RECORD +23 -0
  47. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/WHEEL +5 -0
  48. env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/top_level.txt +1 -0
  49. env-llmeval/lib/python3.10/site-packages/pytablewriter/__pycache__/__version__.cpython-310.pyc +0 -0
  50. env-llmeval/lib/python3.10/site-packages/pytablewriter/__pycache__/_converter.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/LICENSE.rst ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2010 Pallets
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 the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/METADATA ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: MarkupSafe
3
+ Version: 2.1.5
4
+ Summary: Safely add untrusted strings to HTML/XML markup.
5
+ Home-page: https://palletsprojects.com/p/markupsafe/
6
+ Maintainer: Pallets
7
+ Maintainer-email: [email protected]
8
+ License: BSD-3-Clause
9
+ Project-URL: Donate, https://palletsprojects.com/donate
10
+ Project-URL: Documentation, https://markupsafe.palletsprojects.com/
11
+ Project-URL: Changes, https://markupsafe.palletsprojects.com/changes/
12
+ Project-URL: Source Code, https://github.com/pallets/markupsafe/
13
+ Project-URL: Issue Tracker, https://github.com/pallets/markupsafe/issues/
14
+ Project-URL: Chat, https://discord.gg/pallets
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Environment :: Web Environment
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: License :: OSI Approved :: BSD License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
22
+ Classifier: Topic :: Text Processing :: Markup :: HTML
23
+ Requires-Python: >=3.7
24
+ Description-Content-Type: text/x-rst
25
+ License-File: LICENSE.rst
26
+
27
+ MarkupSafe
28
+ ==========
29
+
30
+ MarkupSafe implements a text object that escapes characters so it is
31
+ safe to use in HTML and XML. Characters that have special meanings are
32
+ replaced so that they display as the actual characters. This mitigates
33
+ injection attacks, meaning untrusted user input can safely be displayed
34
+ on a page.
35
+
36
+
37
+ Installing
38
+ ----------
39
+
40
+ Install and update using `pip`_:
41
+
42
+ .. code-block:: text
43
+
44
+ pip install -U MarkupSafe
45
+
46
+ .. _pip: https://pip.pypa.io/en/stable/getting-started/
47
+
48
+
49
+ Examples
50
+ --------
51
+
52
+ .. code-block:: pycon
53
+
54
+ >>> from markupsafe import Markup, escape
55
+
56
+ >>> # escape replaces special characters and wraps in Markup
57
+ >>> escape("<script>alert(document.cookie);</script>")
58
+ Markup('&lt;script&gt;alert(document.cookie);&lt;/script&gt;')
59
+
60
+ >>> # wrap in Markup to mark text "safe" and prevent escaping
61
+ >>> Markup("<strong>Hello</strong>")
62
+ Markup('<strong>hello</strong>')
63
+
64
+ >>> escape(Markup("<strong>Hello</strong>"))
65
+ Markup('<strong>hello</strong>')
66
+
67
+ >>> # Markup is a str subclass
68
+ >>> # methods and operators escape their arguments
69
+ >>> template = Markup("Hello <em>{name}</em>")
70
+ >>> template.format(name='"World"')
71
+ Markup('Hello <em>&#34;World&#34;</em>')
72
+
73
+
74
+ Donate
75
+ ------
76
+
77
+ The Pallets organization develops and supports MarkupSafe and other
78
+ popular packages. In order to grow the community of contributors and
79
+ users, and allow the maintainers to devote more time to the projects,
80
+ `please donate today`_.
81
+
82
+ .. _please donate today: https://palletsprojects.com/donate
83
+
84
+
85
+ Links
86
+ -----
87
+
88
+ - Documentation: https://markupsafe.palletsprojects.com/
89
+ - Changes: https://markupsafe.palletsprojects.com/changes/
90
+ - PyPI Releases: https://pypi.org/project/MarkupSafe/
91
+ - Source Code: https://github.com/pallets/markupsafe/
92
+ - Issue Tracker: https://github.com/pallets/markupsafe/issues/
93
+ - Chat: https://discord.gg/pallets
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/RECORD ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MarkupSafe-2.1.5.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
2
+ MarkupSafe-2.1.5.dist-info/LICENSE.rst,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
3
+ MarkupSafe-2.1.5.dist-info/METADATA,sha256=2dRDPam6OZLfpX0wg1JN5P3u9arqACxVSfdGmsJU7o8,3003
4
+ MarkupSafe-2.1.5.dist-info/RECORD,,
5
+ MarkupSafe-2.1.5.dist-info/WHEEL,sha256=1FEjxEYgybphwh9S0FO9IcZ0B-NIeM2ko8OzhFZeOeQ,152
6
+ MarkupSafe-2.1.5.dist-info/top_level.txt,sha256=qy0Plje5IJuvsCBjejJyhDCjEAdcDLK_2agVcex8Z6U,11
7
+ markupsafe/__init__.py,sha256=r7VOTjUq7EMQ4v3p4R1LoVOGJg6ysfYRncLr34laRBs,10958
8
+ markupsafe/__pycache__/__init__.cpython-310.pyc,,
9
+ markupsafe/__pycache__/_native.cpython-310.pyc,,
10
+ markupsafe/_native.py,sha256=GR86Qvo_GcgKmKreA1WmYN9ud17OFwkww8E-fiW-57s,1713
11
+ markupsafe/_speedups.c,sha256=X2XvQVtIdcK4Usz70BvkzoOfjTCmQlDkkjYSn-swE0g,7083
12
+ markupsafe/_speedups.cpython-310-x86_64-linux-gnu.so,sha256=kPt-fhZ_RG7PUbDvwmyC26ZvRJ9DvUlF3hszBIB6_xs,44240
13
+ markupsafe/_speedups.pyi,sha256=vfMCsOgbAXRNLUXkyuyonG8uEWKYU4PDqNuMaDELAYw,229
14
+ markupsafe/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.42.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-manylinux_2_17_x86_64
5
+ Tag: cp310-cp310-manylinux2014_x86_64
6
+
env-llmeval/lib/python3.10/site-packages/MarkupSafe-2.1.5.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ markupsafe
env-llmeval/lib/python3.10/site-packages/markupsafe/__init__.py ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import functools
2
+ import string
3
+ import sys
4
+ import typing as t
5
+
6
+ if t.TYPE_CHECKING:
7
+ import typing_extensions as te
8
+
9
+ class HasHTML(te.Protocol):
10
+ def __html__(self) -> str:
11
+ pass
12
+
13
+ _P = te.ParamSpec("_P")
14
+
15
+
16
+ __version__ = "2.1.5"
17
+
18
+
19
+ def _simple_escaping_wrapper(func: "t.Callable[_P, str]") -> "t.Callable[_P, Markup]":
20
+ @functools.wraps(func)
21
+ def wrapped(self: "Markup", *args: "_P.args", **kwargs: "_P.kwargs") -> "Markup":
22
+ arg_list = _escape_argspec(list(args), enumerate(args), self.escape)
23
+ _escape_argspec(kwargs, kwargs.items(), self.escape)
24
+ return self.__class__(func(self, *arg_list, **kwargs)) # type: ignore[arg-type]
25
+
26
+ return wrapped # type: ignore[return-value]
27
+
28
+
29
+ class Markup(str):
30
+ """A string that is ready to be safely inserted into an HTML or XML
31
+ document, either because it was escaped or because it was marked
32
+ safe.
33
+
34
+ Passing an object to the constructor converts it to text and wraps
35
+ it to mark it safe without escaping. To escape the text, use the
36
+ :meth:`escape` class method instead.
37
+
38
+ >>> Markup("Hello, <em>World</em>!")
39
+ Markup('Hello, <em>World</em>!')
40
+ >>> Markup(42)
41
+ Markup('42')
42
+ >>> Markup.escape("Hello, <em>World</em>!")
43
+ Markup('Hello &lt;em&gt;World&lt;/em&gt;!')
44
+
45
+ This implements the ``__html__()`` interface that some frameworks
46
+ use. Passing an object that implements ``__html__()`` will wrap the
47
+ output of that method, marking it safe.
48
+
49
+ >>> class Foo:
50
+ ... def __html__(self):
51
+ ... return '<a href="/foo">foo</a>'
52
+ ...
53
+ >>> Markup(Foo())
54
+ Markup('<a href="/foo">foo</a>')
55
+
56
+ This is a subclass of :class:`str`. It has the same methods, but
57
+ escapes their arguments and returns a ``Markup`` instance.
58
+
59
+ >>> Markup("<em>%s</em>") % ("foo & bar",)
60
+ Markup('<em>foo &amp; bar</em>')
61
+ >>> Markup("<em>Hello</em> ") + "<foo>"
62
+ Markup('<em>Hello</em> &lt;foo&gt;')
63
+ """
64
+
65
+ __slots__ = ()
66
+
67
+ def __new__(
68
+ cls, base: t.Any = "", encoding: t.Optional[str] = None, errors: str = "strict"
69
+ ) -> "te.Self":
70
+ if hasattr(base, "__html__"):
71
+ base = base.__html__()
72
+
73
+ if encoding is None:
74
+ return super().__new__(cls, base)
75
+
76
+ return super().__new__(cls, base, encoding, errors)
77
+
78
+ def __html__(self) -> "te.Self":
79
+ return self
80
+
81
+ def __add__(self, other: t.Union[str, "HasHTML"]) -> "te.Self":
82
+ if isinstance(other, str) or hasattr(other, "__html__"):
83
+ return self.__class__(super().__add__(self.escape(other)))
84
+
85
+ return NotImplemented
86
+
87
+ def __radd__(self, other: t.Union[str, "HasHTML"]) -> "te.Self":
88
+ if isinstance(other, str) or hasattr(other, "__html__"):
89
+ return self.escape(other).__add__(self)
90
+
91
+ return NotImplemented
92
+
93
+ def __mul__(self, num: "te.SupportsIndex") -> "te.Self":
94
+ if isinstance(num, int):
95
+ return self.__class__(super().__mul__(num))
96
+
97
+ return NotImplemented
98
+
99
+ __rmul__ = __mul__
100
+
101
+ def __mod__(self, arg: t.Any) -> "te.Self":
102
+ if isinstance(arg, tuple):
103
+ # a tuple of arguments, each wrapped
104
+ arg = tuple(_MarkupEscapeHelper(x, self.escape) for x in arg)
105
+ elif hasattr(type(arg), "__getitem__") and not isinstance(arg, str):
106
+ # a mapping of arguments, wrapped
107
+ arg = _MarkupEscapeHelper(arg, self.escape)
108
+ else:
109
+ # a single argument, wrapped with the helper and a tuple
110
+ arg = (_MarkupEscapeHelper(arg, self.escape),)
111
+
112
+ return self.__class__(super().__mod__(arg))
113
+
114
+ def __repr__(self) -> str:
115
+ return f"{self.__class__.__name__}({super().__repr__()})"
116
+
117
+ def join(self, seq: t.Iterable[t.Union[str, "HasHTML"]]) -> "te.Self":
118
+ return self.__class__(super().join(map(self.escape, seq)))
119
+
120
+ join.__doc__ = str.join.__doc__
121
+
122
+ def split( # type: ignore[override]
123
+ self, sep: t.Optional[str] = None, maxsplit: int = -1
124
+ ) -> t.List["te.Self"]:
125
+ return [self.__class__(v) for v in super().split(sep, maxsplit)]
126
+
127
+ split.__doc__ = str.split.__doc__
128
+
129
+ def rsplit( # type: ignore[override]
130
+ self, sep: t.Optional[str] = None, maxsplit: int = -1
131
+ ) -> t.List["te.Self"]:
132
+ return [self.__class__(v) for v in super().rsplit(sep, maxsplit)]
133
+
134
+ rsplit.__doc__ = str.rsplit.__doc__
135
+
136
+ def splitlines( # type: ignore[override]
137
+ self, keepends: bool = False
138
+ ) -> t.List["te.Self"]:
139
+ return [self.__class__(v) for v in super().splitlines(keepends)]
140
+
141
+ splitlines.__doc__ = str.splitlines.__doc__
142
+
143
+ def unescape(self) -> str:
144
+ """Convert escaped markup back into a text string. This replaces
145
+ HTML entities with the characters they represent.
146
+
147
+ >>> Markup("Main &raquo; <em>About</em>").unescape()
148
+ 'Main » <em>About</em>'
149
+ """
150
+ from html import unescape
151
+
152
+ return unescape(str(self))
153
+
154
+ def striptags(self) -> str:
155
+ """:meth:`unescape` the markup, remove tags, and normalize
156
+ whitespace to single spaces.
157
+
158
+ >>> Markup("Main &raquo;\t<em>About</em>").striptags()
159
+ 'Main » About'
160
+ """
161
+ value = str(self)
162
+
163
+ # Look for comments then tags separately. Otherwise, a comment that
164
+ # contains a tag would end early, leaving some of the comment behind.
165
+
166
+ while True:
167
+ # keep finding comment start marks
168
+ start = value.find("<!--")
169
+
170
+ if start == -1:
171
+ break
172
+
173
+ # find a comment end mark beyond the start, otherwise stop
174
+ end = value.find("-->", start)
175
+
176
+ if end == -1:
177
+ break
178
+
179
+ value = f"{value[:start]}{value[end + 3:]}"
180
+
181
+ # remove tags using the same method
182
+ while True:
183
+ start = value.find("<")
184
+
185
+ if start == -1:
186
+ break
187
+
188
+ end = value.find(">", start)
189
+
190
+ if end == -1:
191
+ break
192
+
193
+ value = f"{value[:start]}{value[end + 1:]}"
194
+
195
+ # collapse spaces
196
+ value = " ".join(value.split())
197
+ return self.__class__(value).unescape()
198
+
199
+ @classmethod
200
+ def escape(cls, s: t.Any) -> "te.Self":
201
+ """Escape a string. Calls :func:`escape` and ensures that for
202
+ subclasses the correct type is returned.
203
+ """
204
+ rv = escape(s)
205
+
206
+ if rv.__class__ is not cls:
207
+ return cls(rv)
208
+
209
+ return rv # type: ignore[return-value]
210
+
211
+ __getitem__ = _simple_escaping_wrapper(str.__getitem__)
212
+ capitalize = _simple_escaping_wrapper(str.capitalize)
213
+ title = _simple_escaping_wrapper(str.title)
214
+ lower = _simple_escaping_wrapper(str.lower)
215
+ upper = _simple_escaping_wrapper(str.upper)
216
+ replace = _simple_escaping_wrapper(str.replace)
217
+ ljust = _simple_escaping_wrapper(str.ljust)
218
+ rjust = _simple_escaping_wrapper(str.rjust)
219
+ lstrip = _simple_escaping_wrapper(str.lstrip)
220
+ rstrip = _simple_escaping_wrapper(str.rstrip)
221
+ center = _simple_escaping_wrapper(str.center)
222
+ strip = _simple_escaping_wrapper(str.strip)
223
+ translate = _simple_escaping_wrapper(str.translate)
224
+ expandtabs = _simple_escaping_wrapper(str.expandtabs)
225
+ swapcase = _simple_escaping_wrapper(str.swapcase)
226
+ zfill = _simple_escaping_wrapper(str.zfill)
227
+ casefold = _simple_escaping_wrapper(str.casefold)
228
+
229
+ if sys.version_info >= (3, 9):
230
+ removeprefix = _simple_escaping_wrapper(str.removeprefix)
231
+ removesuffix = _simple_escaping_wrapper(str.removesuffix)
232
+
233
+ def partition(self, sep: str) -> t.Tuple["te.Self", "te.Self", "te.Self"]:
234
+ l, s, r = super().partition(self.escape(sep))
235
+ cls = self.__class__
236
+ return cls(l), cls(s), cls(r)
237
+
238
+ def rpartition(self, sep: str) -> t.Tuple["te.Self", "te.Self", "te.Self"]:
239
+ l, s, r = super().rpartition(self.escape(sep))
240
+ cls = self.__class__
241
+ return cls(l), cls(s), cls(r)
242
+
243
+ def format(self, *args: t.Any, **kwargs: t.Any) -> "te.Self":
244
+ formatter = EscapeFormatter(self.escape)
245
+ return self.__class__(formatter.vformat(self, args, kwargs))
246
+
247
+ def format_map( # type: ignore[override]
248
+ self, map: t.Mapping[str, t.Any]
249
+ ) -> "te.Self":
250
+ formatter = EscapeFormatter(self.escape)
251
+ return self.__class__(formatter.vformat(self, (), map))
252
+
253
+ def __html_format__(self, format_spec: str) -> "te.Self":
254
+ if format_spec:
255
+ raise ValueError("Unsupported format specification for Markup.")
256
+
257
+ return self
258
+
259
+
260
+ class EscapeFormatter(string.Formatter):
261
+ __slots__ = ("escape",)
262
+
263
+ def __init__(self, escape: t.Callable[[t.Any], Markup]) -> None:
264
+ self.escape = escape
265
+ super().__init__()
266
+
267
+ def format_field(self, value: t.Any, format_spec: str) -> str:
268
+ if hasattr(value, "__html_format__"):
269
+ rv = value.__html_format__(format_spec)
270
+ elif hasattr(value, "__html__"):
271
+ if format_spec:
272
+ raise ValueError(
273
+ f"Format specifier {format_spec} given, but {type(value)} does not"
274
+ " define __html_format__. A class that defines __html__ must define"
275
+ " __html_format__ to work with format specifiers."
276
+ )
277
+ rv = value.__html__()
278
+ else:
279
+ # We need to make sure the format spec is str here as
280
+ # otherwise the wrong callback methods are invoked.
281
+ rv = string.Formatter.format_field(self, value, str(format_spec))
282
+ return str(self.escape(rv))
283
+
284
+
285
+ _ListOrDict = t.TypeVar("_ListOrDict", list, dict)
286
+
287
+
288
+ def _escape_argspec(
289
+ obj: _ListOrDict, iterable: t.Iterable[t.Any], escape: t.Callable[[t.Any], Markup]
290
+ ) -> _ListOrDict:
291
+ """Helper for various string-wrapped functions."""
292
+ for key, value in iterable:
293
+ if isinstance(value, str) or hasattr(value, "__html__"):
294
+ obj[key] = escape(value)
295
+
296
+ return obj
297
+
298
+
299
+ class _MarkupEscapeHelper:
300
+ """Helper for :meth:`Markup.__mod__`."""
301
+
302
+ __slots__ = ("obj", "escape")
303
+
304
+ def __init__(self, obj: t.Any, escape: t.Callable[[t.Any], Markup]) -> None:
305
+ self.obj = obj
306
+ self.escape = escape
307
+
308
+ def __getitem__(self, item: t.Any) -> "te.Self":
309
+ return self.__class__(self.obj[item], self.escape)
310
+
311
+ def __str__(self) -> str:
312
+ return str(self.escape(self.obj))
313
+
314
+ def __repr__(self) -> str:
315
+ return str(self.escape(repr(self.obj)))
316
+
317
+ def __int__(self) -> int:
318
+ return int(self.obj)
319
+
320
+ def __float__(self) -> float:
321
+ return float(self.obj)
322
+
323
+
324
+ # circular import
325
+ try:
326
+ from ._speedups import escape as escape
327
+ from ._speedups import escape_silent as escape_silent
328
+ from ._speedups import soft_str as soft_str
329
+ except ImportError:
330
+ from ._native import escape as escape
331
+ from ._native import escape_silent as escape_silent # noqa: F401
332
+ from ._native import soft_str as soft_str # noqa: F401
env-llmeval/lib/python3.10/site-packages/markupsafe/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (11.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/markupsafe/__pycache__/_native.cpython-310.pyc ADDED
Binary file (2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/markupsafe/_native.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import typing as t
2
+
3
+ from . import Markup
4
+
5
+
6
+ def escape(s: t.Any) -> Markup:
7
+ """Replace the characters ``&``, ``<``, ``>``, ``'``, and ``"`` in
8
+ the string with HTML-safe sequences. Use this if you need to display
9
+ text that might contain such characters in HTML.
10
+
11
+ If the object has an ``__html__`` method, it is called and the
12
+ return value is assumed to already be safe for HTML.
13
+
14
+ :param s: An object to be converted to a string and escaped.
15
+ :return: A :class:`Markup` string with the escaped text.
16
+ """
17
+ if hasattr(s, "__html__"):
18
+ return Markup(s.__html__())
19
+
20
+ return Markup(
21
+ str(s)
22
+ .replace("&", "&amp;")
23
+ .replace(">", "&gt;")
24
+ .replace("<", "&lt;")
25
+ .replace("'", "&#39;")
26
+ .replace('"', "&#34;")
27
+ )
28
+
29
+
30
+ def escape_silent(s: t.Optional[t.Any]) -> Markup:
31
+ """Like :func:`escape` but treats ``None`` as the empty string.
32
+ Useful with optional values, as otherwise you get the string
33
+ ``'None'`` when the value is ``None``.
34
+
35
+ >>> escape(None)
36
+ Markup('None')
37
+ >>> escape_silent(None)
38
+ Markup('')
39
+ """
40
+ if s is None:
41
+ return Markup()
42
+
43
+ return escape(s)
44
+
45
+
46
+ def soft_str(s: t.Any) -> str:
47
+ """Convert an object to a string if it isn't already. This preserves
48
+ a :class:`Markup` string rather than converting it back to a basic
49
+ string, so it will still be marked as safe and won't be escaped
50
+ again.
51
+
52
+ >>> value = escape("<User 1>")
53
+ >>> value
54
+ Markup('&lt;User 1&gt;')
55
+ >>> escape(str(value))
56
+ Markup('&amp;lt;User 1&amp;gt;')
57
+ >>> escape(soft_str(value))
58
+ Markup('&lt;User 1&gt;')
59
+ """
60
+ if not isinstance(s, str):
61
+ return str(s)
62
+
63
+ return s
env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.c ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #include <Python.h>
2
+
3
+ static PyObject* markup;
4
+
5
+ static int
6
+ init_constants(void)
7
+ {
8
+ PyObject *module;
9
+
10
+ /* import markup type so that we can mark the return value */
11
+ module = PyImport_ImportModule("markupsafe");
12
+ if (!module)
13
+ return 0;
14
+ markup = PyObject_GetAttrString(module, "Markup");
15
+ Py_DECREF(module);
16
+
17
+ return 1;
18
+ }
19
+
20
+ #define GET_DELTA(inp, inp_end, delta) \
21
+ while (inp < inp_end) { \
22
+ switch (*inp++) { \
23
+ case '"': \
24
+ case '\'': \
25
+ case '&': \
26
+ delta += 4; \
27
+ break; \
28
+ case '<': \
29
+ case '>': \
30
+ delta += 3; \
31
+ break; \
32
+ } \
33
+ }
34
+
35
+ #define DO_ESCAPE(inp, inp_end, outp) \
36
+ { \
37
+ Py_ssize_t ncopy = 0; \
38
+ while (inp < inp_end) { \
39
+ switch (*inp) { \
40
+ case '"': \
41
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
42
+ outp += ncopy; ncopy = 0; \
43
+ *outp++ = '&'; \
44
+ *outp++ = '#'; \
45
+ *outp++ = '3'; \
46
+ *outp++ = '4'; \
47
+ *outp++ = ';'; \
48
+ break; \
49
+ case '\'': \
50
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
51
+ outp += ncopy; ncopy = 0; \
52
+ *outp++ = '&'; \
53
+ *outp++ = '#'; \
54
+ *outp++ = '3'; \
55
+ *outp++ = '9'; \
56
+ *outp++ = ';'; \
57
+ break; \
58
+ case '&': \
59
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
60
+ outp += ncopy; ncopy = 0; \
61
+ *outp++ = '&'; \
62
+ *outp++ = 'a'; \
63
+ *outp++ = 'm'; \
64
+ *outp++ = 'p'; \
65
+ *outp++ = ';'; \
66
+ break; \
67
+ case '<': \
68
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
69
+ outp += ncopy; ncopy = 0; \
70
+ *outp++ = '&'; \
71
+ *outp++ = 'l'; \
72
+ *outp++ = 't'; \
73
+ *outp++ = ';'; \
74
+ break; \
75
+ case '>': \
76
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
77
+ outp += ncopy; ncopy = 0; \
78
+ *outp++ = '&'; \
79
+ *outp++ = 'g'; \
80
+ *outp++ = 't'; \
81
+ *outp++ = ';'; \
82
+ break; \
83
+ default: \
84
+ ncopy++; \
85
+ } \
86
+ inp++; \
87
+ } \
88
+ memcpy(outp, inp-ncopy, sizeof(*outp)*ncopy); \
89
+ }
90
+
91
+ static PyObject*
92
+ escape_unicode_kind1(PyUnicodeObject *in)
93
+ {
94
+ Py_UCS1 *inp = PyUnicode_1BYTE_DATA(in);
95
+ Py_UCS1 *inp_end = inp + PyUnicode_GET_LENGTH(in);
96
+ Py_UCS1 *outp;
97
+ PyObject *out;
98
+ Py_ssize_t delta = 0;
99
+
100
+ GET_DELTA(inp, inp_end, delta);
101
+ if (!delta) {
102
+ Py_INCREF(in);
103
+ return (PyObject*)in;
104
+ }
105
+
106
+ out = PyUnicode_New(PyUnicode_GET_LENGTH(in) + delta,
107
+ PyUnicode_IS_ASCII(in) ? 127 : 255);
108
+ if (!out)
109
+ return NULL;
110
+
111
+ inp = PyUnicode_1BYTE_DATA(in);
112
+ outp = PyUnicode_1BYTE_DATA(out);
113
+ DO_ESCAPE(inp, inp_end, outp);
114
+ return out;
115
+ }
116
+
117
+ static PyObject*
118
+ escape_unicode_kind2(PyUnicodeObject *in)
119
+ {
120
+ Py_UCS2 *inp = PyUnicode_2BYTE_DATA(in);
121
+ Py_UCS2 *inp_end = inp + PyUnicode_GET_LENGTH(in);
122
+ Py_UCS2 *outp;
123
+ PyObject *out;
124
+ Py_ssize_t delta = 0;
125
+
126
+ GET_DELTA(inp, inp_end, delta);
127
+ if (!delta) {
128
+ Py_INCREF(in);
129
+ return (PyObject*)in;
130
+ }
131
+
132
+ out = PyUnicode_New(PyUnicode_GET_LENGTH(in) + delta, 65535);
133
+ if (!out)
134
+ return NULL;
135
+
136
+ inp = PyUnicode_2BYTE_DATA(in);
137
+ outp = PyUnicode_2BYTE_DATA(out);
138
+ DO_ESCAPE(inp, inp_end, outp);
139
+ return out;
140
+ }
141
+
142
+
143
+ static PyObject*
144
+ escape_unicode_kind4(PyUnicodeObject *in)
145
+ {
146
+ Py_UCS4 *inp = PyUnicode_4BYTE_DATA(in);
147
+ Py_UCS4 *inp_end = inp + PyUnicode_GET_LENGTH(in);
148
+ Py_UCS4 *outp;
149
+ PyObject *out;
150
+ Py_ssize_t delta = 0;
151
+
152
+ GET_DELTA(inp, inp_end, delta);
153
+ if (!delta) {
154
+ Py_INCREF(in);
155
+ return (PyObject*)in;
156
+ }
157
+
158
+ out = PyUnicode_New(PyUnicode_GET_LENGTH(in) + delta, 1114111);
159
+ if (!out)
160
+ return NULL;
161
+
162
+ inp = PyUnicode_4BYTE_DATA(in);
163
+ outp = PyUnicode_4BYTE_DATA(out);
164
+ DO_ESCAPE(inp, inp_end, outp);
165
+ return out;
166
+ }
167
+
168
+ static PyObject*
169
+ escape_unicode(PyUnicodeObject *in)
170
+ {
171
+ if (PyUnicode_READY(in))
172
+ return NULL;
173
+
174
+ switch (PyUnicode_KIND(in)) {
175
+ case PyUnicode_1BYTE_KIND:
176
+ return escape_unicode_kind1(in);
177
+ case PyUnicode_2BYTE_KIND:
178
+ return escape_unicode_kind2(in);
179
+ case PyUnicode_4BYTE_KIND:
180
+ return escape_unicode_kind4(in);
181
+ }
182
+ assert(0); /* shouldn't happen */
183
+ return NULL;
184
+ }
185
+
186
+ static PyObject*
187
+ escape(PyObject *self, PyObject *text)
188
+ {
189
+ static PyObject *id_html;
190
+ PyObject *s = NULL, *rv = NULL, *html;
191
+
192
+ if (id_html == NULL) {
193
+ id_html = PyUnicode_InternFromString("__html__");
194
+ if (id_html == NULL) {
195
+ return NULL;
196
+ }
197
+ }
198
+
199
+ /* we don't have to escape integers, bools or floats */
200
+ if (PyLong_CheckExact(text) ||
201
+ PyFloat_CheckExact(text) || PyBool_Check(text) ||
202
+ text == Py_None)
203
+ return PyObject_CallFunctionObjArgs(markup, text, NULL);
204
+
205
+ /* if the object has an __html__ method that performs the escaping */
206
+ html = PyObject_GetAttr(text ,id_html);
207
+ if (html) {
208
+ s = PyObject_CallObject(html, NULL);
209
+ Py_DECREF(html);
210
+ if (s == NULL) {
211
+ return NULL;
212
+ }
213
+ /* Convert to Markup object */
214
+ rv = PyObject_CallFunctionObjArgs(markup, (PyObject*)s, NULL);
215
+ Py_DECREF(s);
216
+ return rv;
217
+ }
218
+
219
+ /* otherwise make the object unicode if it isn't, then escape */
220
+ PyErr_Clear();
221
+ if (!PyUnicode_Check(text)) {
222
+ PyObject *unicode = PyObject_Str(text);
223
+ if (!unicode)
224
+ return NULL;
225
+ s = escape_unicode((PyUnicodeObject*)unicode);
226
+ Py_DECREF(unicode);
227
+ }
228
+ else
229
+ s = escape_unicode((PyUnicodeObject*)text);
230
+
231
+ /* convert the unicode string into a markup object. */
232
+ rv = PyObject_CallFunctionObjArgs(markup, (PyObject*)s, NULL);
233
+ Py_DECREF(s);
234
+ return rv;
235
+ }
236
+
237
+
238
+ static PyObject*
239
+ escape_silent(PyObject *self, PyObject *text)
240
+ {
241
+ if (text != Py_None)
242
+ return escape(self, text);
243
+ return PyObject_CallFunctionObjArgs(markup, NULL);
244
+ }
245
+
246
+
247
+ static PyObject*
248
+ soft_str(PyObject *self, PyObject *s)
249
+ {
250
+ if (!PyUnicode_Check(s))
251
+ return PyObject_Str(s);
252
+ Py_INCREF(s);
253
+ return s;
254
+ }
255
+
256
+
257
+ static PyMethodDef module_methods[] = {
258
+ {
259
+ "escape",
260
+ (PyCFunction)escape,
261
+ METH_O,
262
+ "Replace the characters ``&``, ``<``, ``>``, ``'``, and ``\"`` in"
263
+ " the string with HTML-safe sequences. Use this if you need to display"
264
+ " text that might contain such characters in HTML.\n\n"
265
+ "If the object has an ``__html__`` method, it is called and the"
266
+ " return value is assumed to already be safe for HTML.\n\n"
267
+ ":param s: An object to be converted to a string and escaped.\n"
268
+ ":return: A :class:`Markup` string with the escaped text.\n"
269
+ },
270
+ {
271
+ "escape_silent",
272
+ (PyCFunction)escape_silent,
273
+ METH_O,
274
+ "Like :func:`escape` but treats ``None`` as the empty string."
275
+ " Useful with optional values, as otherwise you get the string"
276
+ " ``'None'`` when the value is ``None``.\n\n"
277
+ ">>> escape(None)\n"
278
+ "Markup('None')\n"
279
+ ">>> escape_silent(None)\n"
280
+ "Markup('')\n"
281
+ },
282
+ {
283
+ "soft_str",
284
+ (PyCFunction)soft_str,
285
+ METH_O,
286
+ "Convert an object to a string if it isn't already. This preserves"
287
+ " a :class:`Markup` string rather than converting it back to a basic"
288
+ " string, so it will still be marked as safe and won't be escaped"
289
+ " again.\n\n"
290
+ ">>> value = escape(\"<User 1>\")\n"
291
+ ">>> value\n"
292
+ "Markup('&lt;User 1&gt;')\n"
293
+ ">>> escape(str(value))\n"
294
+ "Markup('&amp;lt;User 1&amp;gt;')\n"
295
+ ">>> escape(soft_str(value))\n"
296
+ "Markup('&lt;User 1&gt;')\n"
297
+ },
298
+ {NULL, NULL, 0, NULL} /* Sentinel */
299
+ };
300
+
301
+ static struct PyModuleDef module_definition = {
302
+ PyModuleDef_HEAD_INIT,
303
+ "markupsafe._speedups",
304
+ NULL,
305
+ -1,
306
+ module_methods,
307
+ NULL,
308
+ NULL,
309
+ NULL,
310
+ NULL
311
+ };
312
+
313
+ PyMODINIT_FUNC
314
+ PyInit__speedups(void)
315
+ {
316
+ if (!init_constants())
317
+ return NULL;
318
+
319
+ return PyModule_Create(&module_definition);
320
+ }
env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.cpython-310-x86_64-linux-gnu.so ADDED
Binary file (44.2 kB). View file
 
env-llmeval/lib/python3.10/site-packages/markupsafe/_speedups.pyi ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Any
2
+ from typing import Optional
3
+
4
+ from . import Markup
5
+
6
+ def escape(s: Any) -> Markup: ...
7
+ def escape_silent(s: Optional[Any]) -> Markup: ...
8
+ def soft_str(s: Any) -> str: ...
9
+ def soft_unicode(s: Any) -> str: ...
env-llmeval/lib/python3.10/site-packages/markupsafe/py.typed ADDED
File without changes
env-llmeval/lib/python3.10/site-packages/packaging/__init__.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ __title__ = "packaging"
6
+ __summary__ = "Core utilities for Python packages"
7
+ __uri__ = "https://github.com/pypa/packaging"
8
+
9
+ __version__ = "24.0"
10
+
11
+ __author__ = "Donald Stufft and individual contributors"
12
+ __email__ = "[email protected]"
13
+
14
+ __license__ = "BSD-2-Clause or Apache-2.0"
15
+ __copyright__ = "2014 %s" % __author__
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (504 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_elffile.cpython-310.pyc ADDED
Binary file (3.3 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_manylinux.cpython-310.pyc ADDED
Binary file (6.41 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_musllinux.cpython-310.pyc ADDED
Binary file (3.33 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_parser.cpython-310.pyc ADDED
Binary file (8.95 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_structures.cpython-310.pyc ADDED
Binary file (2.69 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/_tokenizer.cpython-310.pyc ADDED
Binary file (5.81 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/markers.cpython-310.pyc ADDED
Binary file (6.88 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/metadata.cpython-310.pyc ADDED
Binary file (17.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/requirements.cpython-310.pyc ADDED
Binary file (2.82 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/specifiers.cpython-310.pyc ADDED
Binary file (31 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/tags.cpython-310.pyc ADDED
Binary file (13.8 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/utils.cpython-310.pyc ADDED
Binary file (4.5 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/__pycache__/version.cpython-310.pyc ADDED
Binary file (14.1 kB). View file
 
env-llmeval/lib/python3.10/site-packages/packaging/_elffile.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ELF file parser.
3
+
4
+ This provides a class ``ELFFile`` that parses an ELF executable in a similar
5
+ interface to ``ZipFile``. Only the read interface is implemented.
6
+
7
+ Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
8
+ ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
9
+ """
10
+
11
+ import enum
12
+ import os
13
+ import struct
14
+ from typing import IO, Optional, Tuple
15
+
16
+
17
+ class ELFInvalid(ValueError):
18
+ pass
19
+
20
+
21
+ class EIClass(enum.IntEnum):
22
+ C32 = 1
23
+ C64 = 2
24
+
25
+
26
+ class EIData(enum.IntEnum):
27
+ Lsb = 1
28
+ Msb = 2
29
+
30
+
31
+ class EMachine(enum.IntEnum):
32
+ I386 = 3
33
+ S390 = 22
34
+ Arm = 40
35
+ X8664 = 62
36
+ AArc64 = 183
37
+
38
+
39
+ class ELFFile:
40
+ """
41
+ Representation of an ELF executable.
42
+ """
43
+
44
+ def __init__(self, f: IO[bytes]) -> None:
45
+ self._f = f
46
+
47
+ try:
48
+ ident = self._read("16B")
49
+ except struct.error:
50
+ raise ELFInvalid("unable to parse identification")
51
+ magic = bytes(ident[:4])
52
+ if magic != b"\x7fELF":
53
+ raise ELFInvalid(f"invalid magic: {magic!r}")
54
+
55
+ self.capacity = ident[4] # Format for program header (bitness).
56
+ self.encoding = ident[5] # Data structure encoding (endianness).
57
+
58
+ try:
59
+ # e_fmt: Format for program header.
60
+ # p_fmt: Format for section header.
61
+ # p_idx: Indexes to find p_type, p_offset, and p_filesz.
62
+ e_fmt, self._p_fmt, self._p_idx = {
63
+ (1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
64
+ (1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
65
+ (2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
66
+ (2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
67
+ }[(self.capacity, self.encoding)]
68
+ except KeyError:
69
+ raise ELFInvalid(
70
+ f"unrecognized capacity ({self.capacity}) or "
71
+ f"encoding ({self.encoding})"
72
+ )
73
+
74
+ try:
75
+ (
76
+ _,
77
+ self.machine, # Architecture type.
78
+ _,
79
+ _,
80
+ self._e_phoff, # Offset of program header.
81
+ _,
82
+ self.flags, # Processor-specific flags.
83
+ _,
84
+ self._e_phentsize, # Size of section.
85
+ self._e_phnum, # Number of sections.
86
+ ) = self._read(e_fmt)
87
+ except struct.error as e:
88
+ raise ELFInvalid("unable to parse machine and section information") from e
89
+
90
+ def _read(self, fmt: str) -> Tuple[int, ...]:
91
+ return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))
92
+
93
+ @property
94
+ def interpreter(self) -> Optional[str]:
95
+ """
96
+ The path recorded in the ``PT_INTERP`` section header.
97
+ """
98
+ for index in range(self._e_phnum):
99
+ self._f.seek(self._e_phoff + self._e_phentsize * index)
100
+ try:
101
+ data = self._read(self._p_fmt)
102
+ except struct.error:
103
+ continue
104
+ if data[self._p_idx[0]] != 3: # Not PT_INTERP.
105
+ continue
106
+ self._f.seek(data[self._p_idx[1]])
107
+ return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
108
+ return None
env-llmeval/lib/python3.10/site-packages/packaging/_manylinux.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import collections
2
+ import contextlib
3
+ import functools
4
+ import os
5
+ import re
6
+ import sys
7
+ import warnings
8
+ from typing import Dict, Generator, Iterator, NamedTuple, Optional, Sequence, Tuple
9
+
10
+ from ._elffile import EIClass, EIData, ELFFile, EMachine
11
+
12
+ EF_ARM_ABIMASK = 0xFF000000
13
+ EF_ARM_ABI_VER5 = 0x05000000
14
+ EF_ARM_ABI_FLOAT_HARD = 0x00000400
15
+
16
+
17
+ # `os.PathLike` not a generic type until Python 3.9, so sticking with `str`
18
+ # as the type for `path` until then.
19
+ @contextlib.contextmanager
20
+ def _parse_elf(path: str) -> Generator[Optional[ELFFile], None, None]:
21
+ try:
22
+ with open(path, "rb") as f:
23
+ yield ELFFile(f)
24
+ except (OSError, TypeError, ValueError):
25
+ yield None
26
+
27
+
28
+ def _is_linux_armhf(executable: str) -> bool:
29
+ # hard-float ABI can be detected from the ELF header of the running
30
+ # process
31
+ # https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
32
+ with _parse_elf(executable) as f:
33
+ return (
34
+ f is not None
35
+ and f.capacity == EIClass.C32
36
+ and f.encoding == EIData.Lsb
37
+ and f.machine == EMachine.Arm
38
+ and f.flags & EF_ARM_ABIMASK == EF_ARM_ABI_VER5
39
+ and f.flags & EF_ARM_ABI_FLOAT_HARD == EF_ARM_ABI_FLOAT_HARD
40
+ )
41
+
42
+
43
+ def _is_linux_i686(executable: str) -> bool:
44
+ with _parse_elf(executable) as f:
45
+ return (
46
+ f is not None
47
+ and f.capacity == EIClass.C32
48
+ and f.encoding == EIData.Lsb
49
+ and f.machine == EMachine.I386
50
+ )
51
+
52
+
53
+ def _have_compatible_abi(executable: str, archs: Sequence[str]) -> bool:
54
+ if "armv7l" in archs:
55
+ return _is_linux_armhf(executable)
56
+ if "i686" in archs:
57
+ return _is_linux_i686(executable)
58
+ allowed_archs = {
59
+ "x86_64",
60
+ "aarch64",
61
+ "ppc64",
62
+ "ppc64le",
63
+ "s390x",
64
+ "loongarch64",
65
+ "riscv64",
66
+ }
67
+ return any(arch in allowed_archs for arch in archs)
68
+
69
+
70
+ # If glibc ever changes its major version, we need to know what the last
71
+ # minor version was, so we can build the complete list of all versions.
72
+ # For now, guess what the highest minor version might be, assume it will
73
+ # be 50 for testing. Once this actually happens, update the dictionary
74
+ # with the actual value.
75
+ _LAST_GLIBC_MINOR: Dict[int, int] = collections.defaultdict(lambda: 50)
76
+
77
+
78
+ class _GLibCVersion(NamedTuple):
79
+ major: int
80
+ minor: int
81
+
82
+
83
+ def _glibc_version_string_confstr() -> Optional[str]:
84
+ """
85
+ Primary implementation of glibc_version_string using os.confstr.
86
+ """
87
+ # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
88
+ # to be broken or missing. This strategy is used in the standard library
89
+ # platform module.
90
+ # https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183
91
+ try:
92
+ # Should be a string like "glibc 2.17".
93
+ version_string: Optional[str] = os.confstr("CS_GNU_LIBC_VERSION")
94
+ assert version_string is not None
95
+ _, version = version_string.rsplit()
96
+ except (AssertionError, AttributeError, OSError, ValueError):
97
+ # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
98
+ return None
99
+ return version
100
+
101
+
102
+ def _glibc_version_string_ctypes() -> Optional[str]:
103
+ """
104
+ Fallback implementation of glibc_version_string using ctypes.
105
+ """
106
+ try:
107
+ import ctypes
108
+ except ImportError:
109
+ return None
110
+
111
+ # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
112
+ # manpage says, "If filename is NULL, then the returned handle is for the
113
+ # main program". This way we can let the linker do the work to figure out
114
+ # which libc our process is actually using.
115
+ #
116
+ # We must also handle the special case where the executable is not a
117
+ # dynamically linked executable. This can occur when using musl libc,
118
+ # for example. In this situation, dlopen() will error, leading to an
119
+ # OSError. Interestingly, at least in the case of musl, there is no
120
+ # errno set on the OSError. The single string argument used to construct
121
+ # OSError comes from libc itself and is therefore not portable to
122
+ # hard code here. In any case, failure to call dlopen() means we
123
+ # can proceed, so we bail on our attempt.
124
+ try:
125
+ process_namespace = ctypes.CDLL(None)
126
+ except OSError:
127
+ return None
128
+
129
+ try:
130
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
131
+ except AttributeError:
132
+ # Symbol doesn't exist -> therefore, we are not linked to
133
+ # glibc.
134
+ return None
135
+
136
+ # Call gnu_get_libc_version, which returns a string like "2.5"
137
+ gnu_get_libc_version.restype = ctypes.c_char_p
138
+ version_str: str = gnu_get_libc_version()
139
+ # py2 / py3 compatibility:
140
+ if not isinstance(version_str, str):
141
+ version_str = version_str.decode("ascii")
142
+
143
+ return version_str
144
+
145
+
146
+ def _glibc_version_string() -> Optional[str]:
147
+ """Returns glibc version string, or None if not using glibc."""
148
+ return _glibc_version_string_confstr() or _glibc_version_string_ctypes()
149
+
150
+
151
+ def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
152
+ """Parse glibc version.
153
+
154
+ We use a regexp instead of str.split because we want to discard any
155
+ random junk that might come after the minor version -- this might happen
156
+ in patched/forked versions of glibc (e.g. Linaro's version of glibc
157
+ uses version strings like "2.20-2014.11"). See gh-3588.
158
+ """
159
+ m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
160
+ if not m:
161
+ warnings.warn(
162
+ f"Expected glibc version with 2 components major.minor,"
163
+ f" got: {version_str}",
164
+ RuntimeWarning,
165
+ )
166
+ return -1, -1
167
+ return int(m.group("major")), int(m.group("minor"))
168
+
169
+
170
+ @functools.lru_cache()
171
+ def _get_glibc_version() -> Tuple[int, int]:
172
+ version_str = _glibc_version_string()
173
+ if version_str is None:
174
+ return (-1, -1)
175
+ return _parse_glibc_version(version_str)
176
+
177
+
178
+ # From PEP 513, PEP 600
179
+ def _is_compatible(arch: str, version: _GLibCVersion) -> bool:
180
+ sys_glibc = _get_glibc_version()
181
+ if sys_glibc < version:
182
+ return False
183
+ # Check for presence of _manylinux module.
184
+ try:
185
+ import _manylinux
186
+ except ImportError:
187
+ return True
188
+ if hasattr(_manylinux, "manylinux_compatible"):
189
+ result = _manylinux.manylinux_compatible(version[0], version[1], arch)
190
+ if result is not None:
191
+ return bool(result)
192
+ return True
193
+ if version == _GLibCVersion(2, 5):
194
+ if hasattr(_manylinux, "manylinux1_compatible"):
195
+ return bool(_manylinux.manylinux1_compatible)
196
+ if version == _GLibCVersion(2, 12):
197
+ if hasattr(_manylinux, "manylinux2010_compatible"):
198
+ return bool(_manylinux.manylinux2010_compatible)
199
+ if version == _GLibCVersion(2, 17):
200
+ if hasattr(_manylinux, "manylinux2014_compatible"):
201
+ return bool(_manylinux.manylinux2014_compatible)
202
+ return True
203
+
204
+
205
+ _LEGACY_MANYLINUX_MAP = {
206
+ # CentOS 7 w/ glibc 2.17 (PEP 599)
207
+ (2, 17): "manylinux2014",
208
+ # CentOS 6 w/ glibc 2.12 (PEP 571)
209
+ (2, 12): "manylinux2010",
210
+ # CentOS 5 w/ glibc 2.5 (PEP 513)
211
+ (2, 5): "manylinux1",
212
+ }
213
+
214
+
215
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
216
+ """Generate manylinux tags compatible to the current platform.
217
+
218
+ :param archs: Sequence of compatible architectures.
219
+ The first one shall be the closest to the actual architecture and be the part of
220
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
221
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
222
+ be manylinux-compatible.
223
+
224
+ :returns: An iterator of compatible manylinux tags.
225
+ """
226
+ if not _have_compatible_abi(sys.executable, archs):
227
+ return
228
+ # Oldest glibc to be supported regardless of architecture is (2, 17).
229
+ too_old_glibc2 = _GLibCVersion(2, 16)
230
+ if set(archs) & {"x86_64", "i686"}:
231
+ # On x86/i686 also oldest glibc to be supported is (2, 5).
232
+ too_old_glibc2 = _GLibCVersion(2, 4)
233
+ current_glibc = _GLibCVersion(*_get_glibc_version())
234
+ glibc_max_list = [current_glibc]
235
+ # We can assume compatibility across glibc major versions.
236
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=24636
237
+ #
238
+ # Build a list of maximum glibc versions so that we can
239
+ # output the canonical list of all glibc from current_glibc
240
+ # down to too_old_glibc2, including all intermediary versions.
241
+ for glibc_major in range(current_glibc.major - 1, 1, -1):
242
+ glibc_minor = _LAST_GLIBC_MINOR[glibc_major]
243
+ glibc_max_list.append(_GLibCVersion(glibc_major, glibc_minor))
244
+ for arch in archs:
245
+ for glibc_max in glibc_max_list:
246
+ if glibc_max.major == too_old_glibc2.major:
247
+ min_minor = too_old_glibc2.minor
248
+ else:
249
+ # For other glibc major versions oldest supported is (x, 0).
250
+ min_minor = -1
251
+ for glibc_minor in range(glibc_max.minor, min_minor, -1):
252
+ glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
253
+ tag = "manylinux_{}_{}".format(*glibc_version)
254
+ if _is_compatible(arch, glibc_version):
255
+ yield f"{tag}_{arch}"
256
+ # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
257
+ if glibc_version in _LEGACY_MANYLINUX_MAP:
258
+ legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
259
+ if _is_compatible(arch, glibc_version):
260
+ yield f"{legacy_tag}_{arch}"
env-llmeval/lib/python3.10/site-packages/packaging/_musllinux.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PEP 656 support.
2
+
3
+ This module implements logic to detect if the currently running Python is
4
+ linked against musl, and what musl version is used.
5
+ """
6
+
7
+ import functools
8
+ import re
9
+ import subprocess
10
+ import sys
11
+ from typing import Iterator, NamedTuple, Optional, Sequence
12
+
13
+ from ._elffile import ELFFile
14
+
15
+
16
+ class _MuslVersion(NamedTuple):
17
+ major: int
18
+ minor: int
19
+
20
+
21
+ def _parse_musl_version(output: str) -> Optional[_MuslVersion]:
22
+ lines = [n for n in (n.strip() for n in output.splitlines()) if n]
23
+ if len(lines) < 2 or lines[0][:4] != "musl":
24
+ return None
25
+ m = re.match(r"Version (\d+)\.(\d+)", lines[1])
26
+ if not m:
27
+ return None
28
+ return _MuslVersion(major=int(m.group(1)), minor=int(m.group(2)))
29
+
30
+
31
+ @functools.lru_cache()
32
+ def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
33
+ """Detect currently-running musl runtime version.
34
+
35
+ This is done by checking the specified executable's dynamic linking
36
+ information, and invoking the loader to parse its output for a version
37
+ string. If the loader is musl, the output would be something like::
38
+
39
+ musl libc (x86_64)
40
+ Version 1.2.2
41
+ Dynamic Program Loader
42
+ """
43
+ try:
44
+ with open(executable, "rb") as f:
45
+ ld = ELFFile(f).interpreter
46
+ except (OSError, TypeError, ValueError):
47
+ return None
48
+ if ld is None or "musl" not in ld:
49
+ return None
50
+ proc = subprocess.run([ld], stderr=subprocess.PIPE, text=True)
51
+ return _parse_musl_version(proc.stderr)
52
+
53
+
54
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
55
+ """Generate musllinux tags compatible to the current platform.
56
+
57
+ :param archs: Sequence of compatible architectures.
58
+ The first one shall be the closest to the actual architecture and be the part of
59
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
60
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
61
+ be musllinux-compatible.
62
+
63
+ :returns: An iterator of compatible musllinux tags.
64
+ """
65
+ sys_musl = _get_musl_version(sys.executable)
66
+ if sys_musl is None: # Python not dynamically linked against musl.
67
+ return
68
+ for arch in archs:
69
+ for minor in range(sys_musl.minor, -1, -1):
70
+ yield f"musllinux_{sys_musl.major}_{minor}_{arch}"
71
+
72
+
73
+ if __name__ == "__main__": # pragma: no cover
74
+ import sysconfig
75
+
76
+ plat = sysconfig.get_platform()
77
+ assert plat.startswith("linux-"), "not linux"
78
+
79
+ print("plat:", plat)
80
+ print("musl:", _get_musl_version(sys.executable))
81
+ print("tags:", end=" ")
82
+ for t in platform_tags(re.sub(r"[.-]", "_", plat.split("-", 1)[-1])):
83
+ print(t, end="\n ")
env-llmeval/lib/python3.10/site-packages/packaging/_structures.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+
6
+ class InfinityType:
7
+ def __repr__(self) -> str:
8
+ return "Infinity"
9
+
10
+ def __hash__(self) -> int:
11
+ return hash(repr(self))
12
+
13
+ def __lt__(self, other: object) -> bool:
14
+ return False
15
+
16
+ def __le__(self, other: object) -> bool:
17
+ return False
18
+
19
+ def __eq__(self, other: object) -> bool:
20
+ return isinstance(other, self.__class__)
21
+
22
+ def __gt__(self, other: object) -> bool:
23
+ return True
24
+
25
+ def __ge__(self, other: object) -> bool:
26
+ return True
27
+
28
+ def __neg__(self: object) -> "NegativeInfinityType":
29
+ return NegativeInfinity
30
+
31
+
32
+ Infinity = InfinityType()
33
+
34
+
35
+ class NegativeInfinityType:
36
+ def __repr__(self) -> str:
37
+ return "-Infinity"
38
+
39
+ def __hash__(self) -> int:
40
+ return hash(repr(self))
41
+
42
+ def __lt__(self, other: object) -> bool:
43
+ return True
44
+
45
+ def __le__(self, other: object) -> bool:
46
+ return True
47
+
48
+ def __eq__(self, other: object) -> bool:
49
+ return isinstance(other, self.__class__)
50
+
51
+ def __gt__(self, other: object) -> bool:
52
+ return False
53
+
54
+ def __ge__(self, other: object) -> bool:
55
+ return False
56
+
57
+ def __neg__(self: object) -> InfinityType:
58
+ return Infinity
59
+
60
+
61
+ NegativeInfinity = NegativeInfinityType()
env-llmeval/lib/python3.10/site-packages/packaging/_tokenizer.py ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import contextlib
2
+ import re
3
+ from dataclasses import dataclass
4
+ from typing import Dict, Iterator, NoReturn, Optional, Tuple, Union
5
+
6
+ from .specifiers import Specifier
7
+
8
+
9
+ @dataclass
10
+ class Token:
11
+ name: str
12
+ text: str
13
+ position: int
14
+
15
+
16
+ class ParserSyntaxError(Exception):
17
+ """The provided source text could not be parsed correctly."""
18
+
19
+ def __init__(
20
+ self,
21
+ message: str,
22
+ *,
23
+ source: str,
24
+ span: Tuple[int, int],
25
+ ) -> None:
26
+ self.span = span
27
+ self.message = message
28
+ self.source = source
29
+
30
+ super().__init__()
31
+
32
+ def __str__(self) -> str:
33
+ marker = " " * self.span[0] + "~" * (self.span[1] - self.span[0]) + "^"
34
+ return "\n ".join([self.message, self.source, marker])
35
+
36
+
37
+ DEFAULT_RULES: "Dict[str, Union[str, re.Pattern[str]]]" = {
38
+ "LEFT_PARENTHESIS": r"\(",
39
+ "RIGHT_PARENTHESIS": r"\)",
40
+ "LEFT_BRACKET": r"\[",
41
+ "RIGHT_BRACKET": r"\]",
42
+ "SEMICOLON": r";",
43
+ "COMMA": r",",
44
+ "QUOTED_STRING": re.compile(
45
+ r"""
46
+ (
47
+ ('[^']*')
48
+ |
49
+ ("[^"]*")
50
+ )
51
+ """,
52
+ re.VERBOSE,
53
+ ),
54
+ "OP": r"(===|==|~=|!=|<=|>=|<|>)",
55
+ "BOOLOP": r"\b(or|and)\b",
56
+ "IN": r"\bin\b",
57
+ "NOT": r"\bnot\b",
58
+ "VARIABLE": re.compile(
59
+ r"""
60
+ \b(
61
+ python_version
62
+ |python_full_version
63
+ |os[._]name
64
+ |sys[._]platform
65
+ |platform_(release|system)
66
+ |platform[._](version|machine|python_implementation)
67
+ |python_implementation
68
+ |implementation_(name|version)
69
+ |extra
70
+ )\b
71
+ """,
72
+ re.VERBOSE,
73
+ ),
74
+ "SPECIFIER": re.compile(
75
+ Specifier._operator_regex_str + Specifier._version_regex_str,
76
+ re.VERBOSE | re.IGNORECASE,
77
+ ),
78
+ "AT": r"\@",
79
+ "URL": r"[^ \t]+",
80
+ "IDENTIFIER": r"\b[a-zA-Z0-9][a-zA-Z0-9._-]*\b",
81
+ "VERSION_PREFIX_TRAIL": r"\.\*",
82
+ "VERSION_LOCAL_LABEL_TRAIL": r"\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*",
83
+ "WS": r"[ \t]+",
84
+ "END": r"$",
85
+ }
86
+
87
+
88
+ class Tokenizer:
89
+ """Context-sensitive token parsing.
90
+
91
+ Provides methods to examine the input stream to check whether the next token
92
+ matches.
93
+ """
94
+
95
+ def __init__(
96
+ self,
97
+ source: str,
98
+ *,
99
+ rules: "Dict[str, Union[str, re.Pattern[str]]]",
100
+ ) -> None:
101
+ self.source = source
102
+ self.rules: Dict[str, re.Pattern[str]] = {
103
+ name: re.compile(pattern) for name, pattern in rules.items()
104
+ }
105
+ self.next_token: Optional[Token] = None
106
+ self.position = 0
107
+
108
+ def consume(self, name: str) -> None:
109
+ """Move beyond provided token name, if at current position."""
110
+ if self.check(name):
111
+ self.read()
112
+
113
+ def check(self, name: str, *, peek: bool = False) -> bool:
114
+ """Check whether the next token has the provided name.
115
+
116
+ By default, if the check succeeds, the token *must* be read before
117
+ another check. If `peek` is set to `True`, the token is not loaded and
118
+ would need to be checked again.
119
+ """
120
+ assert (
121
+ self.next_token is None
122
+ ), f"Cannot check for {name!r}, already have {self.next_token!r}"
123
+ assert name in self.rules, f"Unknown token name: {name!r}"
124
+
125
+ expression = self.rules[name]
126
+
127
+ match = expression.match(self.source, self.position)
128
+ if match is None:
129
+ return False
130
+ if not peek:
131
+ self.next_token = Token(name, match[0], self.position)
132
+ return True
133
+
134
+ def expect(self, name: str, *, expected: str) -> Token:
135
+ """Expect a certain token name next, failing with a syntax error otherwise.
136
+
137
+ The token is *not* read.
138
+ """
139
+ if not self.check(name):
140
+ raise self.raise_syntax_error(f"Expected {expected}")
141
+ return self.read()
142
+
143
+ def read(self) -> Token:
144
+ """Consume the next token and return it."""
145
+ token = self.next_token
146
+ assert token is not None
147
+
148
+ self.position += len(token.text)
149
+ self.next_token = None
150
+
151
+ return token
152
+
153
+ def raise_syntax_error(
154
+ self,
155
+ message: str,
156
+ *,
157
+ span_start: Optional[int] = None,
158
+ span_end: Optional[int] = None,
159
+ ) -> NoReturn:
160
+ """Raise ParserSyntaxError at the given position."""
161
+ span = (
162
+ self.position if span_start is None else span_start,
163
+ self.position if span_end is None else span_end,
164
+ )
165
+ raise ParserSyntaxError(
166
+ message,
167
+ source=self.source,
168
+ span=span,
169
+ )
170
+
171
+ @contextlib.contextmanager
172
+ def enclosing_tokens(
173
+ self, open_token: str, close_token: str, *, around: str
174
+ ) -> Iterator[None]:
175
+ if self.check(open_token):
176
+ open_position = self.position
177
+ self.read()
178
+ else:
179
+ open_position = None
180
+
181
+ yield
182
+
183
+ if open_position is None:
184
+ return
185
+
186
+ if not self.check(close_token):
187
+ self.raise_syntax_error(
188
+ f"Expected matching {close_token} for {open_token}, after {around}",
189
+ span_start=open_position,
190
+ )
191
+
192
+ self.read()
env-llmeval/lib/python3.10/site-packages/packaging/markers.py ADDED
@@ -0,0 +1,252 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ import operator
6
+ import os
7
+ import platform
8
+ import sys
9
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
10
+
11
+ from ._parser import (
12
+ MarkerAtom,
13
+ MarkerList,
14
+ Op,
15
+ Value,
16
+ Variable,
17
+ parse_marker as _parse_marker,
18
+ )
19
+ from ._tokenizer import ParserSyntaxError
20
+ from .specifiers import InvalidSpecifier, Specifier
21
+ from .utils import canonicalize_name
22
+
23
+ __all__ = [
24
+ "InvalidMarker",
25
+ "UndefinedComparison",
26
+ "UndefinedEnvironmentName",
27
+ "Marker",
28
+ "default_environment",
29
+ ]
30
+
31
+ Operator = Callable[[str, str], bool]
32
+
33
+
34
+ class InvalidMarker(ValueError):
35
+ """
36
+ An invalid marker was found, users should refer to PEP 508.
37
+ """
38
+
39
+
40
+ class UndefinedComparison(ValueError):
41
+ """
42
+ An invalid operation was attempted on a value that doesn't support it.
43
+ """
44
+
45
+
46
+ class UndefinedEnvironmentName(ValueError):
47
+ """
48
+ A name was attempted to be used that does not exist inside of the
49
+ environment.
50
+ """
51
+
52
+
53
+ def _normalize_extra_values(results: Any) -> Any:
54
+ """
55
+ Normalize extra values.
56
+ """
57
+ if isinstance(results[0], tuple):
58
+ lhs, op, rhs = results[0]
59
+ if isinstance(lhs, Variable) and lhs.value == "extra":
60
+ normalized_extra = canonicalize_name(rhs.value)
61
+ rhs = Value(normalized_extra)
62
+ elif isinstance(rhs, Variable) and rhs.value == "extra":
63
+ normalized_extra = canonicalize_name(lhs.value)
64
+ lhs = Value(normalized_extra)
65
+ results[0] = lhs, op, rhs
66
+ return results
67
+
68
+
69
+ def _format_marker(
70
+ marker: Union[List[str], MarkerAtom, str], first: Optional[bool] = True
71
+ ) -> str:
72
+
73
+ assert isinstance(marker, (list, tuple, str))
74
+
75
+ # Sometimes we have a structure like [[...]] which is a single item list
76
+ # where the single item is itself it's own list. In that case we want skip
77
+ # the rest of this function so that we don't get extraneous () on the
78
+ # outside.
79
+ if (
80
+ isinstance(marker, list)
81
+ and len(marker) == 1
82
+ and isinstance(marker[0], (list, tuple))
83
+ ):
84
+ return _format_marker(marker[0])
85
+
86
+ if isinstance(marker, list):
87
+ inner = (_format_marker(m, first=False) for m in marker)
88
+ if first:
89
+ return " ".join(inner)
90
+ else:
91
+ return "(" + " ".join(inner) + ")"
92
+ elif isinstance(marker, tuple):
93
+ return " ".join([m.serialize() for m in marker])
94
+ else:
95
+ return marker
96
+
97
+
98
+ _operators: Dict[str, Operator] = {
99
+ "in": lambda lhs, rhs: lhs in rhs,
100
+ "not in": lambda lhs, rhs: lhs not in rhs,
101
+ "<": operator.lt,
102
+ "<=": operator.le,
103
+ "==": operator.eq,
104
+ "!=": operator.ne,
105
+ ">=": operator.ge,
106
+ ">": operator.gt,
107
+ }
108
+
109
+
110
+ def _eval_op(lhs: str, op: Op, rhs: str) -> bool:
111
+ try:
112
+ spec = Specifier("".join([op.serialize(), rhs]))
113
+ except InvalidSpecifier:
114
+ pass
115
+ else:
116
+ return spec.contains(lhs, prereleases=True)
117
+
118
+ oper: Optional[Operator] = _operators.get(op.serialize())
119
+ if oper is None:
120
+ raise UndefinedComparison(f"Undefined {op!r} on {lhs!r} and {rhs!r}.")
121
+
122
+ return oper(lhs, rhs)
123
+
124
+
125
+ def _normalize(*values: str, key: str) -> Tuple[str, ...]:
126
+ # PEP 685 – Comparison of extra names for optional distribution dependencies
127
+ # https://peps.python.org/pep-0685/
128
+ # > When comparing extra names, tools MUST normalize the names being
129
+ # > compared using the semantics outlined in PEP 503 for names
130
+ if key == "extra":
131
+ return tuple(canonicalize_name(v) for v in values)
132
+
133
+ # other environment markers don't have such standards
134
+ return values
135
+
136
+
137
+ def _evaluate_markers(markers: MarkerList, environment: Dict[str, str]) -> bool:
138
+ groups: List[List[bool]] = [[]]
139
+
140
+ for marker in markers:
141
+ assert isinstance(marker, (list, tuple, str))
142
+
143
+ if isinstance(marker, list):
144
+ groups[-1].append(_evaluate_markers(marker, environment))
145
+ elif isinstance(marker, tuple):
146
+ lhs, op, rhs = marker
147
+
148
+ if isinstance(lhs, Variable):
149
+ environment_key = lhs.value
150
+ lhs_value = environment[environment_key]
151
+ rhs_value = rhs.value
152
+ else:
153
+ lhs_value = lhs.value
154
+ environment_key = rhs.value
155
+ rhs_value = environment[environment_key]
156
+
157
+ lhs_value, rhs_value = _normalize(lhs_value, rhs_value, key=environment_key)
158
+ groups[-1].append(_eval_op(lhs_value, op, rhs_value))
159
+ else:
160
+ assert marker in ["and", "or"]
161
+ if marker == "or":
162
+ groups.append([])
163
+
164
+ return any(all(item) for item in groups)
165
+
166
+
167
+ def format_full_version(info: "sys._version_info") -> str:
168
+ version = "{0.major}.{0.minor}.{0.micro}".format(info)
169
+ kind = info.releaselevel
170
+ if kind != "final":
171
+ version += kind[0] + str(info.serial)
172
+ return version
173
+
174
+
175
+ def default_environment() -> Dict[str, str]:
176
+ iver = format_full_version(sys.implementation.version)
177
+ implementation_name = sys.implementation.name
178
+ return {
179
+ "implementation_name": implementation_name,
180
+ "implementation_version": iver,
181
+ "os_name": os.name,
182
+ "platform_machine": platform.machine(),
183
+ "platform_release": platform.release(),
184
+ "platform_system": platform.system(),
185
+ "platform_version": platform.version(),
186
+ "python_full_version": platform.python_version(),
187
+ "platform_python_implementation": platform.python_implementation(),
188
+ "python_version": ".".join(platform.python_version_tuple()[:2]),
189
+ "sys_platform": sys.platform,
190
+ }
191
+
192
+
193
+ class Marker:
194
+ def __init__(self, marker: str) -> None:
195
+ # Note: We create a Marker object without calling this constructor in
196
+ # packaging.requirements.Requirement. If any additional logic is
197
+ # added here, make sure to mirror/adapt Requirement.
198
+ try:
199
+ self._markers = _normalize_extra_values(_parse_marker(marker))
200
+ # The attribute `_markers` can be described in terms of a recursive type:
201
+ # MarkerList = List[Union[Tuple[Node, ...], str, MarkerList]]
202
+ #
203
+ # For example, the following expression:
204
+ # python_version > "3.6" or (python_version == "3.6" and os_name == "unix")
205
+ #
206
+ # is parsed into:
207
+ # [
208
+ # (<Variable('python_version')>, <Op('>')>, <Value('3.6')>),
209
+ # 'and',
210
+ # [
211
+ # (<Variable('python_version')>, <Op('==')>, <Value('3.6')>),
212
+ # 'or',
213
+ # (<Variable('os_name')>, <Op('==')>, <Value('unix')>)
214
+ # ]
215
+ # ]
216
+ except ParserSyntaxError as e:
217
+ raise InvalidMarker(str(e)) from e
218
+
219
+ def __str__(self) -> str:
220
+ return _format_marker(self._markers)
221
+
222
+ def __repr__(self) -> str:
223
+ return f"<Marker('{self}')>"
224
+
225
+ def __hash__(self) -> int:
226
+ return hash((self.__class__.__name__, str(self)))
227
+
228
+ def __eq__(self, other: Any) -> bool:
229
+ if not isinstance(other, Marker):
230
+ return NotImplemented
231
+
232
+ return str(self) == str(other)
233
+
234
+ def evaluate(self, environment: Optional[Dict[str, str]] = None) -> bool:
235
+ """Evaluate a marker.
236
+
237
+ Return the boolean from evaluating the given marker against the
238
+ environment. environment is an optional argument to override all or
239
+ part of the determined environment.
240
+
241
+ The environment is determined from the current Python process.
242
+ """
243
+ current_environment = default_environment()
244
+ current_environment["extra"] = ""
245
+ if environment is not None:
246
+ current_environment.update(environment)
247
+ # The API used to allow setting extra to None. We need to handle this
248
+ # case for backwards compatibility.
249
+ if current_environment["extra"] is None:
250
+ current_environment["extra"] = ""
251
+
252
+ return _evaluate_markers(self._markers, current_environment)
env-llmeval/lib/python3.10/site-packages/packaging/metadata.py ADDED
@@ -0,0 +1,825 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import email.feedparser
2
+ import email.header
3
+ import email.message
4
+ import email.parser
5
+ import email.policy
6
+ import sys
7
+ import typing
8
+ from typing import (
9
+ Any,
10
+ Callable,
11
+ Dict,
12
+ Generic,
13
+ List,
14
+ Optional,
15
+ Tuple,
16
+ Type,
17
+ Union,
18
+ cast,
19
+ )
20
+
21
+ from . import requirements, specifiers, utils, version as version_module
22
+
23
+ T = typing.TypeVar("T")
24
+ if sys.version_info[:2] >= (3, 8): # pragma: no cover
25
+ from typing import Literal, TypedDict
26
+ else: # pragma: no cover
27
+ if typing.TYPE_CHECKING:
28
+ from typing_extensions import Literal, TypedDict
29
+ else:
30
+ try:
31
+ from typing_extensions import Literal, TypedDict
32
+ except ImportError:
33
+
34
+ class Literal:
35
+ def __init_subclass__(*_args, **_kwargs):
36
+ pass
37
+
38
+ class TypedDict:
39
+ def __init_subclass__(*_args, **_kwargs):
40
+ pass
41
+
42
+
43
+ try:
44
+ ExceptionGroup
45
+ except NameError: # pragma: no cover
46
+
47
+ class ExceptionGroup(Exception): # noqa: N818
48
+ """A minimal implementation of :external:exc:`ExceptionGroup` from Python 3.11.
49
+
50
+ If :external:exc:`ExceptionGroup` is already defined by Python itself,
51
+ that version is used instead.
52
+ """
53
+
54
+ message: str
55
+ exceptions: List[Exception]
56
+
57
+ def __init__(self, message: str, exceptions: List[Exception]) -> None:
58
+ self.message = message
59
+ self.exceptions = exceptions
60
+
61
+ def __repr__(self) -> str:
62
+ return f"{self.__class__.__name__}({self.message!r}, {self.exceptions!r})"
63
+
64
+ else: # pragma: no cover
65
+ ExceptionGroup = ExceptionGroup
66
+
67
+
68
+ class InvalidMetadata(ValueError):
69
+ """A metadata field contains invalid data."""
70
+
71
+ field: str
72
+ """The name of the field that contains invalid data."""
73
+
74
+ def __init__(self, field: str, message: str) -> None:
75
+ self.field = field
76
+ super().__init__(message)
77
+
78
+
79
+ # The RawMetadata class attempts to make as few assumptions about the underlying
80
+ # serialization formats as possible. The idea is that as long as a serialization
81
+ # formats offer some very basic primitives in *some* way then we can support
82
+ # serializing to and from that format.
83
+ class RawMetadata(TypedDict, total=False):
84
+ """A dictionary of raw core metadata.
85
+
86
+ Each field in core metadata maps to a key of this dictionary (when data is
87
+ provided). The key is lower-case and underscores are used instead of dashes
88
+ compared to the equivalent core metadata field. Any core metadata field that
89
+ can be specified multiple times or can hold multiple values in a single
90
+ field have a key with a plural name. See :class:`Metadata` whose attributes
91
+ match the keys of this dictionary.
92
+
93
+ Core metadata fields that can be specified multiple times are stored as a
94
+ list or dict depending on which is appropriate for the field. Any fields
95
+ which hold multiple values in a single field are stored as a list.
96
+
97
+ """
98
+
99
+ # Metadata 1.0 - PEP 241
100
+ metadata_version: str
101
+ name: str
102
+ version: str
103
+ platforms: List[str]
104
+ summary: str
105
+ description: str
106
+ keywords: List[str]
107
+ home_page: str
108
+ author: str
109
+ author_email: str
110
+ license: str
111
+
112
+ # Metadata 1.1 - PEP 314
113
+ supported_platforms: List[str]
114
+ download_url: str
115
+ classifiers: List[str]
116
+ requires: List[str]
117
+ provides: List[str]
118
+ obsoletes: List[str]
119
+
120
+ # Metadata 1.2 - PEP 345
121
+ maintainer: str
122
+ maintainer_email: str
123
+ requires_dist: List[str]
124
+ provides_dist: List[str]
125
+ obsoletes_dist: List[str]
126
+ requires_python: str
127
+ requires_external: List[str]
128
+ project_urls: Dict[str, str]
129
+
130
+ # Metadata 2.0
131
+ # PEP 426 attempted to completely revamp the metadata format
132
+ # but got stuck without ever being able to build consensus on
133
+ # it and ultimately ended up withdrawn.
134
+ #
135
+ # However, a number of tools had started emitting METADATA with
136
+ # `2.0` Metadata-Version, so for historical reasons, this version
137
+ # was skipped.
138
+
139
+ # Metadata 2.1 - PEP 566
140
+ description_content_type: str
141
+ provides_extra: List[str]
142
+
143
+ # Metadata 2.2 - PEP 643
144
+ dynamic: List[str]
145
+
146
+ # Metadata 2.3 - PEP 685
147
+ # No new fields were added in PEP 685, just some edge case were
148
+ # tightened up to provide better interoptability.
149
+
150
+
151
+ _STRING_FIELDS = {
152
+ "author",
153
+ "author_email",
154
+ "description",
155
+ "description_content_type",
156
+ "download_url",
157
+ "home_page",
158
+ "license",
159
+ "maintainer",
160
+ "maintainer_email",
161
+ "metadata_version",
162
+ "name",
163
+ "requires_python",
164
+ "summary",
165
+ "version",
166
+ }
167
+
168
+ _LIST_FIELDS = {
169
+ "classifiers",
170
+ "dynamic",
171
+ "obsoletes",
172
+ "obsoletes_dist",
173
+ "platforms",
174
+ "provides",
175
+ "provides_dist",
176
+ "provides_extra",
177
+ "requires",
178
+ "requires_dist",
179
+ "requires_external",
180
+ "supported_platforms",
181
+ }
182
+
183
+ _DICT_FIELDS = {
184
+ "project_urls",
185
+ }
186
+
187
+
188
+ def _parse_keywords(data: str) -> List[str]:
189
+ """Split a string of comma-separate keyboards into a list of keywords."""
190
+ return [k.strip() for k in data.split(",")]
191
+
192
+
193
+ def _parse_project_urls(data: List[str]) -> Dict[str, str]:
194
+ """Parse a list of label/URL string pairings separated by a comma."""
195
+ urls = {}
196
+ for pair in data:
197
+ # Our logic is slightly tricky here as we want to try and do
198
+ # *something* reasonable with malformed data.
199
+ #
200
+ # The main thing that we have to worry about, is data that does
201
+ # not have a ',' at all to split the label from the Value. There
202
+ # isn't a singular right answer here, and we will fail validation
203
+ # later on (if the caller is validating) so it doesn't *really*
204
+ # matter, but since the missing value has to be an empty str
205
+ # and our return value is dict[str, str], if we let the key
206
+ # be the missing value, then they'd have multiple '' values that
207
+ # overwrite each other in a accumulating dict.
208
+ #
209
+ # The other potentional issue is that it's possible to have the
210
+ # same label multiple times in the metadata, with no solid "right"
211
+ # answer with what to do in that case. As such, we'll do the only
212
+ # thing we can, which is treat the field as unparseable and add it
213
+ # to our list of unparsed fields.
214
+ parts = [p.strip() for p in pair.split(",", 1)]
215
+ parts.extend([""] * (max(0, 2 - len(parts)))) # Ensure 2 items
216
+
217
+ # TODO: The spec doesn't say anything about if the keys should be
218
+ # considered case sensitive or not... logically they should
219
+ # be case-preserving and case-insensitive, but doing that
220
+ # would open up more cases where we might have duplicate
221
+ # entries.
222
+ label, url = parts
223
+ if label in urls:
224
+ # The label already exists in our set of urls, so this field
225
+ # is unparseable, and we can just add the whole thing to our
226
+ # unparseable data and stop processing it.
227
+ raise KeyError("duplicate labels in project urls")
228
+ urls[label] = url
229
+
230
+ return urls
231
+
232
+
233
+ def _get_payload(msg: email.message.Message, source: Union[bytes, str]) -> str:
234
+ """Get the body of the message."""
235
+ # If our source is a str, then our caller has managed encodings for us,
236
+ # and we don't need to deal with it.
237
+ if isinstance(source, str):
238
+ payload: str = msg.get_payload()
239
+ return payload
240
+ # If our source is a bytes, then we're managing the encoding and we need
241
+ # to deal with it.
242
+ else:
243
+ bpayload: bytes = msg.get_payload(decode=True)
244
+ try:
245
+ return bpayload.decode("utf8", "strict")
246
+ except UnicodeDecodeError:
247
+ raise ValueError("payload in an invalid encoding")
248
+
249
+
250
+ # The various parse_FORMAT functions here are intended to be as lenient as
251
+ # possible in their parsing, while still returning a correctly typed
252
+ # RawMetadata.
253
+ #
254
+ # To aid in this, we also generally want to do as little touching of the
255
+ # data as possible, except where there are possibly some historic holdovers
256
+ # that make valid data awkward to work with.
257
+ #
258
+ # While this is a lower level, intermediate format than our ``Metadata``
259
+ # class, some light touch ups can make a massive difference in usability.
260
+
261
+ # Map METADATA fields to RawMetadata.
262
+ _EMAIL_TO_RAW_MAPPING = {
263
+ "author": "author",
264
+ "author-email": "author_email",
265
+ "classifier": "classifiers",
266
+ "description": "description",
267
+ "description-content-type": "description_content_type",
268
+ "download-url": "download_url",
269
+ "dynamic": "dynamic",
270
+ "home-page": "home_page",
271
+ "keywords": "keywords",
272
+ "license": "license",
273
+ "maintainer": "maintainer",
274
+ "maintainer-email": "maintainer_email",
275
+ "metadata-version": "metadata_version",
276
+ "name": "name",
277
+ "obsoletes": "obsoletes",
278
+ "obsoletes-dist": "obsoletes_dist",
279
+ "platform": "platforms",
280
+ "project-url": "project_urls",
281
+ "provides": "provides",
282
+ "provides-dist": "provides_dist",
283
+ "provides-extra": "provides_extra",
284
+ "requires": "requires",
285
+ "requires-dist": "requires_dist",
286
+ "requires-external": "requires_external",
287
+ "requires-python": "requires_python",
288
+ "summary": "summary",
289
+ "supported-platform": "supported_platforms",
290
+ "version": "version",
291
+ }
292
+ _RAW_TO_EMAIL_MAPPING = {raw: email for email, raw in _EMAIL_TO_RAW_MAPPING.items()}
293
+
294
+
295
+ def parse_email(data: Union[bytes, str]) -> Tuple[RawMetadata, Dict[str, List[str]]]:
296
+ """Parse a distribution's metadata stored as email headers (e.g. from ``METADATA``).
297
+
298
+ This function returns a two-item tuple of dicts. The first dict is of
299
+ recognized fields from the core metadata specification. Fields that can be
300
+ parsed and translated into Python's built-in types are converted
301
+ appropriately. All other fields are left as-is. Fields that are allowed to
302
+ appear multiple times are stored as lists.
303
+
304
+ The second dict contains all other fields from the metadata. This includes
305
+ any unrecognized fields. It also includes any fields which are expected to
306
+ be parsed into a built-in type but were not formatted appropriately. Finally,
307
+ any fields that are expected to appear only once but are repeated are
308
+ included in this dict.
309
+
310
+ """
311
+ raw: Dict[str, Union[str, List[str], Dict[str, str]]] = {}
312
+ unparsed: Dict[str, List[str]] = {}
313
+
314
+ if isinstance(data, str):
315
+ parsed = email.parser.Parser(policy=email.policy.compat32).parsestr(data)
316
+ else:
317
+ parsed = email.parser.BytesParser(policy=email.policy.compat32).parsebytes(data)
318
+
319
+ # We have to wrap parsed.keys() in a set, because in the case of multiple
320
+ # values for a key (a list), the key will appear multiple times in the
321
+ # list of keys, but we're avoiding that by using get_all().
322
+ for name in frozenset(parsed.keys()):
323
+ # Header names in RFC are case insensitive, so we'll normalize to all
324
+ # lower case to make comparisons easier.
325
+ name = name.lower()
326
+
327
+ # We use get_all() here, even for fields that aren't multiple use,
328
+ # because otherwise someone could have e.g. two Name fields, and we
329
+ # would just silently ignore it rather than doing something about it.
330
+ headers = parsed.get_all(name) or []
331
+
332
+ # The way the email module works when parsing bytes is that it
333
+ # unconditionally decodes the bytes as ascii using the surrogateescape
334
+ # handler. When you pull that data back out (such as with get_all() ),
335
+ # it looks to see if the str has any surrogate escapes, and if it does
336
+ # it wraps it in a Header object instead of returning the string.
337
+ #
338
+ # As such, we'll look for those Header objects, and fix up the encoding.
339
+ value = []
340
+ # Flag if we have run into any issues processing the headers, thus
341
+ # signalling that the data belongs in 'unparsed'.
342
+ valid_encoding = True
343
+ for h in headers:
344
+ # It's unclear if this can return more types than just a Header or
345
+ # a str, so we'll just assert here to make sure.
346
+ assert isinstance(h, (email.header.Header, str))
347
+
348
+ # If it's a header object, we need to do our little dance to get
349
+ # the real data out of it. In cases where there is invalid data
350
+ # we're going to end up with mojibake, but there's no obvious, good
351
+ # way around that without reimplementing parts of the Header object
352
+ # ourselves.
353
+ #
354
+ # That should be fine since, if mojibacked happens, this key is
355
+ # going into the unparsed dict anyways.
356
+ if isinstance(h, email.header.Header):
357
+ # The Header object stores it's data as chunks, and each chunk
358
+ # can be independently encoded, so we'll need to check each
359
+ # of them.
360
+ chunks: List[Tuple[bytes, Optional[str]]] = []
361
+ for bin, encoding in email.header.decode_header(h):
362
+ try:
363
+ bin.decode("utf8", "strict")
364
+ except UnicodeDecodeError:
365
+ # Enable mojibake.
366
+ encoding = "latin1"
367
+ valid_encoding = False
368
+ else:
369
+ encoding = "utf8"
370
+ chunks.append((bin, encoding))
371
+
372
+ # Turn our chunks back into a Header object, then let that
373
+ # Header object do the right thing to turn them into a
374
+ # string for us.
375
+ value.append(str(email.header.make_header(chunks)))
376
+ # This is already a string, so just add it.
377
+ else:
378
+ value.append(h)
379
+
380
+ # We've processed all of our values to get them into a list of str,
381
+ # but we may have mojibake data, in which case this is an unparsed
382
+ # field.
383
+ if not valid_encoding:
384
+ unparsed[name] = value
385
+ continue
386
+
387
+ raw_name = _EMAIL_TO_RAW_MAPPING.get(name)
388
+ if raw_name is None:
389
+ # This is a bit of a weird situation, we've encountered a key that
390
+ # we don't know what it means, so we don't know whether it's meant
391
+ # to be a list or not.
392
+ #
393
+ # Since we can't really tell one way or another, we'll just leave it
394
+ # as a list, even though it may be a single item list, because that's
395
+ # what makes the most sense for email headers.
396
+ unparsed[name] = value
397
+ continue
398
+
399
+ # If this is one of our string fields, then we'll check to see if our
400
+ # value is a list of a single item. If it is then we'll assume that
401
+ # it was emitted as a single string, and unwrap the str from inside
402
+ # the list.
403
+ #
404
+ # If it's any other kind of data, then we haven't the faintest clue
405
+ # what we should parse it as, and we have to just add it to our list
406
+ # of unparsed stuff.
407
+ if raw_name in _STRING_FIELDS and len(value) == 1:
408
+ raw[raw_name] = value[0]
409
+ # If this is one of our list of string fields, then we can just assign
410
+ # the value, since email *only* has strings, and our get_all() call
411
+ # above ensures that this is a list.
412
+ elif raw_name in _LIST_FIELDS:
413
+ raw[raw_name] = value
414
+ # Special Case: Keywords
415
+ # The keywords field is implemented in the metadata spec as a str,
416
+ # but it conceptually is a list of strings, and is serialized using
417
+ # ", ".join(keywords), so we'll do some light data massaging to turn
418
+ # this into what it logically is.
419
+ elif raw_name == "keywords" and len(value) == 1:
420
+ raw[raw_name] = _parse_keywords(value[0])
421
+ # Special Case: Project-URL
422
+ # The project urls is implemented in the metadata spec as a list of
423
+ # specially-formatted strings that represent a key and a value, which
424
+ # is fundamentally a mapping, however the email format doesn't support
425
+ # mappings in a sane way, so it was crammed into a list of strings
426
+ # instead.
427
+ #
428
+ # We will do a little light data massaging to turn this into a map as
429
+ # it logically should be.
430
+ elif raw_name == "project_urls":
431
+ try:
432
+ raw[raw_name] = _parse_project_urls(value)
433
+ except KeyError:
434
+ unparsed[name] = value
435
+ # Nothing that we've done has managed to parse this, so it'll just
436
+ # throw it in our unparseable data and move on.
437
+ else:
438
+ unparsed[name] = value
439
+
440
+ # We need to support getting the Description from the message payload in
441
+ # addition to getting it from the the headers. This does mean, though, there
442
+ # is the possibility of it being set both ways, in which case we put both
443
+ # in 'unparsed' since we don't know which is right.
444
+ try:
445
+ payload = _get_payload(parsed, data)
446
+ except ValueError:
447
+ unparsed.setdefault("description", []).append(
448
+ parsed.get_payload(decode=isinstance(data, bytes))
449
+ )
450
+ else:
451
+ if payload:
452
+ # Check to see if we've already got a description, if so then both
453
+ # it, and this body move to unparseable.
454
+ if "description" in raw:
455
+ description_header = cast(str, raw.pop("description"))
456
+ unparsed.setdefault("description", []).extend(
457
+ [description_header, payload]
458
+ )
459
+ elif "description" in unparsed:
460
+ unparsed["description"].append(payload)
461
+ else:
462
+ raw["description"] = payload
463
+
464
+ # We need to cast our `raw` to a metadata, because a TypedDict only support
465
+ # literal key names, but we're computing our key names on purpose, but the
466
+ # way this function is implemented, our `TypedDict` can only have valid key
467
+ # names.
468
+ return cast(RawMetadata, raw), unparsed
469
+
470
+
471
+ _NOT_FOUND = object()
472
+
473
+
474
+ # Keep the two values in sync.
475
+ _VALID_METADATA_VERSIONS = ["1.0", "1.1", "1.2", "2.1", "2.2", "2.3"]
476
+ _MetadataVersion = Literal["1.0", "1.1", "1.2", "2.1", "2.2", "2.3"]
477
+
478
+ _REQUIRED_ATTRS = frozenset(["metadata_version", "name", "version"])
479
+
480
+
481
+ class _Validator(Generic[T]):
482
+ """Validate a metadata field.
483
+
484
+ All _process_*() methods correspond to a core metadata field. The method is
485
+ called with the field's raw value. If the raw value is valid it is returned
486
+ in its "enriched" form (e.g. ``version.Version`` for the ``Version`` field).
487
+ If the raw value is invalid, :exc:`InvalidMetadata` is raised (with a cause
488
+ as appropriate).
489
+ """
490
+
491
+ name: str
492
+ raw_name: str
493
+ added: _MetadataVersion
494
+
495
+ def __init__(
496
+ self,
497
+ *,
498
+ added: _MetadataVersion = "1.0",
499
+ ) -> None:
500
+ self.added = added
501
+
502
+ def __set_name__(self, _owner: "Metadata", name: str) -> None:
503
+ self.name = name
504
+ self.raw_name = _RAW_TO_EMAIL_MAPPING[name]
505
+
506
+ def __get__(self, instance: "Metadata", _owner: Type["Metadata"]) -> T:
507
+ # With Python 3.8, the caching can be replaced with functools.cached_property().
508
+ # No need to check the cache as attribute lookup will resolve into the
509
+ # instance's __dict__ before __get__ is called.
510
+ cache = instance.__dict__
511
+ value = instance._raw.get(self.name)
512
+
513
+ # To make the _process_* methods easier, we'll check if the value is None
514
+ # and if this field is NOT a required attribute, and if both of those
515
+ # things are true, we'll skip the the converter. This will mean that the
516
+ # converters never have to deal with the None union.
517
+ if self.name in _REQUIRED_ATTRS or value is not None:
518
+ try:
519
+ converter: Callable[[Any], T] = getattr(self, f"_process_{self.name}")
520
+ except AttributeError:
521
+ pass
522
+ else:
523
+ value = converter(value)
524
+
525
+ cache[self.name] = value
526
+ try:
527
+ del instance._raw[self.name] # type: ignore[misc]
528
+ except KeyError:
529
+ pass
530
+
531
+ return cast(T, value)
532
+
533
+ def _invalid_metadata(
534
+ self, msg: str, cause: Optional[Exception] = None
535
+ ) -> InvalidMetadata:
536
+ exc = InvalidMetadata(
537
+ self.raw_name, msg.format_map({"field": repr(self.raw_name)})
538
+ )
539
+ exc.__cause__ = cause
540
+ return exc
541
+
542
+ def _process_metadata_version(self, value: str) -> _MetadataVersion:
543
+ # Implicitly makes Metadata-Version required.
544
+ if value not in _VALID_METADATA_VERSIONS:
545
+ raise self._invalid_metadata(f"{value!r} is not a valid metadata version")
546
+ return cast(_MetadataVersion, value)
547
+
548
+ def _process_name(self, value: str) -> str:
549
+ if not value:
550
+ raise self._invalid_metadata("{field} is a required field")
551
+ # Validate the name as a side-effect.
552
+ try:
553
+ utils.canonicalize_name(value, validate=True)
554
+ except utils.InvalidName as exc:
555
+ raise self._invalid_metadata(
556
+ f"{value!r} is invalid for {{field}}", cause=exc
557
+ )
558
+ else:
559
+ return value
560
+
561
+ def _process_version(self, value: str) -> version_module.Version:
562
+ if not value:
563
+ raise self._invalid_metadata("{field} is a required field")
564
+ try:
565
+ return version_module.parse(value)
566
+ except version_module.InvalidVersion as exc:
567
+ raise self._invalid_metadata(
568
+ f"{value!r} is invalid for {{field}}", cause=exc
569
+ )
570
+
571
+ def _process_summary(self, value: str) -> str:
572
+ """Check the field contains no newlines."""
573
+ if "\n" in value:
574
+ raise self._invalid_metadata("{field} must be a single line")
575
+ return value
576
+
577
+ def _process_description_content_type(self, value: str) -> str:
578
+ content_types = {"text/plain", "text/x-rst", "text/markdown"}
579
+ message = email.message.EmailMessage()
580
+ message["content-type"] = value
581
+
582
+ content_type, parameters = (
583
+ # Defaults to `text/plain` if parsing failed.
584
+ message.get_content_type().lower(),
585
+ message["content-type"].params,
586
+ )
587
+ # Check if content-type is valid or defaulted to `text/plain` and thus was
588
+ # not parseable.
589
+ if content_type not in content_types or content_type not in value.lower():
590
+ raise self._invalid_metadata(
591
+ f"{{field}} must be one of {list(content_types)}, not {value!r}"
592
+ )
593
+
594
+ charset = parameters.get("charset", "UTF-8")
595
+ if charset != "UTF-8":
596
+ raise self._invalid_metadata(
597
+ f"{{field}} can only specify the UTF-8 charset, not {list(charset)}"
598
+ )
599
+
600
+ markdown_variants = {"GFM", "CommonMark"}
601
+ variant = parameters.get("variant", "GFM") # Use an acceptable default.
602
+ if content_type == "text/markdown" and variant not in markdown_variants:
603
+ raise self._invalid_metadata(
604
+ f"valid Markdown variants for {{field}} are {list(markdown_variants)}, "
605
+ f"not {variant!r}",
606
+ )
607
+ return value
608
+
609
+ def _process_dynamic(self, value: List[str]) -> List[str]:
610
+ for dynamic_field in map(str.lower, value):
611
+ if dynamic_field in {"name", "version", "metadata-version"}:
612
+ raise self._invalid_metadata(
613
+ f"{value!r} is not allowed as a dynamic field"
614
+ )
615
+ elif dynamic_field not in _EMAIL_TO_RAW_MAPPING:
616
+ raise self._invalid_metadata(f"{value!r} is not a valid dynamic field")
617
+ return list(map(str.lower, value))
618
+
619
+ def _process_provides_extra(
620
+ self,
621
+ value: List[str],
622
+ ) -> List[utils.NormalizedName]:
623
+ normalized_names = []
624
+ try:
625
+ for name in value:
626
+ normalized_names.append(utils.canonicalize_name(name, validate=True))
627
+ except utils.InvalidName as exc:
628
+ raise self._invalid_metadata(
629
+ f"{name!r} is invalid for {{field}}", cause=exc
630
+ )
631
+ else:
632
+ return normalized_names
633
+
634
+ def _process_requires_python(self, value: str) -> specifiers.SpecifierSet:
635
+ try:
636
+ return specifiers.SpecifierSet(value)
637
+ except specifiers.InvalidSpecifier as exc:
638
+ raise self._invalid_metadata(
639
+ f"{value!r} is invalid for {{field}}", cause=exc
640
+ )
641
+
642
+ def _process_requires_dist(
643
+ self,
644
+ value: List[str],
645
+ ) -> List[requirements.Requirement]:
646
+ reqs = []
647
+ try:
648
+ for req in value:
649
+ reqs.append(requirements.Requirement(req))
650
+ except requirements.InvalidRequirement as exc:
651
+ raise self._invalid_metadata(f"{req!r} is invalid for {{field}}", cause=exc)
652
+ else:
653
+ return reqs
654
+
655
+
656
+ class Metadata:
657
+ """Representation of distribution metadata.
658
+
659
+ Compared to :class:`RawMetadata`, this class provides objects representing
660
+ metadata fields instead of only using built-in types. Any invalid metadata
661
+ will cause :exc:`InvalidMetadata` to be raised (with a
662
+ :py:attr:`~BaseException.__cause__` attribute as appropriate).
663
+ """
664
+
665
+ _raw: RawMetadata
666
+
667
+ @classmethod
668
+ def from_raw(cls, data: RawMetadata, *, validate: bool = True) -> "Metadata":
669
+ """Create an instance from :class:`RawMetadata`.
670
+
671
+ If *validate* is true, all metadata will be validated. All exceptions
672
+ related to validation will be gathered and raised as an :class:`ExceptionGroup`.
673
+ """
674
+ ins = cls()
675
+ ins._raw = data.copy() # Mutations occur due to caching enriched values.
676
+
677
+ if validate:
678
+ exceptions: List[Exception] = []
679
+ try:
680
+ metadata_version = ins.metadata_version
681
+ metadata_age = _VALID_METADATA_VERSIONS.index(metadata_version)
682
+ except InvalidMetadata as metadata_version_exc:
683
+ exceptions.append(metadata_version_exc)
684
+ metadata_version = None
685
+
686
+ # Make sure to check for the fields that are present, the required
687
+ # fields (so their absence can be reported).
688
+ fields_to_check = frozenset(ins._raw) | _REQUIRED_ATTRS
689
+ # Remove fields that have already been checked.
690
+ fields_to_check -= {"metadata_version"}
691
+
692
+ for key in fields_to_check:
693
+ try:
694
+ if metadata_version:
695
+ # Can't use getattr() as that triggers descriptor protocol which
696
+ # will fail due to no value for the instance argument.
697
+ try:
698
+ field_metadata_version = cls.__dict__[key].added
699
+ except KeyError:
700
+ exc = InvalidMetadata(key, f"unrecognized field: {key!r}")
701
+ exceptions.append(exc)
702
+ continue
703
+ field_age = _VALID_METADATA_VERSIONS.index(
704
+ field_metadata_version
705
+ )
706
+ if field_age > metadata_age:
707
+ field = _RAW_TO_EMAIL_MAPPING[key]
708
+ exc = InvalidMetadata(
709
+ field,
710
+ "{field} introduced in metadata version "
711
+ "{field_metadata_version}, not {metadata_version}",
712
+ )
713
+ exceptions.append(exc)
714
+ continue
715
+ getattr(ins, key)
716
+ except InvalidMetadata as exc:
717
+ exceptions.append(exc)
718
+
719
+ if exceptions:
720
+ raise ExceptionGroup("invalid metadata", exceptions)
721
+
722
+ return ins
723
+
724
+ @classmethod
725
+ def from_email(
726
+ cls, data: Union[bytes, str], *, validate: bool = True
727
+ ) -> "Metadata":
728
+ """Parse metadata from email headers.
729
+
730
+ If *validate* is true, the metadata will be validated. All exceptions
731
+ related to validation will be gathered and raised as an :class:`ExceptionGroup`.
732
+ """
733
+ raw, unparsed = parse_email(data)
734
+
735
+ if validate:
736
+ exceptions: list[Exception] = []
737
+ for unparsed_key in unparsed:
738
+ if unparsed_key in _EMAIL_TO_RAW_MAPPING:
739
+ message = f"{unparsed_key!r} has invalid data"
740
+ else:
741
+ message = f"unrecognized field: {unparsed_key!r}"
742
+ exceptions.append(InvalidMetadata(unparsed_key, message))
743
+
744
+ if exceptions:
745
+ raise ExceptionGroup("unparsed", exceptions)
746
+
747
+ try:
748
+ return cls.from_raw(raw, validate=validate)
749
+ except ExceptionGroup as exc_group:
750
+ raise ExceptionGroup(
751
+ "invalid or unparsed metadata", exc_group.exceptions
752
+ ) from None
753
+
754
+ metadata_version: _Validator[_MetadataVersion] = _Validator()
755
+ """:external:ref:`core-metadata-metadata-version`
756
+ (required; validated to be a valid metadata version)"""
757
+ name: _Validator[str] = _Validator()
758
+ """:external:ref:`core-metadata-name`
759
+ (required; validated using :func:`~packaging.utils.canonicalize_name` and its
760
+ *validate* parameter)"""
761
+ version: _Validator[version_module.Version] = _Validator()
762
+ """:external:ref:`core-metadata-version` (required)"""
763
+ dynamic: _Validator[Optional[List[str]]] = _Validator(
764
+ added="2.2",
765
+ )
766
+ """:external:ref:`core-metadata-dynamic`
767
+ (validated against core metadata field names and lowercased)"""
768
+ platforms: _Validator[Optional[List[str]]] = _Validator()
769
+ """:external:ref:`core-metadata-platform`"""
770
+ supported_platforms: _Validator[Optional[List[str]]] = _Validator(added="1.1")
771
+ """:external:ref:`core-metadata-supported-platform`"""
772
+ summary: _Validator[Optional[str]] = _Validator()
773
+ """:external:ref:`core-metadata-summary` (validated to contain no newlines)"""
774
+ description: _Validator[Optional[str]] = _Validator() # TODO 2.1: can be in body
775
+ """:external:ref:`core-metadata-description`"""
776
+ description_content_type: _Validator[Optional[str]] = _Validator(added="2.1")
777
+ """:external:ref:`core-metadata-description-content-type` (validated)"""
778
+ keywords: _Validator[Optional[List[str]]] = _Validator()
779
+ """:external:ref:`core-metadata-keywords`"""
780
+ home_page: _Validator[Optional[str]] = _Validator()
781
+ """:external:ref:`core-metadata-home-page`"""
782
+ download_url: _Validator[Optional[str]] = _Validator(added="1.1")
783
+ """:external:ref:`core-metadata-download-url`"""
784
+ author: _Validator[Optional[str]] = _Validator()
785
+ """:external:ref:`core-metadata-author`"""
786
+ author_email: _Validator[Optional[str]] = _Validator()
787
+ """:external:ref:`core-metadata-author-email`"""
788
+ maintainer: _Validator[Optional[str]] = _Validator(added="1.2")
789
+ """:external:ref:`core-metadata-maintainer`"""
790
+ maintainer_email: _Validator[Optional[str]] = _Validator(added="1.2")
791
+ """:external:ref:`core-metadata-maintainer-email`"""
792
+ license: _Validator[Optional[str]] = _Validator()
793
+ """:external:ref:`core-metadata-license`"""
794
+ classifiers: _Validator[Optional[List[str]]] = _Validator(added="1.1")
795
+ """:external:ref:`core-metadata-classifier`"""
796
+ requires_dist: _Validator[Optional[List[requirements.Requirement]]] = _Validator(
797
+ added="1.2"
798
+ )
799
+ """:external:ref:`core-metadata-requires-dist`"""
800
+ requires_python: _Validator[Optional[specifiers.SpecifierSet]] = _Validator(
801
+ added="1.2"
802
+ )
803
+ """:external:ref:`core-metadata-requires-python`"""
804
+ # Because `Requires-External` allows for non-PEP 440 version specifiers, we
805
+ # don't do any processing on the values.
806
+ requires_external: _Validator[Optional[List[str]]] = _Validator(added="1.2")
807
+ """:external:ref:`core-metadata-requires-external`"""
808
+ project_urls: _Validator[Optional[Dict[str, str]]] = _Validator(added="1.2")
809
+ """:external:ref:`core-metadata-project-url`"""
810
+ # PEP 685 lets us raise an error if an extra doesn't pass `Name` validation
811
+ # regardless of metadata version.
812
+ provides_extra: _Validator[Optional[List[utils.NormalizedName]]] = _Validator(
813
+ added="2.1",
814
+ )
815
+ """:external:ref:`core-metadata-provides-extra`"""
816
+ provides_dist: _Validator[Optional[List[str]]] = _Validator(added="1.2")
817
+ """:external:ref:`core-metadata-provides-dist`"""
818
+ obsoletes_dist: _Validator[Optional[List[str]]] = _Validator(added="1.2")
819
+ """:external:ref:`core-metadata-obsoletes-dist`"""
820
+ requires: _Validator[Optional[List[str]]] = _Validator(added="1.1")
821
+ """``Requires`` (deprecated)"""
822
+ provides: _Validator[Optional[List[str]]] = _Validator(added="1.1")
823
+ """``Provides`` (deprecated)"""
824
+ obsoletes: _Validator[Optional[List[str]]] = _Validator(added="1.1")
825
+ """``Obsoletes`` (deprecated)"""
env-llmeval/lib/python3.10/site-packages/packaging/py.typed ADDED
File without changes
env-llmeval/lib/python3.10/site-packages/packaging/requirements.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ from typing import Any, Iterator, Optional, Set
6
+
7
+ from ._parser import parse_requirement as _parse_requirement
8
+ from ._tokenizer import ParserSyntaxError
9
+ from .markers import Marker, _normalize_extra_values
10
+ from .specifiers import SpecifierSet
11
+ from .utils import canonicalize_name
12
+
13
+
14
+ class InvalidRequirement(ValueError):
15
+ """
16
+ An invalid requirement was found, users should refer to PEP 508.
17
+ """
18
+
19
+
20
+ class Requirement:
21
+ """Parse a requirement.
22
+
23
+ Parse a given requirement string into its parts, such as name, specifier,
24
+ URL, and extras. Raises InvalidRequirement on a badly-formed requirement
25
+ string.
26
+ """
27
+
28
+ # TODO: Can we test whether something is contained within a requirement?
29
+ # If so how do we do that? Do we need to test against the _name_ of
30
+ # the thing as well as the version? What about the markers?
31
+ # TODO: Can we normalize the name and extra name?
32
+
33
+ def __init__(self, requirement_string: str) -> None:
34
+ try:
35
+ parsed = _parse_requirement(requirement_string)
36
+ except ParserSyntaxError as e:
37
+ raise InvalidRequirement(str(e)) from e
38
+
39
+ self.name: str = parsed.name
40
+ self.url: Optional[str] = parsed.url or None
41
+ self.extras: Set[str] = set(parsed.extras or [])
42
+ self.specifier: SpecifierSet = SpecifierSet(parsed.specifier)
43
+ self.marker: Optional[Marker] = None
44
+ if parsed.marker is not None:
45
+ self.marker = Marker.__new__(Marker)
46
+ self.marker._markers = _normalize_extra_values(parsed.marker)
47
+
48
+ def _iter_parts(self, name: str) -> Iterator[str]:
49
+ yield name
50
+
51
+ if self.extras:
52
+ formatted_extras = ",".join(sorted(self.extras))
53
+ yield f"[{formatted_extras}]"
54
+
55
+ if self.specifier:
56
+ yield str(self.specifier)
57
+
58
+ if self.url:
59
+ yield f"@ {self.url}"
60
+ if self.marker:
61
+ yield " "
62
+
63
+ if self.marker:
64
+ yield f"; {self.marker}"
65
+
66
+ def __str__(self) -> str:
67
+ return "".join(self._iter_parts(self.name))
68
+
69
+ def __repr__(self) -> str:
70
+ return f"<Requirement('{self}')>"
71
+
72
+ def __hash__(self) -> int:
73
+ return hash(
74
+ (
75
+ self.__class__.__name__,
76
+ *self._iter_parts(canonicalize_name(self.name)),
77
+ )
78
+ )
79
+
80
+ def __eq__(self, other: Any) -> bool:
81
+ if not isinstance(other, Requirement):
82
+ return NotImplemented
83
+
84
+ return (
85
+ canonicalize_name(self.name) == canonicalize_name(other.name)
86
+ and self.extras == other.extras
87
+ and self.specifier == other.specifier
88
+ and self.url == other.url
89
+ and self.marker == other.marker
90
+ )
env-llmeval/lib/python3.10/site-packages/packaging/specifiers.py ADDED
@@ -0,0 +1,1017 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+ """
5
+ .. testsetup::
6
+
7
+ from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
8
+ from packaging.version import Version
9
+ """
10
+
11
+ import abc
12
+ import itertools
13
+ import re
14
+ from typing import Callable, Iterable, Iterator, List, Optional, Tuple, TypeVar, Union
15
+
16
+ from .utils import canonicalize_version
17
+ from .version import Version
18
+
19
+ UnparsedVersion = Union[Version, str]
20
+ UnparsedVersionVar = TypeVar("UnparsedVersionVar", bound=UnparsedVersion)
21
+ CallableOperator = Callable[[Version, str], bool]
22
+
23
+
24
+ def _coerce_version(version: UnparsedVersion) -> Version:
25
+ if not isinstance(version, Version):
26
+ version = Version(version)
27
+ return version
28
+
29
+
30
+ class InvalidSpecifier(ValueError):
31
+ """
32
+ Raised when attempting to create a :class:`Specifier` with a specifier
33
+ string that is invalid.
34
+
35
+ >>> Specifier("lolwat")
36
+ Traceback (most recent call last):
37
+ ...
38
+ packaging.specifiers.InvalidSpecifier: Invalid specifier: 'lolwat'
39
+ """
40
+
41
+
42
+ class BaseSpecifier(metaclass=abc.ABCMeta):
43
+ @abc.abstractmethod
44
+ def __str__(self) -> str:
45
+ """
46
+ Returns the str representation of this Specifier-like object. This
47
+ should be representative of the Specifier itself.
48
+ """
49
+
50
+ @abc.abstractmethod
51
+ def __hash__(self) -> int:
52
+ """
53
+ Returns a hash value for this Specifier-like object.
54
+ """
55
+
56
+ @abc.abstractmethod
57
+ def __eq__(self, other: object) -> bool:
58
+ """
59
+ Returns a boolean representing whether or not the two Specifier-like
60
+ objects are equal.
61
+
62
+ :param other: The other object to check against.
63
+ """
64
+
65
+ @property
66
+ @abc.abstractmethod
67
+ def prereleases(self) -> Optional[bool]:
68
+ """Whether or not pre-releases as a whole are allowed.
69
+
70
+ This can be set to either ``True`` or ``False`` to explicitly enable or disable
71
+ prereleases or it can be set to ``None`` (the default) to use default semantics.
72
+ """
73
+
74
+ @prereleases.setter
75
+ def prereleases(self, value: bool) -> None:
76
+ """Setter for :attr:`prereleases`.
77
+
78
+ :param value: The value to set.
79
+ """
80
+
81
+ @abc.abstractmethod
82
+ def contains(self, item: str, prereleases: Optional[bool] = None) -> bool:
83
+ """
84
+ Determines if the given item is contained within this specifier.
85
+ """
86
+
87
+ @abc.abstractmethod
88
+ def filter(
89
+ self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
90
+ ) -> Iterator[UnparsedVersionVar]:
91
+ """
92
+ Takes an iterable of items and filters them so that only items which
93
+ are contained within this specifier are allowed in it.
94
+ """
95
+
96
+
97
+ class Specifier(BaseSpecifier):
98
+ """This class abstracts handling of version specifiers.
99
+
100
+ .. tip::
101
+
102
+ It is generally not required to instantiate this manually. You should instead
103
+ prefer to work with :class:`SpecifierSet` instead, which can parse
104
+ comma-separated version specifiers (which is what package metadata contains).
105
+ """
106
+
107
+ _operator_regex_str = r"""
108
+ (?P<operator>(~=|==|!=|<=|>=|<|>|===))
109
+ """
110
+ _version_regex_str = r"""
111
+ (?P<version>
112
+ (?:
113
+ # The identity operators allow for an escape hatch that will
114
+ # do an exact string match of the version you wish to install.
115
+ # This will not be parsed by PEP 440 and we cannot determine
116
+ # any semantic meaning from it. This operator is discouraged
117
+ # but included entirely as an escape hatch.
118
+ (?<====) # Only match for the identity operator
119
+ \s*
120
+ [^\s;)]* # The arbitrary version can be just about anything,
121
+ # we match everything except for whitespace, a
122
+ # semi-colon for marker support, and a closing paren
123
+ # since versions can be enclosed in them.
124
+ )
125
+ |
126
+ (?:
127
+ # The (non)equality operators allow for wild card and local
128
+ # versions to be specified so we have to define these two
129
+ # operators separately to enable that.
130
+ (?<===|!=) # Only match for equals and not equals
131
+
132
+ \s*
133
+ v?
134
+ (?:[0-9]+!)? # epoch
135
+ [0-9]+(?:\.[0-9]+)* # release
136
+
137
+ # You cannot use a wild card and a pre-release, post-release, a dev or
138
+ # local version together so group them with a | and make them optional.
139
+ (?:
140
+ \.\* # Wild card syntax of .*
141
+ |
142
+ (?: # pre release
143
+ [-_\.]?
144
+ (alpha|beta|preview|pre|a|b|c|rc)
145
+ [-_\.]?
146
+ [0-9]*
147
+ )?
148
+ (?: # post release
149
+ (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
150
+ )?
151
+ (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
152
+ (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
153
+ )?
154
+ )
155
+ |
156
+ (?:
157
+ # The compatible operator requires at least two digits in the
158
+ # release segment.
159
+ (?<=~=) # Only match for the compatible operator
160
+
161
+ \s*
162
+ v?
163
+ (?:[0-9]+!)? # epoch
164
+ [0-9]+(?:\.[0-9]+)+ # release (We have a + instead of a *)
165
+ (?: # pre release
166
+ [-_\.]?
167
+ (alpha|beta|preview|pre|a|b|c|rc)
168
+ [-_\.]?
169
+ [0-9]*
170
+ )?
171
+ (?: # post release
172
+ (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
173
+ )?
174
+ (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
175
+ )
176
+ |
177
+ (?:
178
+ # All other operators only allow a sub set of what the
179
+ # (non)equality operators do. Specifically they do not allow
180
+ # local versions to be specified nor do they allow the prefix
181
+ # matching wild cards.
182
+ (?<!==|!=|~=) # We have special cases for these
183
+ # operators so we want to make sure they
184
+ # don't match here.
185
+
186
+ \s*
187
+ v?
188
+ (?:[0-9]+!)? # epoch
189
+ [0-9]+(?:\.[0-9]+)* # release
190
+ (?: # pre release
191
+ [-_\.]?
192
+ (alpha|beta|preview|pre|a|b|c|rc)
193
+ [-_\.]?
194
+ [0-9]*
195
+ )?
196
+ (?: # post release
197
+ (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
198
+ )?
199
+ (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release
200
+ )
201
+ )
202
+ """
203
+
204
+ _regex = re.compile(
205
+ r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
206
+ re.VERBOSE | re.IGNORECASE,
207
+ )
208
+
209
+ _operators = {
210
+ "~=": "compatible",
211
+ "==": "equal",
212
+ "!=": "not_equal",
213
+ "<=": "less_than_equal",
214
+ ">=": "greater_than_equal",
215
+ "<": "less_than",
216
+ ">": "greater_than",
217
+ "===": "arbitrary",
218
+ }
219
+
220
+ def __init__(self, spec: str = "", prereleases: Optional[bool] = None) -> None:
221
+ """Initialize a Specifier instance.
222
+
223
+ :param spec:
224
+ The string representation of a specifier which will be parsed and
225
+ normalized before use.
226
+ :param prereleases:
227
+ This tells the specifier if it should accept prerelease versions if
228
+ applicable or not. The default of ``None`` will autodetect it from the
229
+ given specifiers.
230
+ :raises InvalidSpecifier:
231
+ If the given specifier is invalid (i.e. bad syntax).
232
+ """
233
+ match = self._regex.search(spec)
234
+ if not match:
235
+ raise InvalidSpecifier(f"Invalid specifier: '{spec}'")
236
+
237
+ self._spec: Tuple[str, str] = (
238
+ match.group("operator").strip(),
239
+ match.group("version").strip(),
240
+ )
241
+
242
+ # Store whether or not this Specifier should accept prereleases
243
+ self._prereleases = prereleases
244
+
245
+ # https://github.com/python/mypy/pull/13475#pullrequestreview-1079784515
246
+ @property # type: ignore[override]
247
+ def prereleases(self) -> bool:
248
+ # If there is an explicit prereleases set for this, then we'll just
249
+ # blindly use that.
250
+ if self._prereleases is not None:
251
+ return self._prereleases
252
+
253
+ # Look at all of our specifiers and determine if they are inclusive
254
+ # operators, and if they are if they are including an explicit
255
+ # prerelease.
256
+ operator, version = self._spec
257
+ if operator in ["==", ">=", "<=", "~=", "==="]:
258
+ # The == specifier can include a trailing .*, if it does we
259
+ # want to remove before parsing.
260
+ if operator == "==" and version.endswith(".*"):
261
+ version = version[:-2]
262
+
263
+ # Parse the version, and if it is a pre-release than this
264
+ # specifier allows pre-releases.
265
+ if Version(version).is_prerelease:
266
+ return True
267
+
268
+ return False
269
+
270
+ @prereleases.setter
271
+ def prereleases(self, value: bool) -> None:
272
+ self._prereleases = value
273
+
274
+ @property
275
+ def operator(self) -> str:
276
+ """The operator of this specifier.
277
+
278
+ >>> Specifier("==1.2.3").operator
279
+ '=='
280
+ """
281
+ return self._spec[0]
282
+
283
+ @property
284
+ def version(self) -> str:
285
+ """The version of this specifier.
286
+
287
+ >>> Specifier("==1.2.3").version
288
+ '1.2.3'
289
+ """
290
+ return self._spec[1]
291
+
292
+ def __repr__(self) -> str:
293
+ """A representation of the Specifier that shows all internal state.
294
+
295
+ >>> Specifier('>=1.0.0')
296
+ <Specifier('>=1.0.0')>
297
+ >>> Specifier('>=1.0.0', prereleases=False)
298
+ <Specifier('>=1.0.0', prereleases=False)>
299
+ >>> Specifier('>=1.0.0', prereleases=True)
300
+ <Specifier('>=1.0.0', prereleases=True)>
301
+ """
302
+ pre = (
303
+ f", prereleases={self.prereleases!r}"
304
+ if self._prereleases is not None
305
+ else ""
306
+ )
307
+
308
+ return f"<{self.__class__.__name__}({str(self)!r}{pre})>"
309
+
310
+ def __str__(self) -> str:
311
+ """A string representation of the Specifier that can be round-tripped.
312
+
313
+ >>> str(Specifier('>=1.0.0'))
314
+ '>=1.0.0'
315
+ >>> str(Specifier('>=1.0.0', prereleases=False))
316
+ '>=1.0.0'
317
+ """
318
+ return "{}{}".format(*self._spec)
319
+
320
+ @property
321
+ def _canonical_spec(self) -> Tuple[str, str]:
322
+ canonical_version = canonicalize_version(
323
+ self._spec[1],
324
+ strip_trailing_zero=(self._spec[0] != "~="),
325
+ )
326
+ return self._spec[0], canonical_version
327
+
328
+ def __hash__(self) -> int:
329
+ return hash(self._canonical_spec)
330
+
331
+ def __eq__(self, other: object) -> bool:
332
+ """Whether or not the two Specifier-like objects are equal.
333
+
334
+ :param other: The other object to check against.
335
+
336
+ The value of :attr:`prereleases` is ignored.
337
+
338
+ >>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
339
+ True
340
+ >>> (Specifier("==1.2.3", prereleases=False) ==
341
+ ... Specifier("==1.2.3", prereleases=True))
342
+ True
343
+ >>> Specifier("==1.2.3") == "==1.2.3"
344
+ True
345
+ >>> Specifier("==1.2.3") == Specifier("==1.2.4")
346
+ False
347
+ >>> Specifier("==1.2.3") == Specifier("~=1.2.3")
348
+ False
349
+ """
350
+ if isinstance(other, str):
351
+ try:
352
+ other = self.__class__(str(other))
353
+ except InvalidSpecifier:
354
+ return NotImplemented
355
+ elif not isinstance(other, self.__class__):
356
+ return NotImplemented
357
+
358
+ return self._canonical_spec == other._canonical_spec
359
+
360
+ def _get_operator(self, op: str) -> CallableOperator:
361
+ operator_callable: CallableOperator = getattr(
362
+ self, f"_compare_{self._operators[op]}"
363
+ )
364
+ return operator_callable
365
+
366
+ def _compare_compatible(self, prospective: Version, spec: str) -> bool:
367
+
368
+ # Compatible releases have an equivalent combination of >= and ==. That
369
+ # is that ~=2.2 is equivalent to >=2.2,==2.*. This allows us to
370
+ # implement this in terms of the other specifiers instead of
371
+ # implementing it ourselves. The only thing we need to do is construct
372
+ # the other specifiers.
373
+
374
+ # We want everything but the last item in the version, but we want to
375
+ # ignore suffix segments.
376
+ prefix = _version_join(
377
+ list(itertools.takewhile(_is_not_suffix, _version_split(spec)))[:-1]
378
+ )
379
+
380
+ # Add the prefix notation to the end of our string
381
+ prefix += ".*"
382
+
383
+ return self._get_operator(">=")(prospective, spec) and self._get_operator("==")(
384
+ prospective, prefix
385
+ )
386
+
387
+ def _compare_equal(self, prospective: Version, spec: str) -> bool:
388
+
389
+ # We need special logic to handle prefix matching
390
+ if spec.endswith(".*"):
391
+ # In the case of prefix matching we want to ignore local segment.
392
+ normalized_prospective = canonicalize_version(
393
+ prospective.public, strip_trailing_zero=False
394
+ )
395
+ # Get the normalized version string ignoring the trailing .*
396
+ normalized_spec = canonicalize_version(spec[:-2], strip_trailing_zero=False)
397
+ # Split the spec out by bangs and dots, and pretend that there is
398
+ # an implicit dot in between a release segment and a pre-release segment.
399
+ split_spec = _version_split(normalized_spec)
400
+
401
+ # Split the prospective version out by bangs and dots, and pretend
402
+ # that there is an implicit dot in between a release segment and
403
+ # a pre-release segment.
404
+ split_prospective = _version_split(normalized_prospective)
405
+
406
+ # 0-pad the prospective version before shortening it to get the correct
407
+ # shortened version.
408
+ padded_prospective, _ = _pad_version(split_prospective, split_spec)
409
+
410
+ # Shorten the prospective version to be the same length as the spec
411
+ # so that we can determine if the specifier is a prefix of the
412
+ # prospective version or not.
413
+ shortened_prospective = padded_prospective[: len(split_spec)]
414
+
415
+ return shortened_prospective == split_spec
416
+ else:
417
+ # Convert our spec string into a Version
418
+ spec_version = Version(spec)
419
+
420
+ # If the specifier does not have a local segment, then we want to
421
+ # act as if the prospective version also does not have a local
422
+ # segment.
423
+ if not spec_version.local:
424
+ prospective = Version(prospective.public)
425
+
426
+ return prospective == spec_version
427
+
428
+ def _compare_not_equal(self, prospective: Version, spec: str) -> bool:
429
+ return not self._compare_equal(prospective, spec)
430
+
431
+ def _compare_less_than_equal(self, prospective: Version, spec: str) -> bool:
432
+
433
+ # NB: Local version identifiers are NOT permitted in the version
434
+ # specifier, so local version labels can be universally removed from
435
+ # the prospective version.
436
+ return Version(prospective.public) <= Version(spec)
437
+
438
+ def _compare_greater_than_equal(self, prospective: Version, spec: str) -> bool:
439
+
440
+ # NB: Local version identifiers are NOT permitted in the version
441
+ # specifier, so local version labels can be universally removed from
442
+ # the prospective version.
443
+ return Version(prospective.public) >= Version(spec)
444
+
445
+ def _compare_less_than(self, prospective: Version, spec_str: str) -> bool:
446
+
447
+ # Convert our spec to a Version instance, since we'll want to work with
448
+ # it as a version.
449
+ spec = Version(spec_str)
450
+
451
+ # Check to see if the prospective version is less than the spec
452
+ # version. If it's not we can short circuit and just return False now
453
+ # instead of doing extra unneeded work.
454
+ if not prospective < spec:
455
+ return False
456
+
457
+ # This special case is here so that, unless the specifier itself
458
+ # includes is a pre-release version, that we do not accept pre-release
459
+ # versions for the version mentioned in the specifier (e.g. <3.1 should
460
+ # not match 3.1.dev0, but should match 3.0.dev0).
461
+ if not spec.is_prerelease and prospective.is_prerelease:
462
+ if Version(prospective.base_version) == Version(spec.base_version):
463
+ return False
464
+
465
+ # If we've gotten to here, it means that prospective version is both
466
+ # less than the spec version *and* it's not a pre-release of the same
467
+ # version in the spec.
468
+ return True
469
+
470
+ def _compare_greater_than(self, prospective: Version, spec_str: str) -> bool:
471
+
472
+ # Convert our spec to a Version instance, since we'll want to work with
473
+ # it as a version.
474
+ spec = Version(spec_str)
475
+
476
+ # Check to see if the prospective version is greater than the spec
477
+ # version. If it's not we can short circuit and just return False now
478
+ # instead of doing extra unneeded work.
479
+ if not prospective > spec:
480
+ return False
481
+
482
+ # This special case is here so that, unless the specifier itself
483
+ # includes is a post-release version, that we do not accept
484
+ # post-release versions for the version mentioned in the specifier
485
+ # (e.g. >3.1 should not match 3.0.post0, but should match 3.2.post0).
486
+ if not spec.is_postrelease and prospective.is_postrelease:
487
+ if Version(prospective.base_version) == Version(spec.base_version):
488
+ return False
489
+
490
+ # Ensure that we do not allow a local version of the version mentioned
491
+ # in the specifier, which is technically greater than, to match.
492
+ if prospective.local is not None:
493
+ if Version(prospective.base_version) == Version(spec.base_version):
494
+ return False
495
+
496
+ # If we've gotten to here, it means that prospective version is both
497
+ # greater than the spec version *and* it's not a pre-release of the
498
+ # same version in the spec.
499
+ return True
500
+
501
+ def _compare_arbitrary(self, prospective: Version, spec: str) -> bool:
502
+ return str(prospective).lower() == str(spec).lower()
503
+
504
+ def __contains__(self, item: Union[str, Version]) -> bool:
505
+ """Return whether or not the item is contained in this specifier.
506
+
507
+ :param item: The item to check for.
508
+
509
+ This is used for the ``in`` operator and behaves the same as
510
+ :meth:`contains` with no ``prereleases`` argument passed.
511
+
512
+ >>> "1.2.3" in Specifier(">=1.2.3")
513
+ True
514
+ >>> Version("1.2.3") in Specifier(">=1.2.3")
515
+ True
516
+ >>> "1.0.0" in Specifier(">=1.2.3")
517
+ False
518
+ >>> "1.3.0a1" in Specifier(">=1.2.3")
519
+ False
520
+ >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
521
+ True
522
+ """
523
+ return self.contains(item)
524
+
525
+ def contains(
526
+ self, item: UnparsedVersion, prereleases: Optional[bool] = None
527
+ ) -> bool:
528
+ """Return whether or not the item is contained in this specifier.
529
+
530
+ :param item:
531
+ The item to check for, which can be a version string or a
532
+ :class:`Version` instance.
533
+ :param prereleases:
534
+ Whether or not to match prereleases with this Specifier. If set to
535
+ ``None`` (the default), it uses :attr:`prereleases` to determine
536
+ whether or not prereleases are allowed.
537
+
538
+ >>> Specifier(">=1.2.3").contains("1.2.3")
539
+ True
540
+ >>> Specifier(">=1.2.3").contains(Version("1.2.3"))
541
+ True
542
+ >>> Specifier(">=1.2.3").contains("1.0.0")
543
+ False
544
+ >>> Specifier(">=1.2.3").contains("1.3.0a1")
545
+ False
546
+ >>> Specifier(">=1.2.3", prereleases=True).contains("1.3.0a1")
547
+ True
548
+ >>> Specifier(">=1.2.3").contains("1.3.0a1", prereleases=True)
549
+ True
550
+ """
551
+
552
+ # Determine if prereleases are to be allowed or not.
553
+ if prereleases is None:
554
+ prereleases = self.prereleases
555
+
556
+ # Normalize item to a Version, this allows us to have a shortcut for
557
+ # "2.0" in Specifier(">=2")
558
+ normalized_item = _coerce_version(item)
559
+
560
+ # Determine if we should be supporting prereleases in this specifier
561
+ # or not, if we do not support prereleases than we can short circuit
562
+ # logic if this version is a prereleases.
563
+ if normalized_item.is_prerelease and not prereleases:
564
+ return False
565
+
566
+ # Actually do the comparison to determine if this item is contained
567
+ # within this Specifier or not.
568
+ operator_callable: CallableOperator = self._get_operator(self.operator)
569
+ return operator_callable(normalized_item, self.version)
570
+
571
+ def filter(
572
+ self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
573
+ ) -> Iterator[UnparsedVersionVar]:
574
+ """Filter items in the given iterable, that match the specifier.
575
+
576
+ :param iterable:
577
+ An iterable that can contain version strings and :class:`Version` instances.
578
+ The items in the iterable will be filtered according to the specifier.
579
+ :param prereleases:
580
+ Whether or not to allow prereleases in the returned iterator. If set to
581
+ ``None`` (the default), it will be intelligently decide whether to allow
582
+ prereleases or not (based on the :attr:`prereleases` attribute, and
583
+ whether the only versions matching are prereleases).
584
+
585
+ This method is smarter than just ``filter(Specifier().contains, [...])``
586
+ because it implements the rule from :pep:`440` that a prerelease item
587
+ SHOULD be accepted if no other versions match the given specifier.
588
+
589
+ >>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
590
+ ['1.3']
591
+ >>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
592
+ ['1.2.3', '1.3', <Version('1.4')>]
593
+ >>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
594
+ ['1.5a1']
595
+ >>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
596
+ ['1.3', '1.5a1']
597
+ >>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
598
+ ['1.3', '1.5a1']
599
+ """
600
+
601
+ yielded = False
602
+ found_prereleases = []
603
+
604
+ kw = {"prereleases": prereleases if prereleases is not None else True}
605
+
606
+ # Attempt to iterate over all the values in the iterable and if any of
607
+ # them match, yield them.
608
+ for version in iterable:
609
+ parsed_version = _coerce_version(version)
610
+
611
+ if self.contains(parsed_version, **kw):
612
+ # If our version is a prerelease, and we were not set to allow
613
+ # prereleases, then we'll store it for later in case nothing
614
+ # else matches this specifier.
615
+ if parsed_version.is_prerelease and not (
616
+ prereleases or self.prereleases
617
+ ):
618
+ found_prereleases.append(version)
619
+ # Either this is not a prerelease, or we should have been
620
+ # accepting prereleases from the beginning.
621
+ else:
622
+ yielded = True
623
+ yield version
624
+
625
+ # Now that we've iterated over everything, determine if we've yielded
626
+ # any values, and if we have not and we have any prereleases stored up
627
+ # then we will go ahead and yield the prereleases.
628
+ if not yielded and found_prereleases:
629
+ for version in found_prereleases:
630
+ yield version
631
+
632
+
633
+ _prefix_regex = re.compile(r"^([0-9]+)((?:a|b|c|rc)[0-9]+)$")
634
+
635
+
636
+ def _version_split(version: str) -> List[str]:
637
+ """Split version into components.
638
+
639
+ The split components are intended for version comparison. The logic does
640
+ not attempt to retain the original version string, so joining the
641
+ components back with :func:`_version_join` may not produce the original
642
+ version string.
643
+ """
644
+ result: List[str] = []
645
+
646
+ epoch, _, rest = version.rpartition("!")
647
+ result.append(epoch or "0")
648
+
649
+ for item in rest.split("."):
650
+ match = _prefix_regex.search(item)
651
+ if match:
652
+ result.extend(match.groups())
653
+ else:
654
+ result.append(item)
655
+ return result
656
+
657
+
658
+ def _version_join(components: List[str]) -> str:
659
+ """Join split version components into a version string.
660
+
661
+ This function assumes the input came from :func:`_version_split`, where the
662
+ first component must be the epoch (either empty or numeric), and all other
663
+ components numeric.
664
+ """
665
+ epoch, *rest = components
666
+ return f"{epoch}!{'.'.join(rest)}"
667
+
668
+
669
+ def _is_not_suffix(segment: str) -> bool:
670
+ return not any(
671
+ segment.startswith(prefix) for prefix in ("dev", "a", "b", "rc", "post")
672
+ )
673
+
674
+
675
+ def _pad_version(left: List[str], right: List[str]) -> Tuple[List[str], List[str]]:
676
+ left_split, right_split = [], []
677
+
678
+ # Get the release segment of our versions
679
+ left_split.append(list(itertools.takewhile(lambda x: x.isdigit(), left)))
680
+ right_split.append(list(itertools.takewhile(lambda x: x.isdigit(), right)))
681
+
682
+ # Get the rest of our versions
683
+ left_split.append(left[len(left_split[0]) :])
684
+ right_split.append(right[len(right_split[0]) :])
685
+
686
+ # Insert our padding
687
+ left_split.insert(1, ["0"] * max(0, len(right_split[0]) - len(left_split[0])))
688
+ right_split.insert(1, ["0"] * max(0, len(left_split[0]) - len(right_split[0])))
689
+
690
+ return (
691
+ list(itertools.chain.from_iterable(left_split)),
692
+ list(itertools.chain.from_iterable(right_split)),
693
+ )
694
+
695
+
696
+ class SpecifierSet(BaseSpecifier):
697
+ """This class abstracts handling of a set of version specifiers.
698
+
699
+ It can be passed a single specifier (``>=3.0``), a comma-separated list of
700
+ specifiers (``>=3.0,!=3.1``), or no specifier at all.
701
+ """
702
+
703
+ def __init__(
704
+ self, specifiers: str = "", prereleases: Optional[bool] = None
705
+ ) -> None:
706
+ """Initialize a SpecifierSet instance.
707
+
708
+ :param specifiers:
709
+ The string representation of a specifier or a comma-separated list of
710
+ specifiers which will be parsed and normalized before use.
711
+ :param prereleases:
712
+ This tells the SpecifierSet if it should accept prerelease versions if
713
+ applicable or not. The default of ``None`` will autodetect it from the
714
+ given specifiers.
715
+
716
+ :raises InvalidSpecifier:
717
+ If the given ``specifiers`` are not parseable than this exception will be
718
+ raised.
719
+ """
720
+
721
+ # Split on `,` to break each individual specifier into it's own item, and
722
+ # strip each item to remove leading/trailing whitespace.
723
+ split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()]
724
+
725
+ # Make each individual specifier a Specifier and save in a frozen set for later.
726
+ self._specs = frozenset(map(Specifier, split_specifiers))
727
+
728
+ # Store our prereleases value so we can use it later to determine if
729
+ # we accept prereleases or not.
730
+ self._prereleases = prereleases
731
+
732
+ @property
733
+ def prereleases(self) -> Optional[bool]:
734
+ # If we have been given an explicit prerelease modifier, then we'll
735
+ # pass that through here.
736
+ if self._prereleases is not None:
737
+ return self._prereleases
738
+
739
+ # If we don't have any specifiers, and we don't have a forced value,
740
+ # then we'll just return None since we don't know if this should have
741
+ # pre-releases or not.
742
+ if not self._specs:
743
+ return None
744
+
745
+ # Otherwise we'll see if any of the given specifiers accept
746
+ # prereleases, if any of them do we'll return True, otherwise False.
747
+ return any(s.prereleases for s in self._specs)
748
+
749
+ @prereleases.setter
750
+ def prereleases(self, value: bool) -> None:
751
+ self._prereleases = value
752
+
753
+ def __repr__(self) -> str:
754
+ """A representation of the specifier set that shows all internal state.
755
+
756
+ Note that the ordering of the individual specifiers within the set may not
757
+ match the input string.
758
+
759
+ >>> SpecifierSet('>=1.0.0,!=2.0.0')
760
+ <SpecifierSet('!=2.0.0,>=1.0.0')>
761
+ >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=False)
762
+ <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=False)>
763
+ >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=True)
764
+ <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=True)>
765
+ """
766
+ pre = (
767
+ f", prereleases={self.prereleases!r}"
768
+ if self._prereleases is not None
769
+ else ""
770
+ )
771
+
772
+ return f"<SpecifierSet({str(self)!r}{pre})>"
773
+
774
+ def __str__(self) -> str:
775
+ """A string representation of the specifier set that can be round-tripped.
776
+
777
+ Note that the ordering of the individual specifiers within the set may not
778
+ match the input string.
779
+
780
+ >>> str(SpecifierSet(">=1.0.0,!=1.0.1"))
781
+ '!=1.0.1,>=1.0.0'
782
+ >>> str(SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False))
783
+ '!=1.0.1,>=1.0.0'
784
+ """
785
+ return ",".join(sorted(str(s) for s in self._specs))
786
+
787
+ def __hash__(self) -> int:
788
+ return hash(self._specs)
789
+
790
+ def __and__(self, other: Union["SpecifierSet", str]) -> "SpecifierSet":
791
+ """Return a SpecifierSet which is a combination of the two sets.
792
+
793
+ :param other: The other object to combine with.
794
+
795
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") & '<=2.0.0,!=2.0.1'
796
+ <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
797
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") & SpecifierSet('<=2.0.0,!=2.0.1')
798
+ <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
799
+ """
800
+ if isinstance(other, str):
801
+ other = SpecifierSet(other)
802
+ elif not isinstance(other, SpecifierSet):
803
+ return NotImplemented
804
+
805
+ specifier = SpecifierSet()
806
+ specifier._specs = frozenset(self._specs | other._specs)
807
+
808
+ if self._prereleases is None and other._prereleases is not None:
809
+ specifier._prereleases = other._prereleases
810
+ elif self._prereleases is not None and other._prereleases is None:
811
+ specifier._prereleases = self._prereleases
812
+ elif self._prereleases == other._prereleases:
813
+ specifier._prereleases = self._prereleases
814
+ else:
815
+ raise ValueError(
816
+ "Cannot combine SpecifierSets with True and False prerelease "
817
+ "overrides."
818
+ )
819
+
820
+ return specifier
821
+
822
+ def __eq__(self, other: object) -> bool:
823
+ """Whether or not the two SpecifierSet-like objects are equal.
824
+
825
+ :param other: The other object to check against.
826
+
827
+ The value of :attr:`prereleases` is ignored.
828
+
829
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.1")
830
+ True
831
+ >>> (SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False) ==
832
+ ... SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True))
833
+ True
834
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") == ">=1.0.0,!=1.0.1"
835
+ True
836
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0")
837
+ False
838
+ >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.2")
839
+ False
840
+ """
841
+ if isinstance(other, (str, Specifier)):
842
+ other = SpecifierSet(str(other))
843
+ elif not isinstance(other, SpecifierSet):
844
+ return NotImplemented
845
+
846
+ return self._specs == other._specs
847
+
848
+ def __len__(self) -> int:
849
+ """Returns the number of specifiers in this specifier set."""
850
+ return len(self._specs)
851
+
852
+ def __iter__(self) -> Iterator[Specifier]:
853
+ """
854
+ Returns an iterator over all the underlying :class:`Specifier` instances
855
+ in this specifier set.
856
+
857
+ >>> sorted(SpecifierSet(">=1.0.0,!=1.0.1"), key=str)
858
+ [<Specifier('!=1.0.1')>, <Specifier('>=1.0.0')>]
859
+ """
860
+ return iter(self._specs)
861
+
862
+ def __contains__(self, item: UnparsedVersion) -> bool:
863
+ """Return whether or not the item is contained in this specifier.
864
+
865
+ :param item: The item to check for.
866
+
867
+ This is used for the ``in`` operator and behaves the same as
868
+ :meth:`contains` with no ``prereleases`` argument passed.
869
+
870
+ >>> "1.2.3" in SpecifierSet(">=1.0.0,!=1.0.1")
871
+ True
872
+ >>> Version("1.2.3") in SpecifierSet(">=1.0.0,!=1.0.1")
873
+ True
874
+ >>> "1.0.1" in SpecifierSet(">=1.0.0,!=1.0.1")
875
+ False
876
+ >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1")
877
+ False
878
+ >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True)
879
+ True
880
+ """
881
+ return self.contains(item)
882
+
883
+ def contains(
884
+ self,
885
+ item: UnparsedVersion,
886
+ prereleases: Optional[bool] = None,
887
+ installed: Optional[bool] = None,
888
+ ) -> bool:
889
+ """Return whether or not the item is contained in this SpecifierSet.
890
+
891
+ :param item:
892
+ The item to check for, which can be a version string or a
893
+ :class:`Version` instance.
894
+ :param prereleases:
895
+ Whether or not to match prereleases with this SpecifierSet. If set to
896
+ ``None`` (the default), it uses :attr:`prereleases` to determine
897
+ whether or not prereleases are allowed.
898
+
899
+ >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.2.3")
900
+ True
901
+ >>> SpecifierSet(">=1.0.0,!=1.0.1").contains(Version("1.2.3"))
902
+ True
903
+ >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.0.1")
904
+ False
905
+ >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1")
906
+ False
907
+ >>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True).contains("1.3.0a1")
908
+ True
909
+ >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True)
910
+ True
911
+ """
912
+ # Ensure that our item is a Version instance.
913
+ if not isinstance(item, Version):
914
+ item = Version(item)
915
+
916
+ # Determine if we're forcing a prerelease or not, if we're not forcing
917
+ # one for this particular filter call, then we'll use whatever the
918
+ # SpecifierSet thinks for whether or not we should support prereleases.
919
+ if prereleases is None:
920
+ prereleases = self.prereleases
921
+
922
+ # We can determine if we're going to allow pre-releases by looking to
923
+ # see if any of the underlying items supports them. If none of them do
924
+ # and this item is a pre-release then we do not allow it and we can
925
+ # short circuit that here.
926
+ # Note: This means that 1.0.dev1 would not be contained in something
927
+ # like >=1.0.devabc however it would be in >=1.0.debabc,>0.0.dev0
928
+ if not prereleases and item.is_prerelease:
929
+ return False
930
+
931
+ if installed and item.is_prerelease:
932
+ item = Version(item.base_version)
933
+
934
+ # We simply dispatch to the underlying specs here to make sure that the
935
+ # given version is contained within all of them.
936
+ # Note: This use of all() here means that an empty set of specifiers
937
+ # will always return True, this is an explicit design decision.
938
+ return all(s.contains(item, prereleases=prereleases) for s in self._specs)
939
+
940
+ def filter(
941
+ self, iterable: Iterable[UnparsedVersionVar], prereleases: Optional[bool] = None
942
+ ) -> Iterator[UnparsedVersionVar]:
943
+ """Filter items in the given iterable, that match the specifiers in this set.
944
+
945
+ :param iterable:
946
+ An iterable that can contain version strings and :class:`Version` instances.
947
+ The items in the iterable will be filtered according to the specifier.
948
+ :param prereleases:
949
+ Whether or not to allow prereleases in the returned iterator. If set to
950
+ ``None`` (the default), it will be intelligently decide whether to allow
951
+ prereleases or not (based on the :attr:`prereleases` attribute, and
952
+ whether the only versions matching are prereleases).
953
+
954
+ This method is smarter than just ``filter(SpecifierSet(...).contains, [...])``
955
+ because it implements the rule from :pep:`440` that a prerelease item
956
+ SHOULD be accepted if no other versions match the given specifier.
957
+
958
+ >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
959
+ ['1.3']
960
+ >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", Version("1.4")]))
961
+ ['1.3', <Version('1.4')>]
962
+ >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.5a1"]))
963
+ []
964
+ >>> list(SpecifierSet(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
965
+ ['1.3', '1.5a1']
966
+ >>> list(SpecifierSet(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
967
+ ['1.3', '1.5a1']
968
+
969
+ An "empty" SpecifierSet will filter items based on the presence of prerelease
970
+ versions in the set.
971
+
972
+ >>> list(SpecifierSet("").filter(["1.3", "1.5a1"]))
973
+ ['1.3']
974
+ >>> list(SpecifierSet("").filter(["1.5a1"]))
975
+ ['1.5a1']
976
+ >>> list(SpecifierSet("", prereleases=True).filter(["1.3", "1.5a1"]))
977
+ ['1.3', '1.5a1']
978
+ >>> list(SpecifierSet("").filter(["1.3", "1.5a1"], prereleases=True))
979
+ ['1.3', '1.5a1']
980
+ """
981
+ # Determine if we're forcing a prerelease or not, if we're not forcing
982
+ # one for this particular filter call, then we'll use whatever the
983
+ # SpecifierSet thinks for whether or not we should support prereleases.
984
+ if prereleases is None:
985
+ prereleases = self.prereleases
986
+
987
+ # If we have any specifiers, then we want to wrap our iterable in the
988
+ # filter method for each one, this will act as a logical AND amongst
989
+ # each specifier.
990
+ if self._specs:
991
+ for spec in self._specs:
992
+ iterable = spec.filter(iterable, prereleases=bool(prereleases))
993
+ return iter(iterable)
994
+ # If we do not have any specifiers, then we need to have a rough filter
995
+ # which will filter out any pre-releases, unless there are no final
996
+ # releases.
997
+ else:
998
+ filtered: List[UnparsedVersionVar] = []
999
+ found_prereleases: List[UnparsedVersionVar] = []
1000
+
1001
+ for item in iterable:
1002
+ parsed_version = _coerce_version(item)
1003
+
1004
+ # Store any item which is a pre-release for later unless we've
1005
+ # already found a final version or we are accepting prereleases
1006
+ if parsed_version.is_prerelease and not prereleases:
1007
+ if not filtered:
1008
+ found_prereleases.append(item)
1009
+ else:
1010
+ filtered.append(item)
1011
+
1012
+ # If we've found no items except for pre-releases, then we'll go
1013
+ # ahead and use the pre-releases
1014
+ if not filtered and found_prereleases and prereleases is None:
1015
+ return iter(found_prereleases)
1016
+
1017
+ return iter(filtered)
env-llmeval/lib/python3.10/site-packages/packaging/tags.py ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ import logging
6
+ import platform
7
+ import re
8
+ import struct
9
+ import subprocess
10
+ import sys
11
+ import sysconfig
12
+ from importlib.machinery import EXTENSION_SUFFIXES
13
+ from typing import (
14
+ Dict,
15
+ FrozenSet,
16
+ Iterable,
17
+ Iterator,
18
+ List,
19
+ Optional,
20
+ Sequence,
21
+ Tuple,
22
+ Union,
23
+ cast,
24
+ )
25
+
26
+ from . import _manylinux, _musllinux
27
+
28
+ logger = logging.getLogger(__name__)
29
+
30
+ PythonVersion = Sequence[int]
31
+ MacVersion = Tuple[int, int]
32
+
33
+ INTERPRETER_SHORT_NAMES: Dict[str, str] = {
34
+ "python": "py", # Generic.
35
+ "cpython": "cp",
36
+ "pypy": "pp",
37
+ "ironpython": "ip",
38
+ "jython": "jy",
39
+ }
40
+
41
+
42
+ _32_BIT_INTERPRETER = struct.calcsize("P") == 4
43
+
44
+
45
+ class Tag:
46
+ """
47
+ A representation of the tag triple for a wheel.
48
+
49
+ Instances are considered immutable and thus are hashable. Equality checking
50
+ is also supported.
51
+ """
52
+
53
+ __slots__ = ["_interpreter", "_abi", "_platform", "_hash"]
54
+
55
+ def __init__(self, interpreter: str, abi: str, platform: str) -> None:
56
+ self._interpreter = interpreter.lower()
57
+ self._abi = abi.lower()
58
+ self._platform = platform.lower()
59
+ # The __hash__ of every single element in a Set[Tag] will be evaluated each time
60
+ # that a set calls its `.disjoint()` method, which may be called hundreds of
61
+ # times when scanning a page of links for packages with tags matching that
62
+ # Set[Tag]. Pre-computing the value here produces significant speedups for
63
+ # downstream consumers.
64
+ self._hash = hash((self._interpreter, self._abi, self._platform))
65
+
66
+ @property
67
+ def interpreter(self) -> str:
68
+ return self._interpreter
69
+
70
+ @property
71
+ def abi(self) -> str:
72
+ return self._abi
73
+
74
+ @property
75
+ def platform(self) -> str:
76
+ return self._platform
77
+
78
+ def __eq__(self, other: object) -> bool:
79
+ if not isinstance(other, Tag):
80
+ return NotImplemented
81
+
82
+ return (
83
+ (self._hash == other._hash) # Short-circuit ASAP for perf reasons.
84
+ and (self._platform == other._platform)
85
+ and (self._abi == other._abi)
86
+ and (self._interpreter == other._interpreter)
87
+ )
88
+
89
+ def __hash__(self) -> int:
90
+ return self._hash
91
+
92
+ def __str__(self) -> str:
93
+ return f"{self._interpreter}-{self._abi}-{self._platform}"
94
+
95
+ def __repr__(self) -> str:
96
+ return f"<{self} @ {id(self)}>"
97
+
98
+
99
+ def parse_tag(tag: str) -> FrozenSet[Tag]:
100
+ """
101
+ Parses the provided tag (e.g. `py3-none-any`) into a frozenset of Tag instances.
102
+
103
+ Returning a set is required due to the possibility that the tag is a
104
+ compressed tag set.
105
+ """
106
+ tags = set()
107
+ interpreters, abis, platforms = tag.split("-")
108
+ for interpreter in interpreters.split("."):
109
+ for abi in abis.split("."):
110
+ for platform_ in platforms.split("."):
111
+ tags.add(Tag(interpreter, abi, platform_))
112
+ return frozenset(tags)
113
+
114
+
115
+ def _get_config_var(name: str, warn: bool = False) -> Union[int, str, None]:
116
+ value: Union[int, str, None] = sysconfig.get_config_var(name)
117
+ if value is None and warn:
118
+ logger.debug(
119
+ "Config variable '%s' is unset, Python ABI tag may be incorrect", name
120
+ )
121
+ return value
122
+
123
+
124
+ def _normalize_string(string: str) -> str:
125
+ return string.replace(".", "_").replace("-", "_").replace(" ", "_")
126
+
127
+
128
+ def _is_threaded_cpython(abis: List[str]) -> bool:
129
+ """
130
+ Determine if the ABI corresponds to a threaded (`--disable-gil`) build.
131
+
132
+ The threaded builds are indicated by a "t" in the abiflags.
133
+ """
134
+ if len(abis) == 0:
135
+ return False
136
+ # expect e.g., cp313
137
+ m = re.match(r"cp\d+(.*)", abis[0])
138
+ if not m:
139
+ return False
140
+ abiflags = m.group(1)
141
+ return "t" in abiflags
142
+
143
+
144
+ def _abi3_applies(python_version: PythonVersion, threading: bool) -> bool:
145
+ """
146
+ Determine if the Python version supports abi3.
147
+
148
+ PEP 384 was first implemented in Python 3.2. The threaded (`--disable-gil`)
149
+ builds do not support abi3.
150
+ """
151
+ return len(python_version) > 1 and tuple(python_version) >= (3, 2) and not threading
152
+
153
+
154
+ def _cpython_abis(py_version: PythonVersion, warn: bool = False) -> List[str]:
155
+ py_version = tuple(py_version) # To allow for version comparison.
156
+ abis = []
157
+ version = _version_nodot(py_version[:2])
158
+ threading = debug = pymalloc = ucs4 = ""
159
+ with_debug = _get_config_var("Py_DEBUG", warn)
160
+ has_refcount = hasattr(sys, "gettotalrefcount")
161
+ # Windows doesn't set Py_DEBUG, so checking for support of debug-compiled
162
+ # extension modules is the best option.
163
+ # https://github.com/pypa/pip/issues/3383#issuecomment-173267692
164
+ has_ext = "_d.pyd" in EXTENSION_SUFFIXES
165
+ if with_debug or (with_debug is None and (has_refcount or has_ext)):
166
+ debug = "d"
167
+ if py_version >= (3, 13) and _get_config_var("Py_GIL_DISABLED", warn):
168
+ threading = "t"
169
+ if py_version < (3, 8):
170
+ with_pymalloc = _get_config_var("WITH_PYMALLOC", warn)
171
+ if with_pymalloc or with_pymalloc is None:
172
+ pymalloc = "m"
173
+ if py_version < (3, 3):
174
+ unicode_size = _get_config_var("Py_UNICODE_SIZE", warn)
175
+ if unicode_size == 4 or (
176
+ unicode_size is None and sys.maxunicode == 0x10FFFF
177
+ ):
178
+ ucs4 = "u"
179
+ elif debug:
180
+ # Debug builds can also load "normal" extension modules.
181
+ # We can also assume no UCS-4 or pymalloc requirement.
182
+ abis.append(f"cp{version}{threading}")
183
+ abis.insert(0, f"cp{version}{threading}{debug}{pymalloc}{ucs4}")
184
+ return abis
185
+
186
+
187
+ def cpython_tags(
188
+ python_version: Optional[PythonVersion] = None,
189
+ abis: Optional[Iterable[str]] = None,
190
+ platforms: Optional[Iterable[str]] = None,
191
+ *,
192
+ warn: bool = False,
193
+ ) -> Iterator[Tag]:
194
+ """
195
+ Yields the tags for a CPython interpreter.
196
+
197
+ The tags consist of:
198
+ - cp<python_version>-<abi>-<platform>
199
+ - cp<python_version>-abi3-<platform>
200
+ - cp<python_version>-none-<platform>
201
+ - cp<less than python_version>-abi3-<platform> # Older Python versions down to 3.2.
202
+
203
+ If python_version only specifies a major version then user-provided ABIs and
204
+ the 'none' ABItag will be used.
205
+
206
+ If 'abi3' or 'none' are specified in 'abis' then they will be yielded at
207
+ their normal position and not at the beginning.
208
+ """
209
+ if not python_version:
210
+ python_version = sys.version_info[:2]
211
+
212
+ interpreter = f"cp{_version_nodot(python_version[:2])}"
213
+
214
+ if abis is None:
215
+ if len(python_version) > 1:
216
+ abis = _cpython_abis(python_version, warn)
217
+ else:
218
+ abis = []
219
+ abis = list(abis)
220
+ # 'abi3' and 'none' are explicitly handled later.
221
+ for explicit_abi in ("abi3", "none"):
222
+ try:
223
+ abis.remove(explicit_abi)
224
+ except ValueError:
225
+ pass
226
+
227
+ platforms = list(platforms or platform_tags())
228
+ for abi in abis:
229
+ for platform_ in platforms:
230
+ yield Tag(interpreter, abi, platform_)
231
+
232
+ threading = _is_threaded_cpython(abis)
233
+ use_abi3 = _abi3_applies(python_version, threading)
234
+ if use_abi3:
235
+ yield from (Tag(interpreter, "abi3", platform_) for platform_ in platforms)
236
+ yield from (Tag(interpreter, "none", platform_) for platform_ in platforms)
237
+
238
+ if use_abi3:
239
+ for minor_version in range(python_version[1] - 1, 1, -1):
240
+ for platform_ in platforms:
241
+ interpreter = "cp{version}".format(
242
+ version=_version_nodot((python_version[0], minor_version))
243
+ )
244
+ yield Tag(interpreter, "abi3", platform_)
245
+
246
+
247
+ def _generic_abi() -> List[str]:
248
+ """
249
+ Return the ABI tag based on EXT_SUFFIX.
250
+ """
251
+ # The following are examples of `EXT_SUFFIX`.
252
+ # We want to keep the parts which are related to the ABI and remove the
253
+ # parts which are related to the platform:
254
+ # - linux: '.cpython-310-x86_64-linux-gnu.so' => cp310
255
+ # - mac: '.cpython-310-darwin.so' => cp310
256
+ # - win: '.cp310-win_amd64.pyd' => cp310
257
+ # - win: '.pyd' => cp37 (uses _cpython_abis())
258
+ # - pypy: '.pypy38-pp73-x86_64-linux-gnu.so' => pypy38_pp73
259
+ # - graalpy: '.graalpy-38-native-x86_64-darwin.dylib'
260
+ # => graalpy_38_native
261
+
262
+ ext_suffix = _get_config_var("EXT_SUFFIX", warn=True)
263
+ if not isinstance(ext_suffix, str) or ext_suffix[0] != ".":
264
+ raise SystemError("invalid sysconfig.get_config_var('EXT_SUFFIX')")
265
+ parts = ext_suffix.split(".")
266
+ if len(parts) < 3:
267
+ # CPython3.7 and earlier uses ".pyd" on Windows.
268
+ return _cpython_abis(sys.version_info[:2])
269
+ soabi = parts[1]
270
+ if soabi.startswith("cpython"):
271
+ # non-windows
272
+ abi = "cp" + soabi.split("-")[1]
273
+ elif soabi.startswith("cp"):
274
+ # windows
275
+ abi = soabi.split("-")[0]
276
+ elif soabi.startswith("pypy"):
277
+ abi = "-".join(soabi.split("-")[:2])
278
+ elif soabi.startswith("graalpy"):
279
+ abi = "-".join(soabi.split("-")[:3])
280
+ elif soabi:
281
+ # pyston, ironpython, others?
282
+ abi = soabi
283
+ else:
284
+ return []
285
+ return [_normalize_string(abi)]
286
+
287
+
288
+ def generic_tags(
289
+ interpreter: Optional[str] = None,
290
+ abis: Optional[Iterable[str]] = None,
291
+ platforms: Optional[Iterable[str]] = None,
292
+ *,
293
+ warn: bool = False,
294
+ ) -> Iterator[Tag]:
295
+ """
296
+ Yields the tags for a generic interpreter.
297
+
298
+ The tags consist of:
299
+ - <interpreter>-<abi>-<platform>
300
+
301
+ The "none" ABI will be added if it was not explicitly provided.
302
+ """
303
+ if not interpreter:
304
+ interp_name = interpreter_name()
305
+ interp_version = interpreter_version(warn=warn)
306
+ interpreter = "".join([interp_name, interp_version])
307
+ if abis is None:
308
+ abis = _generic_abi()
309
+ else:
310
+ abis = list(abis)
311
+ platforms = list(platforms or platform_tags())
312
+ if "none" not in abis:
313
+ abis.append("none")
314
+ for abi in abis:
315
+ for platform_ in platforms:
316
+ yield Tag(interpreter, abi, platform_)
317
+
318
+
319
+ def _py_interpreter_range(py_version: PythonVersion) -> Iterator[str]:
320
+ """
321
+ Yields Python versions in descending order.
322
+
323
+ After the latest version, the major-only version will be yielded, and then
324
+ all previous versions of that major version.
325
+ """
326
+ if len(py_version) > 1:
327
+ yield f"py{_version_nodot(py_version[:2])}"
328
+ yield f"py{py_version[0]}"
329
+ if len(py_version) > 1:
330
+ for minor in range(py_version[1] - 1, -1, -1):
331
+ yield f"py{_version_nodot((py_version[0], minor))}"
332
+
333
+
334
+ def compatible_tags(
335
+ python_version: Optional[PythonVersion] = None,
336
+ interpreter: Optional[str] = None,
337
+ platforms: Optional[Iterable[str]] = None,
338
+ ) -> Iterator[Tag]:
339
+ """
340
+ Yields the sequence of tags that are compatible with a specific version of Python.
341
+
342
+ The tags consist of:
343
+ - py*-none-<platform>
344
+ - <interpreter>-none-any # ... if `interpreter` is provided.
345
+ - py*-none-any
346
+ """
347
+ if not python_version:
348
+ python_version = sys.version_info[:2]
349
+ platforms = list(platforms or platform_tags())
350
+ for version in _py_interpreter_range(python_version):
351
+ for platform_ in platforms:
352
+ yield Tag(version, "none", platform_)
353
+ if interpreter:
354
+ yield Tag(interpreter, "none", "any")
355
+ for version in _py_interpreter_range(python_version):
356
+ yield Tag(version, "none", "any")
357
+
358
+
359
+ def _mac_arch(arch: str, is_32bit: bool = _32_BIT_INTERPRETER) -> str:
360
+ if not is_32bit:
361
+ return arch
362
+
363
+ if arch.startswith("ppc"):
364
+ return "ppc"
365
+
366
+ return "i386"
367
+
368
+
369
+ def _mac_binary_formats(version: MacVersion, cpu_arch: str) -> List[str]:
370
+ formats = [cpu_arch]
371
+ if cpu_arch == "x86_64":
372
+ if version < (10, 4):
373
+ return []
374
+ formats.extend(["intel", "fat64", "fat32"])
375
+
376
+ elif cpu_arch == "i386":
377
+ if version < (10, 4):
378
+ return []
379
+ formats.extend(["intel", "fat32", "fat"])
380
+
381
+ elif cpu_arch == "ppc64":
382
+ # TODO: Need to care about 32-bit PPC for ppc64 through 10.2?
383
+ if version > (10, 5) or version < (10, 4):
384
+ return []
385
+ formats.append("fat64")
386
+
387
+ elif cpu_arch == "ppc":
388
+ if version > (10, 6):
389
+ return []
390
+ formats.extend(["fat32", "fat"])
391
+
392
+ if cpu_arch in {"arm64", "x86_64"}:
393
+ formats.append("universal2")
394
+
395
+ if cpu_arch in {"x86_64", "i386", "ppc64", "ppc", "intel"}:
396
+ formats.append("universal")
397
+
398
+ return formats
399
+
400
+
401
+ def mac_platforms(
402
+ version: Optional[MacVersion] = None, arch: Optional[str] = None
403
+ ) -> Iterator[str]:
404
+ """
405
+ Yields the platform tags for a macOS system.
406
+
407
+ The `version` parameter is a two-item tuple specifying the macOS version to
408
+ generate platform tags for. The `arch` parameter is the CPU architecture to
409
+ generate platform tags for. Both parameters default to the appropriate value
410
+ for the current system.
411
+ """
412
+ version_str, _, cpu_arch = platform.mac_ver()
413
+ if version is None:
414
+ version = cast("MacVersion", tuple(map(int, version_str.split(".")[:2])))
415
+ if version == (10, 16):
416
+ # When built against an older macOS SDK, Python will report macOS 10.16
417
+ # instead of the real version.
418
+ version_str = subprocess.run(
419
+ [
420
+ sys.executable,
421
+ "-sS",
422
+ "-c",
423
+ "import platform; print(platform.mac_ver()[0])",
424
+ ],
425
+ check=True,
426
+ env={"SYSTEM_VERSION_COMPAT": "0"},
427
+ stdout=subprocess.PIPE,
428
+ text=True,
429
+ ).stdout
430
+ version = cast("MacVersion", tuple(map(int, version_str.split(".")[:2])))
431
+ else:
432
+ version = version
433
+ if arch is None:
434
+ arch = _mac_arch(cpu_arch)
435
+ else:
436
+ arch = arch
437
+
438
+ if (10, 0) <= version and version < (11, 0):
439
+ # Prior to Mac OS 11, each yearly release of Mac OS bumped the
440
+ # "minor" version number. The major version was always 10.
441
+ for minor_version in range(version[1], -1, -1):
442
+ compat_version = 10, minor_version
443
+ binary_formats = _mac_binary_formats(compat_version, arch)
444
+ for binary_format in binary_formats:
445
+ yield "macosx_{major}_{minor}_{binary_format}".format(
446
+ major=10, minor=minor_version, binary_format=binary_format
447
+ )
448
+
449
+ if version >= (11, 0):
450
+ # Starting with Mac OS 11, each yearly release bumps the major version
451
+ # number. The minor versions are now the midyear updates.
452
+ for major_version in range(version[0], 10, -1):
453
+ compat_version = major_version, 0
454
+ binary_formats = _mac_binary_formats(compat_version, arch)
455
+ for binary_format in binary_formats:
456
+ yield "macosx_{major}_{minor}_{binary_format}".format(
457
+ major=major_version, minor=0, binary_format=binary_format
458
+ )
459
+
460
+ if version >= (11, 0):
461
+ # Mac OS 11 on x86_64 is compatible with binaries from previous releases.
462
+ # Arm64 support was introduced in 11.0, so no Arm binaries from previous
463
+ # releases exist.
464
+ #
465
+ # However, the "universal2" binary format can have a
466
+ # macOS version earlier than 11.0 when the x86_64 part of the binary supports
467
+ # that version of macOS.
468
+ if arch == "x86_64":
469
+ for minor_version in range(16, 3, -1):
470
+ compat_version = 10, minor_version
471
+ binary_formats = _mac_binary_formats(compat_version, arch)
472
+ for binary_format in binary_formats:
473
+ yield "macosx_{major}_{minor}_{binary_format}".format(
474
+ major=compat_version[0],
475
+ minor=compat_version[1],
476
+ binary_format=binary_format,
477
+ )
478
+ else:
479
+ for minor_version in range(16, 3, -1):
480
+ compat_version = 10, minor_version
481
+ binary_format = "universal2"
482
+ yield "macosx_{major}_{minor}_{binary_format}".format(
483
+ major=compat_version[0],
484
+ minor=compat_version[1],
485
+ binary_format=binary_format,
486
+ )
487
+
488
+
489
+ def _linux_platforms(is_32bit: bool = _32_BIT_INTERPRETER) -> Iterator[str]:
490
+ linux = _normalize_string(sysconfig.get_platform())
491
+ if not linux.startswith("linux_"):
492
+ # we should never be here, just yield the sysconfig one and return
493
+ yield linux
494
+ return
495
+ if is_32bit:
496
+ if linux == "linux_x86_64":
497
+ linux = "linux_i686"
498
+ elif linux == "linux_aarch64":
499
+ linux = "linux_armv8l"
500
+ _, arch = linux.split("_", 1)
501
+ archs = {"armv8l": ["armv8l", "armv7l"]}.get(arch, [arch])
502
+ yield from _manylinux.platform_tags(archs)
503
+ yield from _musllinux.platform_tags(archs)
504
+ for arch in archs:
505
+ yield f"linux_{arch}"
506
+
507
+
508
+ def _generic_platforms() -> Iterator[str]:
509
+ yield _normalize_string(sysconfig.get_platform())
510
+
511
+
512
+ def platform_tags() -> Iterator[str]:
513
+ """
514
+ Provides the platform tags for this installation.
515
+ """
516
+ if platform.system() == "Darwin":
517
+ return mac_platforms()
518
+ elif platform.system() == "Linux":
519
+ return _linux_platforms()
520
+ else:
521
+ return _generic_platforms()
522
+
523
+
524
+ def interpreter_name() -> str:
525
+ """
526
+ Returns the name of the running interpreter.
527
+
528
+ Some implementations have a reserved, two-letter abbreviation which will
529
+ be returned when appropriate.
530
+ """
531
+ name = sys.implementation.name
532
+ return INTERPRETER_SHORT_NAMES.get(name) or name
533
+
534
+
535
+ def interpreter_version(*, warn: bool = False) -> str:
536
+ """
537
+ Returns the version of the running interpreter.
538
+ """
539
+ version = _get_config_var("py_version_nodot", warn=warn)
540
+ if version:
541
+ version = str(version)
542
+ else:
543
+ version = _version_nodot(sys.version_info[:2])
544
+ return version
545
+
546
+
547
+ def _version_nodot(version: PythonVersion) -> str:
548
+ return "".join(map(str, version))
549
+
550
+
551
+ def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
552
+ """
553
+ Returns the sequence of tag triples for the running interpreter.
554
+
555
+ The order of the sequence corresponds to priority order for the
556
+ interpreter, from most to least important.
557
+ """
558
+
559
+ interp_name = interpreter_name()
560
+ if interp_name == "cp":
561
+ yield from cpython_tags(warn=warn)
562
+ else:
563
+ yield from generic_tags()
564
+
565
+ if interp_name == "pp":
566
+ interp = "pp3"
567
+ elif interp_name == "cp":
568
+ interp = "cp" + interpreter_version(warn=warn)
569
+ else:
570
+ interp = None
571
+ yield from compatible_tags(interpreter=interp)
env-llmeval/lib/python3.10/site-packages/packaging/utils.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ import re
6
+ from typing import FrozenSet, NewType, Tuple, Union, cast
7
+
8
+ from .tags import Tag, parse_tag
9
+ from .version import InvalidVersion, Version
10
+
11
+ BuildTag = Union[Tuple[()], Tuple[int, str]]
12
+ NormalizedName = NewType("NormalizedName", str)
13
+
14
+
15
+ class InvalidName(ValueError):
16
+ """
17
+ An invalid distribution name; users should refer to the packaging user guide.
18
+ """
19
+
20
+
21
+ class InvalidWheelFilename(ValueError):
22
+ """
23
+ An invalid wheel filename was found, users should refer to PEP 427.
24
+ """
25
+
26
+
27
+ class InvalidSdistFilename(ValueError):
28
+ """
29
+ An invalid sdist filename was found, users should refer to the packaging user guide.
30
+ """
31
+
32
+
33
+ # Core metadata spec for `Name`
34
+ _validate_regex = re.compile(
35
+ r"^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", re.IGNORECASE
36
+ )
37
+ _canonicalize_regex = re.compile(r"[-_.]+")
38
+ _normalized_regex = re.compile(r"^([a-z0-9]|[a-z0-9]([a-z0-9-](?!--))*[a-z0-9])$")
39
+ # PEP 427: The build number must start with a digit.
40
+ _build_tag_regex = re.compile(r"(\d+)(.*)")
41
+
42
+
43
+ def canonicalize_name(name: str, *, validate: bool = False) -> NormalizedName:
44
+ if validate and not _validate_regex.match(name):
45
+ raise InvalidName(f"name is invalid: {name!r}")
46
+ # This is taken from PEP 503.
47
+ value = _canonicalize_regex.sub("-", name).lower()
48
+ return cast(NormalizedName, value)
49
+
50
+
51
+ def is_normalized_name(name: str) -> bool:
52
+ return _normalized_regex.match(name) is not None
53
+
54
+
55
+ def canonicalize_version(
56
+ version: Union[Version, str], *, strip_trailing_zero: bool = True
57
+ ) -> str:
58
+ """
59
+ This is very similar to Version.__str__, but has one subtle difference
60
+ with the way it handles the release segment.
61
+ """
62
+ if isinstance(version, str):
63
+ try:
64
+ parsed = Version(version)
65
+ except InvalidVersion:
66
+ # Legacy versions cannot be normalized
67
+ return version
68
+ else:
69
+ parsed = version
70
+
71
+ parts = []
72
+
73
+ # Epoch
74
+ if parsed.epoch != 0:
75
+ parts.append(f"{parsed.epoch}!")
76
+
77
+ # Release segment
78
+ release_segment = ".".join(str(x) for x in parsed.release)
79
+ if strip_trailing_zero:
80
+ # NB: This strips trailing '.0's to normalize
81
+ release_segment = re.sub(r"(\.0)+$", "", release_segment)
82
+ parts.append(release_segment)
83
+
84
+ # Pre-release
85
+ if parsed.pre is not None:
86
+ parts.append("".join(str(x) for x in parsed.pre))
87
+
88
+ # Post-release
89
+ if parsed.post is not None:
90
+ parts.append(f".post{parsed.post}")
91
+
92
+ # Development release
93
+ if parsed.dev is not None:
94
+ parts.append(f".dev{parsed.dev}")
95
+
96
+ # Local version segment
97
+ if parsed.local is not None:
98
+ parts.append(f"+{parsed.local}")
99
+
100
+ return "".join(parts)
101
+
102
+
103
+ def parse_wheel_filename(
104
+ filename: str,
105
+ ) -> Tuple[NormalizedName, Version, BuildTag, FrozenSet[Tag]]:
106
+ if not filename.endswith(".whl"):
107
+ raise InvalidWheelFilename(
108
+ f"Invalid wheel filename (extension must be '.whl'): {filename}"
109
+ )
110
+
111
+ filename = filename[:-4]
112
+ dashes = filename.count("-")
113
+ if dashes not in (4, 5):
114
+ raise InvalidWheelFilename(
115
+ f"Invalid wheel filename (wrong number of parts): {filename}"
116
+ )
117
+
118
+ parts = filename.split("-", dashes - 2)
119
+ name_part = parts[0]
120
+ # See PEP 427 for the rules on escaping the project name.
121
+ if "__" in name_part or re.match(r"^[\w\d._]*$", name_part, re.UNICODE) is None:
122
+ raise InvalidWheelFilename(f"Invalid project name: {filename}")
123
+ name = canonicalize_name(name_part)
124
+
125
+ try:
126
+ version = Version(parts[1])
127
+ except InvalidVersion as e:
128
+ raise InvalidWheelFilename(
129
+ f"Invalid wheel filename (invalid version): {filename}"
130
+ ) from e
131
+
132
+ if dashes == 5:
133
+ build_part = parts[2]
134
+ build_match = _build_tag_regex.match(build_part)
135
+ if build_match is None:
136
+ raise InvalidWheelFilename(
137
+ f"Invalid build number: {build_part} in '{filename}'"
138
+ )
139
+ build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
140
+ else:
141
+ build = ()
142
+ tags = parse_tag(parts[-1])
143
+ return (name, version, build, tags)
144
+
145
+
146
+ def parse_sdist_filename(filename: str) -> Tuple[NormalizedName, Version]:
147
+ if filename.endswith(".tar.gz"):
148
+ file_stem = filename[: -len(".tar.gz")]
149
+ elif filename.endswith(".zip"):
150
+ file_stem = filename[: -len(".zip")]
151
+ else:
152
+ raise InvalidSdistFilename(
153
+ f"Invalid sdist filename (extension must be '.tar.gz' or '.zip'):"
154
+ f" {filename}"
155
+ )
156
+
157
+ # We are requiring a PEP 440 version, which cannot contain dashes,
158
+ # so we split on the last dash.
159
+ name_part, sep, version_part = file_stem.rpartition("-")
160
+ if not sep:
161
+ raise InvalidSdistFilename(f"Invalid sdist filename: {filename}")
162
+
163
+ name = canonicalize_name(name_part)
164
+
165
+ try:
166
+ version = Version(version_part)
167
+ except InvalidVersion as e:
168
+ raise InvalidSdistFilename(
169
+ f"Invalid sdist filename (invalid version): {filename}"
170
+ ) from e
171
+
172
+ return (name, version)
env-llmeval/lib/python3.10/site-packages/packaging/version.py ADDED
@@ -0,0 +1,563 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+ """
5
+ .. testsetup::
6
+
7
+ from packaging.version import parse, Version
8
+ """
9
+
10
+ import itertools
11
+ import re
12
+ from typing import Any, Callable, NamedTuple, Optional, SupportsInt, Tuple, Union
13
+
14
+ from ._structures import Infinity, InfinityType, NegativeInfinity, NegativeInfinityType
15
+
16
+ __all__ = ["VERSION_PATTERN", "parse", "Version", "InvalidVersion"]
17
+
18
+ LocalType = Tuple[Union[int, str], ...]
19
+
20
+ CmpPrePostDevType = Union[InfinityType, NegativeInfinityType, Tuple[str, int]]
21
+ CmpLocalType = Union[
22
+ NegativeInfinityType,
23
+ Tuple[Union[Tuple[int, str], Tuple[NegativeInfinityType, Union[int, str]]], ...],
24
+ ]
25
+ CmpKey = Tuple[
26
+ int,
27
+ Tuple[int, ...],
28
+ CmpPrePostDevType,
29
+ CmpPrePostDevType,
30
+ CmpPrePostDevType,
31
+ CmpLocalType,
32
+ ]
33
+ VersionComparisonMethod = Callable[[CmpKey, CmpKey], bool]
34
+
35
+
36
+ class _Version(NamedTuple):
37
+ epoch: int
38
+ release: Tuple[int, ...]
39
+ dev: Optional[Tuple[str, int]]
40
+ pre: Optional[Tuple[str, int]]
41
+ post: Optional[Tuple[str, int]]
42
+ local: Optional[LocalType]
43
+
44
+
45
+ def parse(version: str) -> "Version":
46
+ """Parse the given version string.
47
+
48
+ >>> parse('1.0.dev1')
49
+ <Version('1.0.dev1')>
50
+
51
+ :param version: The version string to parse.
52
+ :raises InvalidVersion: When the version string is not a valid version.
53
+ """
54
+ return Version(version)
55
+
56
+
57
+ class InvalidVersion(ValueError):
58
+ """Raised when a version string is not a valid version.
59
+
60
+ >>> Version("invalid")
61
+ Traceback (most recent call last):
62
+ ...
63
+ packaging.version.InvalidVersion: Invalid version: 'invalid'
64
+ """
65
+
66
+
67
+ class _BaseVersion:
68
+ _key: Tuple[Any, ...]
69
+
70
+ def __hash__(self) -> int:
71
+ return hash(self._key)
72
+
73
+ # Please keep the duplicated `isinstance` check
74
+ # in the six comparisons hereunder
75
+ # unless you find a way to avoid adding overhead function calls.
76
+ def __lt__(self, other: "_BaseVersion") -> bool:
77
+ if not isinstance(other, _BaseVersion):
78
+ return NotImplemented
79
+
80
+ return self._key < other._key
81
+
82
+ def __le__(self, other: "_BaseVersion") -> bool:
83
+ if not isinstance(other, _BaseVersion):
84
+ return NotImplemented
85
+
86
+ return self._key <= other._key
87
+
88
+ def __eq__(self, other: object) -> bool:
89
+ if not isinstance(other, _BaseVersion):
90
+ return NotImplemented
91
+
92
+ return self._key == other._key
93
+
94
+ def __ge__(self, other: "_BaseVersion") -> bool:
95
+ if not isinstance(other, _BaseVersion):
96
+ return NotImplemented
97
+
98
+ return self._key >= other._key
99
+
100
+ def __gt__(self, other: "_BaseVersion") -> bool:
101
+ if not isinstance(other, _BaseVersion):
102
+ return NotImplemented
103
+
104
+ return self._key > other._key
105
+
106
+ def __ne__(self, other: object) -> bool:
107
+ if not isinstance(other, _BaseVersion):
108
+ return NotImplemented
109
+
110
+ return self._key != other._key
111
+
112
+
113
+ # Deliberately not anchored to the start and end of the string, to make it
114
+ # easier for 3rd party code to reuse
115
+ _VERSION_PATTERN = r"""
116
+ v?
117
+ (?:
118
+ (?:(?P<epoch>[0-9]+)!)? # epoch
119
+ (?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
120
+ (?P<pre> # pre-release
121
+ [-_\.]?
122
+ (?P<pre_l>alpha|a|beta|b|preview|pre|c|rc)
123
+ [-_\.]?
124
+ (?P<pre_n>[0-9]+)?
125
+ )?
126
+ (?P<post> # post release
127
+ (?:-(?P<post_n1>[0-9]+))
128
+ |
129
+ (?:
130
+ [-_\.]?
131
+ (?P<post_l>post|rev|r)
132
+ [-_\.]?
133
+ (?P<post_n2>[0-9]+)?
134
+ )
135
+ )?
136
+ (?P<dev> # dev release
137
+ [-_\.]?
138
+ (?P<dev_l>dev)
139
+ [-_\.]?
140
+ (?P<dev_n>[0-9]+)?
141
+ )?
142
+ )
143
+ (?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
144
+ """
145
+
146
+ VERSION_PATTERN = _VERSION_PATTERN
147
+ """
148
+ A string containing the regular expression used to match a valid version.
149
+
150
+ The pattern is not anchored at either end, and is intended for embedding in larger
151
+ expressions (for example, matching a version number as part of a file name). The
152
+ regular expression should be compiled with the ``re.VERBOSE`` and ``re.IGNORECASE``
153
+ flags set.
154
+
155
+ :meta hide-value:
156
+ """
157
+
158
+
159
+ class Version(_BaseVersion):
160
+ """This class abstracts handling of a project's versions.
161
+
162
+ A :class:`Version` instance is comparison aware and can be compared and
163
+ sorted using the standard Python interfaces.
164
+
165
+ >>> v1 = Version("1.0a5")
166
+ >>> v2 = Version("1.0")
167
+ >>> v1
168
+ <Version('1.0a5')>
169
+ >>> v2
170
+ <Version('1.0')>
171
+ >>> v1 < v2
172
+ True
173
+ >>> v1 == v2
174
+ False
175
+ >>> v1 > v2
176
+ False
177
+ >>> v1 >= v2
178
+ False
179
+ >>> v1 <= v2
180
+ True
181
+ """
182
+
183
+ _regex = re.compile(r"^\s*" + VERSION_PATTERN + r"\s*$", re.VERBOSE | re.IGNORECASE)
184
+ _key: CmpKey
185
+
186
+ def __init__(self, version: str) -> None:
187
+ """Initialize a Version object.
188
+
189
+ :param version:
190
+ The string representation of a version which will be parsed and normalized
191
+ before use.
192
+ :raises InvalidVersion:
193
+ If the ``version`` does not conform to PEP 440 in any way then this
194
+ exception will be raised.
195
+ """
196
+
197
+ # Validate the version and parse it into pieces
198
+ match = self._regex.search(version)
199
+ if not match:
200
+ raise InvalidVersion(f"Invalid version: '{version}'")
201
+
202
+ # Store the parsed out pieces of the version
203
+ self._version = _Version(
204
+ epoch=int(match.group("epoch")) if match.group("epoch") else 0,
205
+ release=tuple(int(i) for i in match.group("release").split(".")),
206
+ pre=_parse_letter_version(match.group("pre_l"), match.group("pre_n")),
207
+ post=_parse_letter_version(
208
+ match.group("post_l"), match.group("post_n1") or match.group("post_n2")
209
+ ),
210
+ dev=_parse_letter_version(match.group("dev_l"), match.group("dev_n")),
211
+ local=_parse_local_version(match.group("local")),
212
+ )
213
+
214
+ # Generate a key which will be used for sorting
215
+ self._key = _cmpkey(
216
+ self._version.epoch,
217
+ self._version.release,
218
+ self._version.pre,
219
+ self._version.post,
220
+ self._version.dev,
221
+ self._version.local,
222
+ )
223
+
224
+ def __repr__(self) -> str:
225
+ """A representation of the Version that shows all internal state.
226
+
227
+ >>> Version('1.0.0')
228
+ <Version('1.0.0')>
229
+ """
230
+ return f"<Version('{self}')>"
231
+
232
+ def __str__(self) -> str:
233
+ """A string representation of the version that can be rounded-tripped.
234
+
235
+ >>> str(Version("1.0a5"))
236
+ '1.0a5'
237
+ """
238
+ parts = []
239
+
240
+ # Epoch
241
+ if self.epoch != 0:
242
+ parts.append(f"{self.epoch}!")
243
+
244
+ # Release segment
245
+ parts.append(".".join(str(x) for x in self.release))
246
+
247
+ # Pre-release
248
+ if self.pre is not None:
249
+ parts.append("".join(str(x) for x in self.pre))
250
+
251
+ # Post-release
252
+ if self.post is not None:
253
+ parts.append(f".post{self.post}")
254
+
255
+ # Development release
256
+ if self.dev is not None:
257
+ parts.append(f".dev{self.dev}")
258
+
259
+ # Local version segment
260
+ if self.local is not None:
261
+ parts.append(f"+{self.local}")
262
+
263
+ return "".join(parts)
264
+
265
+ @property
266
+ def epoch(self) -> int:
267
+ """The epoch of the version.
268
+
269
+ >>> Version("2.0.0").epoch
270
+ 0
271
+ >>> Version("1!2.0.0").epoch
272
+ 1
273
+ """
274
+ return self._version.epoch
275
+
276
+ @property
277
+ def release(self) -> Tuple[int, ...]:
278
+ """The components of the "release" segment of the version.
279
+
280
+ >>> Version("1.2.3").release
281
+ (1, 2, 3)
282
+ >>> Version("2.0.0").release
283
+ (2, 0, 0)
284
+ >>> Version("1!2.0.0.post0").release
285
+ (2, 0, 0)
286
+
287
+ Includes trailing zeroes but not the epoch or any pre-release / development /
288
+ post-release suffixes.
289
+ """
290
+ return self._version.release
291
+
292
+ @property
293
+ def pre(self) -> Optional[Tuple[str, int]]:
294
+ """The pre-release segment of the version.
295
+
296
+ >>> print(Version("1.2.3").pre)
297
+ None
298
+ >>> Version("1.2.3a1").pre
299
+ ('a', 1)
300
+ >>> Version("1.2.3b1").pre
301
+ ('b', 1)
302
+ >>> Version("1.2.3rc1").pre
303
+ ('rc', 1)
304
+ """
305
+ return self._version.pre
306
+
307
+ @property
308
+ def post(self) -> Optional[int]:
309
+ """The post-release number of the version.
310
+
311
+ >>> print(Version("1.2.3").post)
312
+ None
313
+ >>> Version("1.2.3.post1").post
314
+ 1
315
+ """
316
+ return self._version.post[1] if self._version.post else None
317
+
318
+ @property
319
+ def dev(self) -> Optional[int]:
320
+ """The development number of the version.
321
+
322
+ >>> print(Version("1.2.3").dev)
323
+ None
324
+ >>> Version("1.2.3.dev1").dev
325
+ 1
326
+ """
327
+ return self._version.dev[1] if self._version.dev else None
328
+
329
+ @property
330
+ def local(self) -> Optional[str]:
331
+ """The local version segment of the version.
332
+
333
+ >>> print(Version("1.2.3").local)
334
+ None
335
+ >>> Version("1.2.3+abc").local
336
+ 'abc'
337
+ """
338
+ if self._version.local:
339
+ return ".".join(str(x) for x in self._version.local)
340
+ else:
341
+ return None
342
+
343
+ @property
344
+ def public(self) -> str:
345
+ """The public portion of the version.
346
+
347
+ >>> Version("1.2.3").public
348
+ '1.2.3'
349
+ >>> Version("1.2.3+abc").public
350
+ '1.2.3'
351
+ >>> Version("1.2.3+abc.dev1").public
352
+ '1.2.3'
353
+ """
354
+ return str(self).split("+", 1)[0]
355
+
356
+ @property
357
+ def base_version(self) -> str:
358
+ """The "base version" of the version.
359
+
360
+ >>> Version("1.2.3").base_version
361
+ '1.2.3'
362
+ >>> Version("1.2.3+abc").base_version
363
+ '1.2.3'
364
+ >>> Version("1!1.2.3+abc.dev1").base_version
365
+ '1!1.2.3'
366
+
367
+ The "base version" is the public version of the project without any pre or post
368
+ release markers.
369
+ """
370
+ parts = []
371
+
372
+ # Epoch
373
+ if self.epoch != 0:
374
+ parts.append(f"{self.epoch}!")
375
+
376
+ # Release segment
377
+ parts.append(".".join(str(x) for x in self.release))
378
+
379
+ return "".join(parts)
380
+
381
+ @property
382
+ def is_prerelease(self) -> bool:
383
+ """Whether this version is a pre-release.
384
+
385
+ >>> Version("1.2.3").is_prerelease
386
+ False
387
+ >>> Version("1.2.3a1").is_prerelease
388
+ True
389
+ >>> Version("1.2.3b1").is_prerelease
390
+ True
391
+ >>> Version("1.2.3rc1").is_prerelease
392
+ True
393
+ >>> Version("1.2.3dev1").is_prerelease
394
+ True
395
+ """
396
+ return self.dev is not None or self.pre is not None
397
+
398
+ @property
399
+ def is_postrelease(self) -> bool:
400
+ """Whether this version is a post-release.
401
+
402
+ >>> Version("1.2.3").is_postrelease
403
+ False
404
+ >>> Version("1.2.3.post1").is_postrelease
405
+ True
406
+ """
407
+ return self.post is not None
408
+
409
+ @property
410
+ def is_devrelease(self) -> bool:
411
+ """Whether this version is a development release.
412
+
413
+ >>> Version("1.2.3").is_devrelease
414
+ False
415
+ >>> Version("1.2.3.dev1").is_devrelease
416
+ True
417
+ """
418
+ return self.dev is not None
419
+
420
+ @property
421
+ def major(self) -> int:
422
+ """The first item of :attr:`release` or ``0`` if unavailable.
423
+
424
+ >>> Version("1.2.3").major
425
+ 1
426
+ """
427
+ return self.release[0] if len(self.release) >= 1 else 0
428
+
429
+ @property
430
+ def minor(self) -> int:
431
+ """The second item of :attr:`release` or ``0`` if unavailable.
432
+
433
+ >>> Version("1.2.3").minor
434
+ 2
435
+ >>> Version("1").minor
436
+ 0
437
+ """
438
+ return self.release[1] if len(self.release) >= 2 else 0
439
+
440
+ @property
441
+ def micro(self) -> int:
442
+ """The third item of :attr:`release` or ``0`` if unavailable.
443
+
444
+ >>> Version("1.2.3").micro
445
+ 3
446
+ >>> Version("1").micro
447
+ 0
448
+ """
449
+ return self.release[2] if len(self.release) >= 3 else 0
450
+
451
+
452
+ def _parse_letter_version(
453
+ letter: Optional[str], number: Union[str, bytes, SupportsInt, None]
454
+ ) -> Optional[Tuple[str, int]]:
455
+
456
+ if letter:
457
+ # We consider there to be an implicit 0 in a pre-release if there is
458
+ # not a numeral associated with it.
459
+ if number is None:
460
+ number = 0
461
+
462
+ # We normalize any letters to their lower case form
463
+ letter = letter.lower()
464
+
465
+ # We consider some words to be alternate spellings of other words and
466
+ # in those cases we want to normalize the spellings to our preferred
467
+ # spelling.
468
+ if letter == "alpha":
469
+ letter = "a"
470
+ elif letter == "beta":
471
+ letter = "b"
472
+ elif letter in ["c", "pre", "preview"]:
473
+ letter = "rc"
474
+ elif letter in ["rev", "r"]:
475
+ letter = "post"
476
+
477
+ return letter, int(number)
478
+ if not letter and number:
479
+ # We assume if we are given a number, but we are not given a letter
480
+ # then this is using the implicit post release syntax (e.g. 1.0-1)
481
+ letter = "post"
482
+
483
+ return letter, int(number)
484
+
485
+ return None
486
+
487
+
488
+ _local_version_separators = re.compile(r"[\._-]")
489
+
490
+
491
+ def _parse_local_version(local: Optional[str]) -> Optional[LocalType]:
492
+ """
493
+ Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
494
+ """
495
+ if local is not None:
496
+ return tuple(
497
+ part.lower() if not part.isdigit() else int(part)
498
+ for part in _local_version_separators.split(local)
499
+ )
500
+ return None
501
+
502
+
503
+ def _cmpkey(
504
+ epoch: int,
505
+ release: Tuple[int, ...],
506
+ pre: Optional[Tuple[str, int]],
507
+ post: Optional[Tuple[str, int]],
508
+ dev: Optional[Tuple[str, int]],
509
+ local: Optional[LocalType],
510
+ ) -> CmpKey:
511
+
512
+ # When we compare a release version, we want to compare it with all of the
513
+ # trailing zeros removed. So we'll use a reverse the list, drop all the now
514
+ # leading zeros until we come to something non zero, then take the rest
515
+ # re-reverse it back into the correct order and make it a tuple and use
516
+ # that for our sorting key.
517
+ _release = tuple(
518
+ reversed(list(itertools.dropwhile(lambda x: x == 0, reversed(release))))
519
+ )
520
+
521
+ # We need to "trick" the sorting algorithm to put 1.0.dev0 before 1.0a0.
522
+ # We'll do this by abusing the pre segment, but we _only_ want to do this
523
+ # if there is not a pre or a post segment. If we have one of those then
524
+ # the normal sorting rules will handle this case correctly.
525
+ if pre is None and post is None and dev is not None:
526
+ _pre: CmpPrePostDevType = NegativeInfinity
527
+ # Versions without a pre-release (except as noted above) should sort after
528
+ # those with one.
529
+ elif pre is None:
530
+ _pre = Infinity
531
+ else:
532
+ _pre = pre
533
+
534
+ # Versions without a post segment should sort before those with one.
535
+ if post is None:
536
+ _post: CmpPrePostDevType = NegativeInfinity
537
+
538
+ else:
539
+ _post = post
540
+
541
+ # Versions without a development segment should sort after those with one.
542
+ if dev is None:
543
+ _dev: CmpPrePostDevType = Infinity
544
+
545
+ else:
546
+ _dev = dev
547
+
548
+ if local is None:
549
+ # Versions without a local segment should sort before those with one.
550
+ _local: CmpLocalType = NegativeInfinity
551
+ else:
552
+ # Versions with a local segment need that segment parsed to implement
553
+ # the sorting rules in PEP440.
554
+ # - Alpha numeric segments sort before numeric segments
555
+ # - Alpha numeric segments sort lexicographically
556
+ # - Numeric segments sort numerically
557
+ # - Shorter versions sort before longer versions when the prefixes
558
+ # match exactly
559
+ _local = tuple(
560
+ (i, "") if isinstance(i, int) else (NegativeInfinity, i) for i in local
561
+ )
562
+
563
+ return epoch, _release, _pre, _post, _dev, _local
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ pip
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/LICENSE ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2022 Rick van Hattem
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/METADATA ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: portalocker
3
+ Version: 2.8.2
4
+ Summary: Wraps the portalocker recipe for easy usage
5
+ Author-email: Rick van Hattem <[email protected]>
6
+ License: BSD-3-Clause
7
+ Project-URL: bugs, https://github.com/wolph/portalocker/issues
8
+ Project-URL: documentation, https://portalocker.readthedocs.io/en/latest/
9
+ Project-URL: repository, https://github.com/wolph/portalocker/
10
+ Keywords: locking,locks,with,statement,windows,linux,unix
11
+ Platform: any
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Development Status :: 6 - Mature
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: BSD License
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: MacOS :: MacOS X
18
+ Classifier: Operating System :: MacOS
19
+ Classifier: Operating System :: Microsoft :: MS-DOS
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Classifier: Operating System :: Microsoft
22
+ Classifier: Operating System :: POSIX :: BSD :: FreeBSD
23
+ Classifier: Operating System :: POSIX :: BSD
24
+ Classifier: Operating System :: POSIX :: Linux
25
+ Classifier: Operating System :: POSIX :: SunOS/Solaris
26
+ Classifier: Operating System :: POSIX
27
+ Classifier: Operating System :: Unix
28
+ Classifier: Programming Language :: Python :: 3 :: Only
29
+ Classifier: Programming Language :: Python :: 3
30
+ Classifier: Programming Language :: Python :: 3.10
31
+ Classifier: Programming Language :: Python :: 3.11
32
+ Classifier: Programming Language :: Python :: 3.12
33
+ Classifier: Programming Language :: Python :: 3.8
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: Implementation :: CPython
36
+ Classifier: Programming Language :: Python :: Implementation :: IronPython
37
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
38
+ Classifier: Programming Language :: Python :: Implementation
39
+ Classifier: Programming Language :: Python
40
+ Classifier: Topic :: Education :: Testing
41
+ Classifier: Topic :: Office/Business
42
+ Classifier: Topic :: Other/Nonlisted Topic
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Classifier: Topic :: Software Development :: Libraries
45
+ Classifier: Topic :: System :: Monitoring
46
+ Requires-Python: >=3.8
47
+ Description-Content-Type: text/x-rst
48
+ License-File: LICENSE
49
+ Requires-Dist: pywin32 >=226 ; platform_system == "Windows"
50
+ Provides-Extra: docs
51
+ Requires-Dist: sphinx >=1.7.1 ; extra == 'docs'
52
+ Provides-Extra: redis
53
+ Requires-Dist: redis ; extra == 'redis'
54
+ Provides-Extra: tests
55
+ Requires-Dist: pytest >=5.4.1 ; extra == 'tests'
56
+ Requires-Dist: pytest-cov >=2.8.1 ; extra == 'tests'
57
+ Requires-Dist: pytest-timeout >=2.1.0 ; extra == 'tests'
58
+ Requires-Dist: sphinx >=6.0.0 ; extra == 'tests'
59
+ Requires-Dist: pytest-mypy >=0.8.0 ; extra == 'tests'
60
+ Requires-Dist: types-redis ; extra == 'tests'
61
+ Requires-Dist: redis ; extra == 'tests'
62
+
63
+ ############################################
64
+ portalocker - Cross-platform locking library
65
+ ############################################
66
+
67
+ .. image:: https://github.com/WoLpH/portalocker/actions/workflows/python-package.yml/badge.svg?branch=master
68
+ :alt: Linux Test Status
69
+ :target: https://github.com/WoLpH/portalocker/actions/
70
+
71
+ .. image:: https://ci.appveyor.com/api/projects/status/mgqry98hgpy4prhh?svg=true
72
+ :alt: Windows Tests Status
73
+ :target: https://ci.appveyor.com/project/WoLpH/portalocker
74
+
75
+ .. image:: https://coveralls.io/repos/WoLpH/portalocker/badge.svg?branch=master
76
+ :alt: Coverage Status
77
+ :target: https://coveralls.io/r/WoLpH/portalocker?branch=master
78
+
79
+ Overview
80
+ --------
81
+
82
+ Portalocker is a library to provide an easy API to file locking.
83
+
84
+ An important detail to note is that on Linux and Unix systems the locks are
85
+ advisory by default. By specifying the `-o mand` option to the mount command it
86
+ is possible to enable mandatory file locking on Linux. This is generally not
87
+ recommended however. For more information about the subject:
88
+
89
+ - https://en.wikipedia.org/wiki/File_locking
90
+ - http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
91
+ - https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
92
+
93
+ The module is currently maintained by Rick van Hattem <[email protected]>.
94
+ The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
95
+ requests can be submitted there. Patches are also very welcome.
96
+
97
+ Security contact information
98
+ ------------------------------------------------------------------------------
99
+
100
+ To report a security vulnerability, please use the
101
+ `Tidelift security contact <https://tidelift.com/security>`_.
102
+ Tidelift will coordinate the fix and disclosure.
103
+
104
+ Redis Locks
105
+ -----------
106
+
107
+ This library now features a lock based on Redis which allows for locks across
108
+ multiple threads, processes and even distributed locks across multiple
109
+ computers.
110
+
111
+ It is an extremely reliable Redis lock that is based on pubsub.
112
+
113
+ As opposed to most Redis locking systems based on key/value pairs,
114
+ this locking method is based on the pubsub system. The big advantage is
115
+ that if the connection gets killed due to network issues, crashing
116
+ processes or otherwise, it will still immediately unlock instead of
117
+ waiting for a lock timeout.
118
+
119
+ First make sure you have everything installed correctly:
120
+
121
+ ::
122
+
123
+ pip install "portalocker[redis]"
124
+
125
+ Usage is really easy:
126
+
127
+ ::
128
+
129
+ import portalocker
130
+
131
+ lock = portalocker.RedisLock('some_lock_channel_name')
132
+
133
+ with lock:
134
+ print('do something here')
135
+
136
+ The API is essentially identical to the other ``Lock`` classes so in addition
137
+ to the ``with`` statement you can also use ``lock.acquire(...)``.
138
+
139
+ Python 2
140
+ --------
141
+
142
+ Python 2 was supported in versions before Portalocker 2.0. If you are still
143
+ using
144
+ Python 2,
145
+ you can run this to install:
146
+
147
+ ::
148
+
149
+ pip install "portalocker<2"
150
+
151
+ Tips
152
+ ----
153
+
154
+ On some networked filesystems it might be needed to force a `os.fsync()` before
155
+ closing the file so it's actually written before another client reads the file.
156
+ Effectively this comes down to:
157
+
158
+ ::
159
+
160
+ with portalocker.Lock('some_file', 'rb+', timeout=60) as fh:
161
+ # do what you need to do
162
+ ...
163
+
164
+ # flush and sync to filesystem
165
+ fh.flush()
166
+ os.fsync(fh.fileno())
167
+
168
+ Links
169
+ -----
170
+
171
+ * Documentation
172
+ - http://portalocker.readthedocs.org/en/latest/
173
+ * Source
174
+ - https://github.com/WoLpH/portalocker
175
+ * Bug reports
176
+ - https://github.com/WoLpH/portalocker/issues
177
+ * Package homepage
178
+ - https://pypi.python.org/pypi/portalocker
179
+ * My blog
180
+ - http://w.wol.ph/
181
+
182
+ Examples
183
+ --------
184
+
185
+ To make sure your cache generation scripts don't race, use the `Lock` class:
186
+
187
+ >>> import portalocker
188
+ >>> with portalocker.Lock('somefile', timeout=1) as fh:
189
+ ... print('writing some stuff to my cache...', file=fh)
190
+
191
+ To customize the opening and locking a manual approach is also possible:
192
+
193
+ >>> import portalocker
194
+ >>> file = open('somefile', 'r+')
195
+ >>> portalocker.lock(file, portalocker.LockFlags.EXCLUSIVE)
196
+ >>> file.seek(12)
197
+ >>> file.write('foo')
198
+ >>> file.close()
199
+
200
+ Explicitly unlocking is not needed in most cases but omitting it has been known
201
+ to cause issues:
202
+ https://github.com/AzureAD/microsoft-authentication-extensions-for-python/issues/42#issuecomment-601108266
203
+
204
+ If needed, it can be done through:
205
+
206
+ >>> portalocker.unlock(file)
207
+
208
+ Do note that your data might still be in a buffer so it is possible that your
209
+ data is not available until you `flush()` or `close()`.
210
+
211
+ To create a cross platform bounded semaphore across multiple processes you can
212
+ use the `BoundedSemaphore` class which functions somewhat similar to
213
+ `threading.BoundedSemaphore`:
214
+
215
+ >>> import portalocker
216
+ >>> n = 2
217
+ >>> timeout = 0.1
218
+
219
+ >>> semaphore_a = portalocker.BoundedSemaphore(n, timeout=timeout)
220
+ >>> semaphore_b = portalocker.BoundedSemaphore(n, timeout=timeout)
221
+ >>> semaphore_c = portalocker.BoundedSemaphore(n, timeout=timeout)
222
+
223
+ >>> semaphore_a.acquire()
224
+ <portalocker.utils.Lock object at ...>
225
+ >>> semaphore_b.acquire()
226
+ <portalocker.utils.Lock object at ...>
227
+ >>> semaphore_c.acquire()
228
+ Traceback (most recent call last):
229
+ ...
230
+ portalocker.exceptions.AlreadyLocked
231
+
232
+
233
+ More examples can be found in the
234
+ `tests <http://portalocker.readthedocs.io/en/latest/_modules/tests/tests.html>`_.
235
+
236
+
237
+ Versioning
238
+ ----------
239
+
240
+ This library follows `Semantic Versioning <http://semver.org/>`_.
241
+
242
+
243
+ Changelog
244
+ ---------
245
+
246
+ Every release has a ``git tag`` with a commit message for the tag
247
+ explaining what was added and/or changed. The list of tags/releases
248
+ including the commit messages can be found here:
249
+ https://github.com/WoLpH/portalocker/releases
250
+
251
+ License
252
+ -------
253
+
254
+ See the `LICENSE <https://github.com/WoLpH/portalocker/blob/develop/LICENSE>`_ file.
255
+
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/RECORD ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ portalocker-2.8.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
2
+ portalocker-2.8.2.dist-info/LICENSE,sha256=pQVw-jsxAqQte6uwVpI4sLPArtzgBjyOTWUGDf0_cpM,1460
3
+ portalocker-2.8.2.dist-info/METADATA,sha256=2KIoWHT2tr_abTIWy3-8rpyF1uGPtlZUWZw2yK4jxWA,8525
4
+ portalocker-2.8.2.dist-info/RECORD,,
5
+ portalocker-2.8.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
6
+ portalocker-2.8.2.dist-info/top_level.txt,sha256=qfIEwW2X8cgtD0cFJIIWaR-cnKNo4ESR7Raiwxf-UNA,12
7
+ portalocker/__about__.py,sha256=qQIzhUALgyblL5TXWsApg_XFvmUJ70dzk1odhoSjNfo,230
8
+ portalocker/__init__.py,sha256=6z6mM1nNwPQnMvyuAUOsHdXp1KQivxsFhtf_zu5-UmQ,2087
9
+ portalocker/__main__.py,sha256=vhMZUPO17zwNarq7h2b-ne-M4vVpYN2gdIbrHJmBS8k,2624
10
+ portalocker/__pycache__/__about__.cpython-310.pyc,,
11
+ portalocker/__pycache__/__init__.cpython-310.pyc,,
12
+ portalocker/__pycache__/__main__.cpython-310.pyc,,
13
+ portalocker/__pycache__/constants.cpython-310.pyc,,
14
+ portalocker/__pycache__/exceptions.cpython-310.pyc,,
15
+ portalocker/__pycache__/portalocker.cpython-310.pyc,,
16
+ portalocker/__pycache__/redis.cpython-310.pyc,,
17
+ portalocker/__pycache__/utils.cpython-310.pyc,,
18
+ portalocker/constants.py,sha256=mw8YwUWn6ie91HK4pszEdWrfTU6il--QYPt4ve0rj4w,1130
19
+ portalocker/exceptions.py,sha256=giyP3Ha8URNlsN2YezZgQ9FwtRAcFOosBWl_GH1SnOA,469
20
+ portalocker/portalocker.py,sha256=0rc9ZsFVZ_JJdPJoiy1PhZzXd_FTUYlJqh9Xd2KouKk,4006
21
+ portalocker/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ portalocker/redis.py,sha256=DImklGnN42uHe8GG1viLVMRjGJwydrAKb8PV9uevUrk,8338
23
+ portalocker/utils.py,sha256=HYi0lQDlTPGVMnM21kXKmNNMbB8Q46JGglxqao0Y3IY,17489
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.41.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
env-llmeval/lib/python3.10/site-packages/portalocker-2.8.2.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ portalocker
env-llmeval/lib/python3.10/site-packages/pytablewriter/__pycache__/__version__.cpython-310.pyc ADDED
Binary file (384 Bytes). View file
 
env-llmeval/lib/python3.10/site-packages/pytablewriter/__pycache__/_converter.cpython-310.pyc ADDED
Binary file (511 Bytes). View file