Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- llmeval-env/lib/python3.10/site-packages/examples/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/examples/__pycache__/basic_example.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/filelock/__init__.py +52 -0
- llmeval-env/lib/python3.10/site-packages/filelock/__pycache__/_windows.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_api.py +366 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_error.py +30 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_soft.py +47 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_unix.py +68 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_util.py +52 -0
- llmeval-env/lib/python3.10/site-packages/filelock/_windows.py +65 -0
- llmeval-env/lib/python3.10/site-packages/filelock/py.typed +0 -0
- llmeval-env/lib/python3.10/site-packages/filelock/version.py +16 -0
- llmeval-env/lib/python3.10/site-packages/numpy.libs/libquadmath-96973f99.so.0.0.0 +0 -0
- llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow.so.1600 +3 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/adapters.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/certs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/compat.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/exceptions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/help.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/models.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__pycache__/status_codes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/requests/__version__.py +14 -0
- llmeval-env/lib/python3.10/site-packages/requests/_internal_utils.py +50 -0
- llmeval-env/lib/python3.10/site-packages/requests/adapters.py +538 -0
- llmeval-env/lib/python3.10/site-packages/requests/api.py +157 -0
- llmeval-env/lib/python3.10/site-packages/requests/auth.py +315 -0
- llmeval-env/lib/python3.10/site-packages/requests/certs.py +17 -0
- llmeval-env/lib/python3.10/site-packages/requests/compat.py +79 -0
- llmeval-env/lib/python3.10/site-packages/requests/exceptions.py +141 -0
- llmeval-env/lib/python3.10/site-packages/requests/help.py +134 -0
- llmeval-env/lib/python3.10/site-packages/requests/packages.py +28 -0
- llmeval-env/lib/python3.10/site-packages/requests/status_codes.py +128 -0
- llmeval-env/lib/python3.10/site-packages/requests/structures.py +99 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_common.py +28 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_dictionary.py +28 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_infinity.py +32 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_interface.py +15 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_ipaddress.py +35 -0
- llmeval-env/lib/python3.10/site-packages/typepy/checker/_list.py +32 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__init__.py +37 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_base.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_binary.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_bool.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_bytes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_datetime.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_dictionary.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_infinity.cpython-310.pyc +0 -0
.gitattributes
CHANGED
@@ -79,3 +79,4 @@ llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_dataset.so.1600 filter
|
|
79 |
llmeval-env/lib/python3.10/site-packages/pyarrow/lib.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
80 |
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_substrait.so.1600 filter=lfs diff=lfs merge=lfs -text
|
81 |
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_flight.so.1600 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
79 |
llmeval-env/lib/python3.10/site-packages/pyarrow/lib.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
80 |
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_substrait.so.1600 filter=lfs diff=lfs merge=lfs -text
|
81 |
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow_flight.so.1600 filter=lfs diff=lfs merge=lfs -text
|
82 |
+
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow.so.1600 filter=lfs diff=lfs merge=lfs -text
|
llmeval-env/lib/python3.10/site-packages/examples/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (181 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/examples/__pycache__/basic_example.cpython-310.pyc
ADDED
Binary file (2.18 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/filelock/__init__.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
A platform independent file lock that supports the with-statement.
|
3 |
+
|
4 |
+
.. autodata:: filelock.__version__
|
5 |
+
:no-value:
|
6 |
+
|
7 |
+
"""
|
8 |
+
|
9 |
+
from __future__ import annotations
|
10 |
+
|
11 |
+
import sys
|
12 |
+
import warnings
|
13 |
+
from typing import TYPE_CHECKING
|
14 |
+
|
15 |
+
from ._api import AcquireReturnProxy, BaseFileLock
|
16 |
+
from ._error import Timeout
|
17 |
+
from ._soft import SoftFileLock
|
18 |
+
from ._unix import UnixFileLock, has_fcntl
|
19 |
+
from ._windows import WindowsFileLock
|
20 |
+
from .version import version
|
21 |
+
|
22 |
+
#: version of the project as a string
|
23 |
+
__version__: str = version
|
24 |
+
|
25 |
+
|
26 |
+
if sys.platform == "win32": # pragma: win32 cover
|
27 |
+
_FileLock: type[BaseFileLock] = WindowsFileLock
|
28 |
+
else: # pragma: win32 no cover # noqa: PLR5501
|
29 |
+
if has_fcntl:
|
30 |
+
_FileLock: type[BaseFileLock] = UnixFileLock
|
31 |
+
else:
|
32 |
+
_FileLock = SoftFileLock
|
33 |
+
if warnings is not None:
|
34 |
+
warnings.warn("only soft file lock is available", stacklevel=2)
|
35 |
+
|
36 |
+
if TYPE_CHECKING:
|
37 |
+
FileLock = SoftFileLock
|
38 |
+
else:
|
39 |
+
#: Alias for the lock, which should be used for the current platform.
|
40 |
+
FileLock = _FileLock
|
41 |
+
|
42 |
+
|
43 |
+
__all__ = [
|
44 |
+
"AcquireReturnProxy",
|
45 |
+
"BaseFileLock",
|
46 |
+
"FileLock",
|
47 |
+
"SoftFileLock",
|
48 |
+
"Timeout",
|
49 |
+
"UnixFileLock",
|
50 |
+
"WindowsFileLock",
|
51 |
+
"__version__",
|
52 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/__pycache__/_windows.cpython-310.pyc
ADDED
Binary file (2.08 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/filelock/_api.py
ADDED
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import contextlib
|
4 |
+
import logging
|
5 |
+
import os
|
6 |
+
import time
|
7 |
+
import warnings
|
8 |
+
from abc import ABC, abstractmethod
|
9 |
+
from dataclasses import dataclass
|
10 |
+
from threading import local
|
11 |
+
from typing import TYPE_CHECKING, Any
|
12 |
+
from weakref import WeakValueDictionary
|
13 |
+
|
14 |
+
from ._error import Timeout
|
15 |
+
|
16 |
+
if TYPE_CHECKING:
|
17 |
+
import sys
|
18 |
+
from types import TracebackType
|
19 |
+
|
20 |
+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
|
21 |
+
from typing import Self
|
22 |
+
else: # pragma: no cover (<py311)
|
23 |
+
from typing_extensions import Self
|
24 |
+
|
25 |
+
|
26 |
+
_LOGGER = logging.getLogger("filelock")
|
27 |
+
|
28 |
+
|
29 |
+
# This is a helper class which is returned by :meth:`BaseFileLock.acquire` and wraps the lock to make sure __enter__
|
30 |
+
# is not called twice when entering the with statement. If we would simply return *self*, the lock would be acquired
|
31 |
+
# again in the *__enter__* method of the BaseFileLock, but not released again automatically. issue #37 (memory leak)
|
32 |
+
class AcquireReturnProxy:
|
33 |
+
"""A context-aware object that will release the lock file when exiting."""
|
34 |
+
|
35 |
+
def __init__(self, lock: BaseFileLock) -> None:
|
36 |
+
self.lock = lock
|
37 |
+
|
38 |
+
def __enter__(self) -> BaseFileLock:
|
39 |
+
return self.lock
|
40 |
+
|
41 |
+
def __exit__(
|
42 |
+
self,
|
43 |
+
exc_type: type[BaseException] | None,
|
44 |
+
exc_value: BaseException | None,
|
45 |
+
traceback: TracebackType | None,
|
46 |
+
) -> None:
|
47 |
+
self.lock.release()
|
48 |
+
|
49 |
+
|
50 |
+
@dataclass
|
51 |
+
class FileLockContext:
|
52 |
+
"""A dataclass which holds the context for a ``BaseFileLock`` object."""
|
53 |
+
|
54 |
+
# The context is held in a separate class to allow optional use of thread local storage via the
|
55 |
+
# ThreadLocalFileContext class.
|
56 |
+
|
57 |
+
#: The path to the lock file.
|
58 |
+
lock_file: str
|
59 |
+
|
60 |
+
#: The default timeout value.
|
61 |
+
timeout: float
|
62 |
+
|
63 |
+
#: The mode for the lock files
|
64 |
+
mode: int
|
65 |
+
|
66 |
+
#: Whether the lock should be blocking or not
|
67 |
+
blocking: bool
|
68 |
+
|
69 |
+
#: The file descriptor for the *_lock_file* as it is returned by the os.open() function, not None when lock held
|
70 |
+
lock_file_fd: int | None = None
|
71 |
+
|
72 |
+
#: The lock counter is used for implementing the nested locking mechanism.
|
73 |
+
lock_counter: int = 0 # When the lock is acquired is increased and the lock is only released, when this value is 0
|
74 |
+
|
75 |
+
|
76 |
+
class ThreadLocalFileContext(FileLockContext, local):
|
77 |
+
"""A thread local version of the ``FileLockContext`` class."""
|
78 |
+
|
79 |
+
|
80 |
+
class BaseFileLock(ABC, contextlib.ContextDecorator):
|
81 |
+
"""Abstract base class for a file lock object."""
|
82 |
+
|
83 |
+
_instances: WeakValueDictionary[str, BaseFileLock]
|
84 |
+
|
85 |
+
def __new__( # noqa: PLR0913
|
86 |
+
cls,
|
87 |
+
lock_file: str | os.PathLike[str],
|
88 |
+
timeout: float = -1,
|
89 |
+
mode: int = 0o644,
|
90 |
+
thread_local: bool = True, # noqa: ARG003, FBT001, FBT002
|
91 |
+
*,
|
92 |
+
blocking: bool = True, # noqa: ARG003
|
93 |
+
is_singleton: bool = False,
|
94 |
+
**kwargs: dict[str, Any], # capture remaining kwargs for subclasses # noqa: ARG003
|
95 |
+
) -> Self:
|
96 |
+
"""Create a new lock object or if specified return the singleton instance for the lock file."""
|
97 |
+
if not is_singleton:
|
98 |
+
return super().__new__(cls)
|
99 |
+
|
100 |
+
instance = cls._instances.get(str(lock_file))
|
101 |
+
if not instance:
|
102 |
+
instance = super().__new__(cls)
|
103 |
+
cls._instances[str(lock_file)] = instance
|
104 |
+
elif timeout != instance.timeout or mode != instance.mode:
|
105 |
+
msg = "Singleton lock instances cannot be initialized with differing arguments"
|
106 |
+
raise ValueError(msg)
|
107 |
+
|
108 |
+
return instance # type: ignore[return-value] # https://github.com/python/mypy/issues/15322
|
109 |
+
|
110 |
+
def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
|
111 |
+
"""Setup unique state for lock subclasses."""
|
112 |
+
super().__init_subclass__(**kwargs)
|
113 |
+
cls._instances = WeakValueDictionary()
|
114 |
+
|
115 |
+
def __init__( # noqa: PLR0913
|
116 |
+
self,
|
117 |
+
lock_file: str | os.PathLike[str],
|
118 |
+
timeout: float = -1,
|
119 |
+
mode: int = 0o644,
|
120 |
+
thread_local: bool = True, # noqa: FBT001, FBT002
|
121 |
+
*,
|
122 |
+
blocking: bool = True,
|
123 |
+
is_singleton: bool = False,
|
124 |
+
) -> None:
|
125 |
+
"""
|
126 |
+
Create a new lock object.
|
127 |
+
|
128 |
+
:param lock_file: path to the file
|
129 |
+
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in \
|
130 |
+
the acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it \
|
131 |
+
to a negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
|
132 |
+
:param mode: file permissions for the lockfile
|
133 |
+
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to \
|
134 |
+
``False`` then the lock will be reentrant across threads.
|
135 |
+
:param blocking: whether the lock should be blocking or not
|
136 |
+
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created \
|
137 |
+
per lock file. This is useful if you want to use the lock object for reentrant locking without needing \
|
138 |
+
to pass the same object around.
|
139 |
+
|
140 |
+
"""
|
141 |
+
self._is_thread_local = thread_local
|
142 |
+
self._is_singleton = is_singleton
|
143 |
+
|
144 |
+
# Create the context. Note that external code should not work with the context directly and should instead use
|
145 |
+
# properties of this class.
|
146 |
+
kwargs: dict[str, Any] = {
|
147 |
+
"lock_file": os.fspath(lock_file),
|
148 |
+
"timeout": timeout,
|
149 |
+
"mode": mode,
|
150 |
+
"blocking": blocking,
|
151 |
+
}
|
152 |
+
self._context: FileLockContext = (ThreadLocalFileContext if thread_local else FileLockContext)(**kwargs)
|
153 |
+
|
154 |
+
def is_thread_local(self) -> bool:
|
155 |
+
""":return: a flag indicating if this lock is thread local or not"""
|
156 |
+
return self._is_thread_local
|
157 |
+
|
158 |
+
@property
|
159 |
+
def is_singleton(self) -> bool:
|
160 |
+
""":return: a flag indicating if this lock is singleton or not"""
|
161 |
+
return self._is_singleton
|
162 |
+
|
163 |
+
@property
|
164 |
+
def lock_file(self) -> str:
|
165 |
+
""":return: path to the lock file"""
|
166 |
+
return self._context.lock_file
|
167 |
+
|
168 |
+
@property
|
169 |
+
def timeout(self) -> float:
|
170 |
+
"""
|
171 |
+
:return: the default timeout value, in seconds
|
172 |
+
|
173 |
+
.. versionadded:: 2.0.0
|
174 |
+
"""
|
175 |
+
return self._context.timeout
|
176 |
+
|
177 |
+
@timeout.setter
|
178 |
+
def timeout(self, value: float | str) -> None:
|
179 |
+
"""
|
180 |
+
Change the default timeout value.
|
181 |
+
|
182 |
+
:param value: the new value, in seconds
|
183 |
+
|
184 |
+
"""
|
185 |
+
self._context.timeout = float(value)
|
186 |
+
|
187 |
+
@property
|
188 |
+
def blocking(self) -> bool:
|
189 |
+
""":return: whether the locking is blocking or not"""
|
190 |
+
return self._context.blocking
|
191 |
+
|
192 |
+
@blocking.setter
|
193 |
+
def blocking(self, value: bool) -> None:
|
194 |
+
"""
|
195 |
+
Change the default blocking value.
|
196 |
+
|
197 |
+
:param value: the new value as bool
|
198 |
+
|
199 |
+
"""
|
200 |
+
self._context.blocking = value
|
201 |
+
|
202 |
+
@property
|
203 |
+
def mode(self) -> int:
|
204 |
+
""":return: the file permissions for the lockfile"""
|
205 |
+
return self._context.mode
|
206 |
+
|
207 |
+
@abstractmethod
|
208 |
+
def _acquire(self) -> None:
|
209 |
+
"""If the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file."""
|
210 |
+
raise NotImplementedError
|
211 |
+
|
212 |
+
@abstractmethod
|
213 |
+
def _release(self) -> None:
|
214 |
+
"""Releases the lock and sets self._context.lock_file_fd to None."""
|
215 |
+
raise NotImplementedError
|
216 |
+
|
217 |
+
@property
|
218 |
+
def is_locked(self) -> bool:
|
219 |
+
"""
|
220 |
+
|
221 |
+
:return: A boolean indicating if the lock file is holding the lock currently.
|
222 |
+
|
223 |
+
.. versionchanged:: 2.0.0
|
224 |
+
|
225 |
+
This was previously a method and is now a property.
|
226 |
+
"""
|
227 |
+
return self._context.lock_file_fd is not None
|
228 |
+
|
229 |
+
@property
|
230 |
+
def lock_counter(self) -> int:
|
231 |
+
""":return: The number of times this lock has been acquired (but not yet released)."""
|
232 |
+
return self._context.lock_counter
|
233 |
+
|
234 |
+
def acquire(
|
235 |
+
self,
|
236 |
+
timeout: float | None = None,
|
237 |
+
poll_interval: float = 0.05,
|
238 |
+
*,
|
239 |
+
poll_intervall: float | None = None,
|
240 |
+
blocking: bool | None = None,
|
241 |
+
) -> AcquireReturnProxy:
|
242 |
+
"""
|
243 |
+
Try to acquire the file lock.
|
244 |
+
|
245 |
+
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
|
246 |
+
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
|
247 |
+
:param poll_interval: interval of trying to acquire the lock file
|
248 |
+
:param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
|
249 |
+
:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
|
250 |
+
first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
|
251 |
+
:raises Timeout: if fails to acquire lock within the timeout period
|
252 |
+
:return: a context object that will unlock the file when the context is exited
|
253 |
+
|
254 |
+
.. code-block:: python
|
255 |
+
|
256 |
+
# You can use this method in the context manager (recommended)
|
257 |
+
with lock.acquire():
|
258 |
+
pass
|
259 |
+
|
260 |
+
# Or use an equivalent try-finally construct:
|
261 |
+
lock.acquire()
|
262 |
+
try:
|
263 |
+
pass
|
264 |
+
finally:
|
265 |
+
lock.release()
|
266 |
+
|
267 |
+
.. versionchanged:: 2.0.0
|
268 |
+
|
269 |
+
This method returns now a *proxy* object instead of *self*,
|
270 |
+
so that it can be used in a with statement without side effects.
|
271 |
+
|
272 |
+
"""
|
273 |
+
# Use the default timeout, if no timeout is provided.
|
274 |
+
if timeout is None:
|
275 |
+
timeout = self._context.timeout
|
276 |
+
|
277 |
+
if blocking is None:
|
278 |
+
blocking = self._context.blocking
|
279 |
+
|
280 |
+
if poll_intervall is not None:
|
281 |
+
msg = "use poll_interval instead of poll_intervall"
|
282 |
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
283 |
+
poll_interval = poll_intervall
|
284 |
+
|
285 |
+
# Increment the number right at the beginning. We can still undo it, if something fails.
|
286 |
+
self._context.lock_counter += 1
|
287 |
+
|
288 |
+
lock_id = id(self)
|
289 |
+
lock_filename = self.lock_file
|
290 |
+
start_time = time.perf_counter()
|
291 |
+
try:
|
292 |
+
while True:
|
293 |
+
if not self.is_locked:
|
294 |
+
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
295 |
+
self._acquire()
|
296 |
+
if self.is_locked:
|
297 |
+
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
298 |
+
break
|
299 |
+
if blocking is False:
|
300 |
+
_LOGGER.debug("Failed to immediately acquire lock %s on %s", lock_id, lock_filename)
|
301 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
302 |
+
if 0 <= timeout < time.perf_counter() - start_time:
|
303 |
+
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
|
304 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
305 |
+
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
|
306 |
+
_LOGGER.debug(msg, lock_id, lock_filename, poll_interval)
|
307 |
+
time.sleep(poll_interval)
|
308 |
+
except BaseException: # Something did go wrong, so decrement the counter.
|
309 |
+
self._context.lock_counter = max(0, self._context.lock_counter - 1)
|
310 |
+
raise
|
311 |
+
return AcquireReturnProxy(lock=self)
|
312 |
+
|
313 |
+
def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
|
314 |
+
"""
|
315 |
+
Releases the file lock. Please note, that the lock is only completely released, if the lock counter is 0.
|
316 |
+
Also note, that the lock file itself is not automatically deleted.
|
317 |
+
|
318 |
+
:param force: If true, the lock counter is ignored and the lock is released in every case/
|
319 |
+
|
320 |
+
"""
|
321 |
+
if self.is_locked:
|
322 |
+
self._context.lock_counter -= 1
|
323 |
+
|
324 |
+
if self._context.lock_counter == 0 or force:
|
325 |
+
lock_id, lock_filename = id(self), self.lock_file
|
326 |
+
|
327 |
+
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
328 |
+
self._release()
|
329 |
+
self._context.lock_counter = 0
|
330 |
+
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
331 |
+
|
332 |
+
def __enter__(self) -> Self:
|
333 |
+
"""
|
334 |
+
Acquire the lock.
|
335 |
+
|
336 |
+
:return: the lock object
|
337 |
+
|
338 |
+
"""
|
339 |
+
self.acquire()
|
340 |
+
return self
|
341 |
+
|
342 |
+
def __exit__(
|
343 |
+
self,
|
344 |
+
exc_type: type[BaseException] | None,
|
345 |
+
exc_value: BaseException | None,
|
346 |
+
traceback: TracebackType | None,
|
347 |
+
) -> None:
|
348 |
+
"""
|
349 |
+
Release the lock.
|
350 |
+
|
351 |
+
:param exc_type: the exception type if raised
|
352 |
+
:param exc_value: the exception value if raised
|
353 |
+
:param traceback: the exception traceback if raised
|
354 |
+
|
355 |
+
"""
|
356 |
+
self.release()
|
357 |
+
|
358 |
+
def __del__(self) -> None:
|
359 |
+
"""Called when the lock object is deleted."""
|
360 |
+
self.release(force=True)
|
361 |
+
|
362 |
+
|
363 |
+
__all__ = [
|
364 |
+
"AcquireReturnProxy",
|
365 |
+
"BaseFileLock",
|
366 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/_error.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
from typing import Any
|
4 |
+
|
5 |
+
|
6 |
+
class Timeout(TimeoutError): # noqa: N818
|
7 |
+
"""Raised when the lock could not be acquired in *timeout* seconds."""
|
8 |
+
|
9 |
+
def __init__(self, lock_file: str) -> None:
|
10 |
+
super().__init__()
|
11 |
+
self._lock_file = lock_file
|
12 |
+
|
13 |
+
def __reduce__(self) -> str | tuple[Any, ...]:
|
14 |
+
return self.__class__, (self._lock_file,) # Properly pickle the exception
|
15 |
+
|
16 |
+
def __str__(self) -> str:
|
17 |
+
return f"The file lock '{self._lock_file}' could not be acquired."
|
18 |
+
|
19 |
+
def __repr__(self) -> str:
|
20 |
+
return f"{self.__class__.__name__}({self.lock_file!r})"
|
21 |
+
|
22 |
+
@property
|
23 |
+
def lock_file(self) -> str:
|
24 |
+
""":return: The path of the file lock."""
|
25 |
+
return self._lock_file
|
26 |
+
|
27 |
+
|
28 |
+
__all__ = [
|
29 |
+
"Timeout",
|
30 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/_soft.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from contextlib import suppress
|
6 |
+
from errno import EACCES, EEXIST
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
from ._api import BaseFileLock
|
10 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
11 |
+
|
12 |
+
|
13 |
+
class SoftFileLock(BaseFileLock):
|
14 |
+
"""Simply watches the existence of the lock file."""
|
15 |
+
|
16 |
+
def _acquire(self) -> None:
|
17 |
+
raise_on_not_writable_file(self.lock_file)
|
18 |
+
ensure_directory_exists(self.lock_file)
|
19 |
+
# first check for exists and read-only mode as the open will mask this case as EEXIST
|
20 |
+
flags = (
|
21 |
+
os.O_WRONLY # open for writing only
|
22 |
+
| os.O_CREAT
|
23 |
+
| os.O_EXCL # together with above raise EEXIST if the file specified by filename exists
|
24 |
+
| os.O_TRUNC # truncate the file to zero byte
|
25 |
+
)
|
26 |
+
try:
|
27 |
+
file_handler = os.open(self.lock_file, flags, self._context.mode)
|
28 |
+
except OSError as exception: # re-raise unless expected exception
|
29 |
+
if not (
|
30 |
+
exception.errno == EEXIST # lock already exist
|
31 |
+
or (exception.errno == EACCES and sys.platform == "win32") # has no access to this lock
|
32 |
+
): # pragma: win32 no cover
|
33 |
+
raise
|
34 |
+
else:
|
35 |
+
self._context.lock_file_fd = file_handler
|
36 |
+
|
37 |
+
def _release(self) -> None:
|
38 |
+
assert self._context.lock_file_fd is not None # noqa: S101
|
39 |
+
os.close(self._context.lock_file_fd) # the lock file is definitely not None
|
40 |
+
self._context.lock_file_fd = None
|
41 |
+
with suppress(OSError): # the file is already deleted and that's what we want
|
42 |
+
Path(self.lock_file).unlink()
|
43 |
+
|
44 |
+
|
45 |
+
__all__ = [
|
46 |
+
"SoftFileLock",
|
47 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/_unix.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from contextlib import suppress
|
6 |
+
from errno import ENOSYS
|
7 |
+
from pathlib import Path
|
8 |
+
from typing import cast
|
9 |
+
|
10 |
+
from ._api import BaseFileLock
|
11 |
+
from ._util import ensure_directory_exists
|
12 |
+
|
13 |
+
#: a flag to indicate if the fcntl API is available
|
14 |
+
has_fcntl = False
|
15 |
+
if sys.platform == "win32": # pragma: win32 cover
|
16 |
+
|
17 |
+
class UnixFileLock(BaseFileLock):
|
18 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
19 |
+
|
20 |
+
def _acquire(self) -> None:
|
21 |
+
raise NotImplementedError
|
22 |
+
|
23 |
+
def _release(self) -> None:
|
24 |
+
raise NotImplementedError
|
25 |
+
|
26 |
+
else: # pragma: win32 no cover
|
27 |
+
try:
|
28 |
+
import fcntl
|
29 |
+
except ImportError:
|
30 |
+
pass
|
31 |
+
else:
|
32 |
+
has_fcntl = True
|
33 |
+
|
34 |
+
class UnixFileLock(BaseFileLock):
|
35 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
36 |
+
|
37 |
+
def _acquire(self) -> None:
|
38 |
+
ensure_directory_exists(self.lock_file)
|
39 |
+
open_flags = os.O_RDWR | os.O_TRUNC
|
40 |
+
if not Path(self.lock_file).exists():
|
41 |
+
open_flags |= os.O_CREAT
|
42 |
+
fd = os.open(self.lock_file, open_flags, self._context.mode)
|
43 |
+
with suppress(PermissionError): # This locked is not owned by this UID
|
44 |
+
os.fchmod(fd, self._context.mode)
|
45 |
+
try:
|
46 |
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
47 |
+
except OSError as exception:
|
48 |
+
os.close(fd)
|
49 |
+
if exception.errno == ENOSYS: # NotImplemented error
|
50 |
+
msg = "FileSystem does not appear to support flock; use SoftFileLock instead"
|
51 |
+
raise NotImplementedError(msg) from exception
|
52 |
+
else:
|
53 |
+
self._context.lock_file_fd = fd
|
54 |
+
|
55 |
+
def _release(self) -> None:
|
56 |
+
# Do not remove the lockfile:
|
57 |
+
# https://github.com/tox-dev/py-filelock/issues/31
|
58 |
+
# https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
|
59 |
+
fd = cast(int, self._context.lock_file_fd)
|
60 |
+
self._context.lock_file_fd = None
|
61 |
+
fcntl.flock(fd, fcntl.LOCK_UN)
|
62 |
+
os.close(fd)
|
63 |
+
|
64 |
+
|
65 |
+
__all__ = [
|
66 |
+
"UnixFileLock",
|
67 |
+
"has_fcntl",
|
68 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/_util.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import stat
|
5 |
+
import sys
|
6 |
+
from errno import EACCES, EISDIR
|
7 |
+
from pathlib import Path
|
8 |
+
|
9 |
+
|
10 |
+
def raise_on_not_writable_file(filename: str) -> None:
|
11 |
+
"""
|
12 |
+
Raise an exception if attempting to open the file for writing would fail.
|
13 |
+
|
14 |
+
This is done so files that will never be writable can be separated from files that are writable but currently
|
15 |
+
locked.
|
16 |
+
|
17 |
+
:param filename: file to check
|
18 |
+
:raises OSError: as if the file was opened for writing.
|
19 |
+
|
20 |
+
"""
|
21 |
+
try: # use stat to do exists + can write to check without race condition
|
22 |
+
file_stat = os.stat(filename) # noqa: PTH116
|
23 |
+
except OSError:
|
24 |
+
return # swallow does not exist or other errors
|
25 |
+
|
26 |
+
if file_stat.st_mtime != 0: # if os.stat returns but modification is zero that's an invalid os.stat - ignore it
|
27 |
+
if not (file_stat.st_mode & stat.S_IWUSR):
|
28 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
29 |
+
|
30 |
+
if stat.S_ISDIR(file_stat.st_mode):
|
31 |
+
if sys.platform == "win32": # pragma: win32 cover
|
32 |
+
# On Windows, this is PermissionError
|
33 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
34 |
+
else: # pragma: win32 no cover # noqa: RET506
|
35 |
+
# On linux / macOS, this is IsADirectoryError
|
36 |
+
raise IsADirectoryError(EISDIR, "Is a directory", filename)
|
37 |
+
|
38 |
+
|
39 |
+
def ensure_directory_exists(filename: Path | str) -> None:
|
40 |
+
"""
|
41 |
+
Ensure the directory containing the file exists (create it if necessary).
|
42 |
+
|
43 |
+
:param filename: file.
|
44 |
+
|
45 |
+
"""
|
46 |
+
Path(filename).parent.mkdir(parents=True, exist_ok=True)
|
47 |
+
|
48 |
+
|
49 |
+
__all__ = [
|
50 |
+
"ensure_directory_exists",
|
51 |
+
"raise_on_not_writable_file",
|
52 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/_windows.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
from contextlib import suppress
|
6 |
+
from errno import EACCES
|
7 |
+
from pathlib import Path
|
8 |
+
from typing import cast
|
9 |
+
|
10 |
+
from ._api import BaseFileLock
|
11 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
12 |
+
|
13 |
+
if sys.platform == "win32": # pragma: win32 cover
|
14 |
+
import msvcrt
|
15 |
+
|
16 |
+
class WindowsFileLock(BaseFileLock):
|
17 |
+
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems."""
|
18 |
+
|
19 |
+
def _acquire(self) -> None:
|
20 |
+
raise_on_not_writable_file(self.lock_file)
|
21 |
+
ensure_directory_exists(self.lock_file)
|
22 |
+
flags = (
|
23 |
+
os.O_RDWR # open for read and write
|
24 |
+
| os.O_CREAT # create file if not exists
|
25 |
+
| os.O_TRUNC # truncate file if not empty
|
26 |
+
)
|
27 |
+
try:
|
28 |
+
fd = os.open(self.lock_file, flags, self._context.mode)
|
29 |
+
except OSError as exception:
|
30 |
+
if exception.errno != EACCES: # has no access to this lock
|
31 |
+
raise
|
32 |
+
else:
|
33 |
+
try:
|
34 |
+
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
|
35 |
+
except OSError as exception:
|
36 |
+
os.close(fd) # close file first
|
37 |
+
if exception.errno != EACCES: # file is already locked
|
38 |
+
raise
|
39 |
+
else:
|
40 |
+
self._context.lock_file_fd = fd
|
41 |
+
|
42 |
+
def _release(self) -> None:
|
43 |
+
fd = cast(int, self._context.lock_file_fd)
|
44 |
+
self._context.lock_file_fd = None
|
45 |
+
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
|
46 |
+
os.close(fd)
|
47 |
+
|
48 |
+
with suppress(OSError): # Probably another instance of the application hat acquired the file lock.
|
49 |
+
Path(self.lock_file).unlink()
|
50 |
+
|
51 |
+
else: # pragma: win32 no cover
|
52 |
+
|
53 |
+
class WindowsFileLock(BaseFileLock):
|
54 |
+
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems."""
|
55 |
+
|
56 |
+
def _acquire(self) -> None:
|
57 |
+
raise NotImplementedError
|
58 |
+
|
59 |
+
def _release(self) -> None:
|
60 |
+
raise NotImplementedError
|
61 |
+
|
62 |
+
|
63 |
+
__all__ = [
|
64 |
+
"WindowsFileLock",
|
65 |
+
]
|
llmeval-env/lib/python3.10/site-packages/filelock/py.typed
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/filelock/version.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# file generated by setuptools_scm
|
2 |
+
# don't change, don't track in version control
|
3 |
+
TYPE_CHECKING = False
|
4 |
+
if TYPE_CHECKING:
|
5 |
+
from typing import Tuple, Union
|
6 |
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
7 |
+
else:
|
8 |
+
VERSION_TUPLE = object
|
9 |
+
|
10 |
+
version: str
|
11 |
+
__version__: str
|
12 |
+
__version_tuple__: VERSION_TUPLE
|
13 |
+
version_tuple: VERSION_TUPLE
|
14 |
+
|
15 |
+
__version__ = version = '3.14.0'
|
16 |
+
__version_tuple__ = version_tuple = (3, 14, 0)
|
llmeval-env/lib/python3.10/site-packages/numpy.libs/libquadmath-96973f99.so.0.0.0
ADDED
Binary file (248 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pyarrow/libarrow.so.1600
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d85a4a6d150efcee79c4cd53c88a5a31fd3f6f6efde3e7bd439cd8f4883024ae
|
3 |
+
size 67913016
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (3.87 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/adapters.cpython-310.pyc
ADDED
Binary file (16.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/certs.cpython-310.pyc
ADDED
Binary file (616 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/compat.cpython-310.pyc
ADDED
Binary file (1.51 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/exceptions.cpython-310.pyc
ADDED
Binary file (5.72 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/help.cpython-310.pyc
ADDED
Binary file (2.84 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/models.cpython-310.pyc
ADDED
Binary file (24.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__pycache__/status_codes.cpython-310.pyc
ADDED
Binary file (4.66 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/requests/__version__.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# .-. .-. .-. . . .-. .-. .-. .-.
|
2 |
+
# |( |- |.| | | |- `-. | `-.
|
3 |
+
# ' ' `-' `-`.`-' `-' `-' ' `-'
|
4 |
+
|
5 |
+
__title__ = "requests"
|
6 |
+
__description__ = "Python HTTP for Humans."
|
7 |
+
__url__ = "https://requests.readthedocs.io"
|
8 |
+
__version__ = "2.31.0"
|
9 |
+
__build__ = 0x023100
|
10 |
+
__author__ = "Kenneth Reitz"
|
11 |
+
__author_email__ = "[email protected]"
|
12 |
+
__license__ = "Apache 2.0"
|
13 |
+
__copyright__ = "Copyright Kenneth Reitz"
|
14 |
+
__cake__ = "\u2728 \U0001f370 \u2728"
|
llmeval-env/lib/python3.10/site-packages/requests/_internal_utils.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests._internal_utils
|
3 |
+
~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Provides utility functions that are consumed internally by Requests
|
6 |
+
which depend on extremely few external helpers (such as compat)
|
7 |
+
"""
|
8 |
+
import re
|
9 |
+
|
10 |
+
from .compat import builtin_str
|
11 |
+
|
12 |
+
_VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*$")
|
13 |
+
_VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*$")
|
14 |
+
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
|
15 |
+
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")
|
16 |
+
|
17 |
+
_HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
|
18 |
+
_HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
|
19 |
+
HEADER_VALIDATORS = {
|
20 |
+
bytes: _HEADER_VALIDATORS_BYTE,
|
21 |
+
str: _HEADER_VALIDATORS_STR,
|
22 |
+
}
|
23 |
+
|
24 |
+
|
25 |
+
def to_native_string(string, encoding="ascii"):
|
26 |
+
"""Given a string object, regardless of type, returns a representation of
|
27 |
+
that string in the native string type, encoding and decoding where
|
28 |
+
necessary. This assumes ASCII unless told otherwise.
|
29 |
+
"""
|
30 |
+
if isinstance(string, builtin_str):
|
31 |
+
out = string
|
32 |
+
else:
|
33 |
+
out = string.decode(encoding)
|
34 |
+
|
35 |
+
return out
|
36 |
+
|
37 |
+
|
38 |
+
def unicode_is_ascii(u_string):
|
39 |
+
"""Determine if unicode string only contains ASCII characters.
|
40 |
+
|
41 |
+
:param str u_string: unicode string to check. Must be unicode
|
42 |
+
and not Python 2 `str`.
|
43 |
+
:rtype: bool
|
44 |
+
"""
|
45 |
+
assert isinstance(u_string, str)
|
46 |
+
try:
|
47 |
+
u_string.encode("ascii")
|
48 |
+
return True
|
49 |
+
except UnicodeEncodeError:
|
50 |
+
return False
|
llmeval-env/lib/python3.10/site-packages/requests/adapters.py
ADDED
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.adapters
|
3 |
+
~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
This module contains the transport adapters that Requests uses to define
|
6 |
+
and maintain connections.
|
7 |
+
"""
|
8 |
+
|
9 |
+
import os.path
|
10 |
+
import socket # noqa: F401
|
11 |
+
|
12 |
+
from urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
|
13 |
+
from urllib3.exceptions import HTTPError as _HTTPError
|
14 |
+
from urllib3.exceptions import InvalidHeader as _InvalidHeader
|
15 |
+
from urllib3.exceptions import (
|
16 |
+
LocationValueError,
|
17 |
+
MaxRetryError,
|
18 |
+
NewConnectionError,
|
19 |
+
ProtocolError,
|
20 |
+
)
|
21 |
+
from urllib3.exceptions import ProxyError as _ProxyError
|
22 |
+
from urllib3.exceptions import ReadTimeoutError, ResponseError
|
23 |
+
from urllib3.exceptions import SSLError as _SSLError
|
24 |
+
from urllib3.poolmanager import PoolManager, proxy_from_url
|
25 |
+
from urllib3.util import Timeout as TimeoutSauce
|
26 |
+
from urllib3.util import parse_url
|
27 |
+
from urllib3.util.retry import Retry
|
28 |
+
|
29 |
+
from .auth import _basic_auth_str
|
30 |
+
from .compat import basestring, urlparse
|
31 |
+
from .cookies import extract_cookies_to_jar
|
32 |
+
from .exceptions import (
|
33 |
+
ConnectionError,
|
34 |
+
ConnectTimeout,
|
35 |
+
InvalidHeader,
|
36 |
+
InvalidProxyURL,
|
37 |
+
InvalidSchema,
|
38 |
+
InvalidURL,
|
39 |
+
ProxyError,
|
40 |
+
ReadTimeout,
|
41 |
+
RetryError,
|
42 |
+
SSLError,
|
43 |
+
)
|
44 |
+
from .models import Response
|
45 |
+
from .structures import CaseInsensitiveDict
|
46 |
+
from .utils import (
|
47 |
+
DEFAULT_CA_BUNDLE_PATH,
|
48 |
+
extract_zipped_paths,
|
49 |
+
get_auth_from_url,
|
50 |
+
get_encoding_from_headers,
|
51 |
+
prepend_scheme_if_needed,
|
52 |
+
select_proxy,
|
53 |
+
urldefragauth,
|
54 |
+
)
|
55 |
+
|
56 |
+
try:
|
57 |
+
from urllib3.contrib.socks import SOCKSProxyManager
|
58 |
+
except ImportError:
|
59 |
+
|
60 |
+
def SOCKSProxyManager(*args, **kwargs):
|
61 |
+
raise InvalidSchema("Missing dependencies for SOCKS support.")
|
62 |
+
|
63 |
+
|
64 |
+
DEFAULT_POOLBLOCK = False
|
65 |
+
DEFAULT_POOLSIZE = 10
|
66 |
+
DEFAULT_RETRIES = 0
|
67 |
+
DEFAULT_POOL_TIMEOUT = None
|
68 |
+
|
69 |
+
|
70 |
+
class BaseAdapter:
|
71 |
+
"""The Base Transport Adapter"""
|
72 |
+
|
73 |
+
def __init__(self):
|
74 |
+
super().__init__()
|
75 |
+
|
76 |
+
def send(
|
77 |
+
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
|
78 |
+
):
|
79 |
+
"""Sends PreparedRequest object. Returns Response object.
|
80 |
+
|
81 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
82 |
+
:param stream: (optional) Whether to stream the request content.
|
83 |
+
:param timeout: (optional) How long to wait for the server to send
|
84 |
+
data before giving up, as a float, or a :ref:`(connect timeout,
|
85 |
+
read timeout) <timeouts>` tuple.
|
86 |
+
:type timeout: float or tuple
|
87 |
+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
|
88 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
89 |
+
to a CA bundle to use
|
90 |
+
:param cert: (optional) Any user-provided SSL certificate to be trusted.
|
91 |
+
:param proxies: (optional) The proxies dictionary to apply to the request.
|
92 |
+
"""
|
93 |
+
raise NotImplementedError
|
94 |
+
|
95 |
+
def close(self):
|
96 |
+
"""Cleans up adapter specific items."""
|
97 |
+
raise NotImplementedError
|
98 |
+
|
99 |
+
|
100 |
+
class HTTPAdapter(BaseAdapter):
|
101 |
+
"""The built-in HTTP Adapter for urllib3.
|
102 |
+
|
103 |
+
Provides a general-case interface for Requests sessions to contact HTTP and
|
104 |
+
HTTPS urls by implementing the Transport Adapter interface. This class will
|
105 |
+
usually be created by the :class:`Session <Session>` class under the
|
106 |
+
covers.
|
107 |
+
|
108 |
+
:param pool_connections: The number of urllib3 connection pools to cache.
|
109 |
+
:param pool_maxsize: The maximum number of connections to save in the pool.
|
110 |
+
:param max_retries: The maximum number of retries each connection
|
111 |
+
should attempt. Note, this applies only to failed DNS lookups, socket
|
112 |
+
connections and connection timeouts, never to requests where data has
|
113 |
+
made it to the server. By default, Requests does not retry failed
|
114 |
+
connections. If you need granular control over the conditions under
|
115 |
+
which we retry a request, import urllib3's ``Retry`` class and pass
|
116 |
+
that instead.
|
117 |
+
:param pool_block: Whether the connection pool should block for connections.
|
118 |
+
|
119 |
+
Usage::
|
120 |
+
|
121 |
+
>>> import requests
|
122 |
+
>>> s = requests.Session()
|
123 |
+
>>> a = requests.adapters.HTTPAdapter(max_retries=3)
|
124 |
+
>>> s.mount('http://', a)
|
125 |
+
"""
|
126 |
+
|
127 |
+
__attrs__ = [
|
128 |
+
"max_retries",
|
129 |
+
"config",
|
130 |
+
"_pool_connections",
|
131 |
+
"_pool_maxsize",
|
132 |
+
"_pool_block",
|
133 |
+
]
|
134 |
+
|
135 |
+
def __init__(
|
136 |
+
self,
|
137 |
+
pool_connections=DEFAULT_POOLSIZE,
|
138 |
+
pool_maxsize=DEFAULT_POOLSIZE,
|
139 |
+
max_retries=DEFAULT_RETRIES,
|
140 |
+
pool_block=DEFAULT_POOLBLOCK,
|
141 |
+
):
|
142 |
+
if max_retries == DEFAULT_RETRIES:
|
143 |
+
self.max_retries = Retry(0, read=False)
|
144 |
+
else:
|
145 |
+
self.max_retries = Retry.from_int(max_retries)
|
146 |
+
self.config = {}
|
147 |
+
self.proxy_manager = {}
|
148 |
+
|
149 |
+
super().__init__()
|
150 |
+
|
151 |
+
self._pool_connections = pool_connections
|
152 |
+
self._pool_maxsize = pool_maxsize
|
153 |
+
self._pool_block = pool_block
|
154 |
+
|
155 |
+
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
|
156 |
+
|
157 |
+
def __getstate__(self):
|
158 |
+
return {attr: getattr(self, attr, None) for attr in self.__attrs__}
|
159 |
+
|
160 |
+
def __setstate__(self, state):
|
161 |
+
# Can't handle by adding 'proxy_manager' to self.__attrs__ because
|
162 |
+
# self.poolmanager uses a lambda function, which isn't pickleable.
|
163 |
+
self.proxy_manager = {}
|
164 |
+
self.config = {}
|
165 |
+
|
166 |
+
for attr, value in state.items():
|
167 |
+
setattr(self, attr, value)
|
168 |
+
|
169 |
+
self.init_poolmanager(
|
170 |
+
self._pool_connections, self._pool_maxsize, block=self._pool_block
|
171 |
+
)
|
172 |
+
|
173 |
+
def init_poolmanager(
|
174 |
+
self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs
|
175 |
+
):
|
176 |
+
"""Initializes a urllib3 PoolManager.
|
177 |
+
|
178 |
+
This method should not be called from user code, and is only
|
179 |
+
exposed for use when subclassing the
|
180 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
181 |
+
|
182 |
+
:param connections: The number of urllib3 connection pools to cache.
|
183 |
+
:param maxsize: The maximum number of connections to save in the pool.
|
184 |
+
:param block: Block when no free connections are available.
|
185 |
+
:param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
|
186 |
+
"""
|
187 |
+
# save these values for pickling
|
188 |
+
self._pool_connections = connections
|
189 |
+
self._pool_maxsize = maxsize
|
190 |
+
self._pool_block = block
|
191 |
+
|
192 |
+
self.poolmanager = PoolManager(
|
193 |
+
num_pools=connections,
|
194 |
+
maxsize=maxsize,
|
195 |
+
block=block,
|
196 |
+
**pool_kwargs,
|
197 |
+
)
|
198 |
+
|
199 |
+
def proxy_manager_for(self, proxy, **proxy_kwargs):
|
200 |
+
"""Return urllib3 ProxyManager for the given proxy.
|
201 |
+
|
202 |
+
This method should not be called from user code, and is only
|
203 |
+
exposed for use when subclassing the
|
204 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
205 |
+
|
206 |
+
:param proxy: The proxy to return a urllib3 ProxyManager for.
|
207 |
+
:param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
|
208 |
+
:returns: ProxyManager
|
209 |
+
:rtype: urllib3.ProxyManager
|
210 |
+
"""
|
211 |
+
if proxy in self.proxy_manager:
|
212 |
+
manager = self.proxy_manager[proxy]
|
213 |
+
elif proxy.lower().startswith("socks"):
|
214 |
+
username, password = get_auth_from_url(proxy)
|
215 |
+
manager = self.proxy_manager[proxy] = SOCKSProxyManager(
|
216 |
+
proxy,
|
217 |
+
username=username,
|
218 |
+
password=password,
|
219 |
+
num_pools=self._pool_connections,
|
220 |
+
maxsize=self._pool_maxsize,
|
221 |
+
block=self._pool_block,
|
222 |
+
**proxy_kwargs,
|
223 |
+
)
|
224 |
+
else:
|
225 |
+
proxy_headers = self.proxy_headers(proxy)
|
226 |
+
manager = self.proxy_manager[proxy] = proxy_from_url(
|
227 |
+
proxy,
|
228 |
+
proxy_headers=proxy_headers,
|
229 |
+
num_pools=self._pool_connections,
|
230 |
+
maxsize=self._pool_maxsize,
|
231 |
+
block=self._pool_block,
|
232 |
+
**proxy_kwargs,
|
233 |
+
)
|
234 |
+
|
235 |
+
return manager
|
236 |
+
|
237 |
+
def cert_verify(self, conn, url, verify, cert):
|
238 |
+
"""Verify a SSL certificate. This method should not be called from user
|
239 |
+
code, and is only exposed for use when subclassing the
|
240 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
241 |
+
|
242 |
+
:param conn: The urllib3 connection object associated with the cert.
|
243 |
+
:param url: The requested URL.
|
244 |
+
:param verify: Either a boolean, in which case it controls whether we verify
|
245 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
246 |
+
to a CA bundle to use
|
247 |
+
:param cert: The SSL certificate to verify.
|
248 |
+
"""
|
249 |
+
if url.lower().startswith("https") and verify:
|
250 |
+
|
251 |
+
cert_loc = None
|
252 |
+
|
253 |
+
# Allow self-specified cert location.
|
254 |
+
if verify is not True:
|
255 |
+
cert_loc = verify
|
256 |
+
|
257 |
+
if not cert_loc:
|
258 |
+
cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
|
259 |
+
|
260 |
+
if not cert_loc or not os.path.exists(cert_loc):
|
261 |
+
raise OSError(
|
262 |
+
f"Could not find a suitable TLS CA certificate bundle, "
|
263 |
+
f"invalid path: {cert_loc}"
|
264 |
+
)
|
265 |
+
|
266 |
+
conn.cert_reqs = "CERT_REQUIRED"
|
267 |
+
|
268 |
+
if not os.path.isdir(cert_loc):
|
269 |
+
conn.ca_certs = cert_loc
|
270 |
+
else:
|
271 |
+
conn.ca_cert_dir = cert_loc
|
272 |
+
else:
|
273 |
+
conn.cert_reqs = "CERT_NONE"
|
274 |
+
conn.ca_certs = None
|
275 |
+
conn.ca_cert_dir = None
|
276 |
+
|
277 |
+
if cert:
|
278 |
+
if not isinstance(cert, basestring):
|
279 |
+
conn.cert_file = cert[0]
|
280 |
+
conn.key_file = cert[1]
|
281 |
+
else:
|
282 |
+
conn.cert_file = cert
|
283 |
+
conn.key_file = None
|
284 |
+
if conn.cert_file and not os.path.exists(conn.cert_file):
|
285 |
+
raise OSError(
|
286 |
+
f"Could not find the TLS certificate file, "
|
287 |
+
f"invalid path: {conn.cert_file}"
|
288 |
+
)
|
289 |
+
if conn.key_file and not os.path.exists(conn.key_file):
|
290 |
+
raise OSError(
|
291 |
+
f"Could not find the TLS key file, invalid path: {conn.key_file}"
|
292 |
+
)
|
293 |
+
|
294 |
+
def build_response(self, req, resp):
|
295 |
+
"""Builds a :class:`Response <requests.Response>` object from a urllib3
|
296 |
+
response. This should not be called from user code, and is only exposed
|
297 |
+
for use when subclassing the
|
298 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
|
299 |
+
|
300 |
+
:param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
|
301 |
+
:param resp: The urllib3 response object.
|
302 |
+
:rtype: requests.Response
|
303 |
+
"""
|
304 |
+
response = Response()
|
305 |
+
|
306 |
+
# Fallback to None if there's no status_code, for whatever reason.
|
307 |
+
response.status_code = getattr(resp, "status", None)
|
308 |
+
|
309 |
+
# Make headers case-insensitive.
|
310 |
+
response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))
|
311 |
+
|
312 |
+
# Set encoding.
|
313 |
+
response.encoding = get_encoding_from_headers(response.headers)
|
314 |
+
response.raw = resp
|
315 |
+
response.reason = response.raw.reason
|
316 |
+
|
317 |
+
if isinstance(req.url, bytes):
|
318 |
+
response.url = req.url.decode("utf-8")
|
319 |
+
else:
|
320 |
+
response.url = req.url
|
321 |
+
|
322 |
+
# Add new cookies from the server.
|
323 |
+
extract_cookies_to_jar(response.cookies, req, resp)
|
324 |
+
|
325 |
+
# Give the Response some context.
|
326 |
+
response.request = req
|
327 |
+
response.connection = self
|
328 |
+
|
329 |
+
return response
|
330 |
+
|
331 |
+
def get_connection(self, url, proxies=None):
|
332 |
+
"""Returns a urllib3 connection for the given URL. This should not be
|
333 |
+
called from user code, and is only exposed for use when subclassing the
|
334 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
335 |
+
|
336 |
+
:param url: The URL to connect to.
|
337 |
+
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
|
338 |
+
:rtype: urllib3.ConnectionPool
|
339 |
+
"""
|
340 |
+
proxy = select_proxy(url, proxies)
|
341 |
+
|
342 |
+
if proxy:
|
343 |
+
proxy = prepend_scheme_if_needed(proxy, "http")
|
344 |
+
proxy_url = parse_url(proxy)
|
345 |
+
if not proxy_url.host:
|
346 |
+
raise InvalidProxyURL(
|
347 |
+
"Please check proxy URL. It is malformed "
|
348 |
+
"and could be missing the host."
|
349 |
+
)
|
350 |
+
proxy_manager = self.proxy_manager_for(proxy)
|
351 |
+
conn = proxy_manager.connection_from_url(url)
|
352 |
+
else:
|
353 |
+
# Only scheme should be lower case
|
354 |
+
parsed = urlparse(url)
|
355 |
+
url = parsed.geturl()
|
356 |
+
conn = self.poolmanager.connection_from_url(url)
|
357 |
+
|
358 |
+
return conn
|
359 |
+
|
360 |
+
def close(self):
|
361 |
+
"""Disposes of any internal state.
|
362 |
+
|
363 |
+
Currently, this closes the PoolManager and any active ProxyManager,
|
364 |
+
which closes any pooled connections.
|
365 |
+
"""
|
366 |
+
self.poolmanager.clear()
|
367 |
+
for proxy in self.proxy_manager.values():
|
368 |
+
proxy.clear()
|
369 |
+
|
370 |
+
def request_url(self, request, proxies):
|
371 |
+
"""Obtain the url to use when making the final request.
|
372 |
+
|
373 |
+
If the message is being sent through a HTTP proxy, the full URL has to
|
374 |
+
be used. Otherwise, we should only use the path portion of the URL.
|
375 |
+
|
376 |
+
This should not be called from user code, and is only exposed for use
|
377 |
+
when subclassing the
|
378 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
379 |
+
|
380 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
381 |
+
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
|
382 |
+
:rtype: str
|
383 |
+
"""
|
384 |
+
proxy = select_proxy(request.url, proxies)
|
385 |
+
scheme = urlparse(request.url).scheme
|
386 |
+
|
387 |
+
is_proxied_http_request = proxy and scheme != "https"
|
388 |
+
using_socks_proxy = False
|
389 |
+
if proxy:
|
390 |
+
proxy_scheme = urlparse(proxy).scheme.lower()
|
391 |
+
using_socks_proxy = proxy_scheme.startswith("socks")
|
392 |
+
|
393 |
+
url = request.path_url
|
394 |
+
if is_proxied_http_request and not using_socks_proxy:
|
395 |
+
url = urldefragauth(request.url)
|
396 |
+
|
397 |
+
return url
|
398 |
+
|
399 |
+
def add_headers(self, request, **kwargs):
|
400 |
+
"""Add any headers needed by the connection. As of v2.0 this does
|
401 |
+
nothing by default, but is left for overriding by users that subclass
|
402 |
+
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
403 |
+
|
404 |
+
This should not be called from user code, and is only exposed for use
|
405 |
+
when subclassing the
|
406 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
407 |
+
|
408 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
|
409 |
+
:param kwargs: The keyword arguments from the call to send().
|
410 |
+
"""
|
411 |
+
pass
|
412 |
+
|
413 |
+
def proxy_headers(self, proxy):
|
414 |
+
"""Returns a dictionary of the headers to add to any request sent
|
415 |
+
through a proxy. This works with urllib3 magic to ensure that they are
|
416 |
+
correctly sent to the proxy, rather than in a tunnelled request if
|
417 |
+
CONNECT is being used.
|
418 |
+
|
419 |
+
This should not be called from user code, and is only exposed for use
|
420 |
+
when subclassing the
|
421 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
422 |
+
|
423 |
+
:param proxy: The url of the proxy being used for this request.
|
424 |
+
:rtype: dict
|
425 |
+
"""
|
426 |
+
headers = {}
|
427 |
+
username, password = get_auth_from_url(proxy)
|
428 |
+
|
429 |
+
if username:
|
430 |
+
headers["Proxy-Authorization"] = _basic_auth_str(username, password)
|
431 |
+
|
432 |
+
return headers
|
433 |
+
|
434 |
+
def send(
|
435 |
+
self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
|
436 |
+
):
|
437 |
+
"""Sends PreparedRequest object. Returns Response object.
|
438 |
+
|
439 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
440 |
+
:param stream: (optional) Whether to stream the request content.
|
441 |
+
:param timeout: (optional) How long to wait for the server to send
|
442 |
+
data before giving up, as a float, or a :ref:`(connect timeout,
|
443 |
+
read timeout) <timeouts>` tuple.
|
444 |
+
:type timeout: float or tuple or urllib3 Timeout object
|
445 |
+
:param verify: (optional) Either a boolean, in which case it controls whether
|
446 |
+
we verify the server's TLS certificate, or a string, in which case it
|
447 |
+
must be a path to a CA bundle to use
|
448 |
+
:param cert: (optional) Any user-provided SSL certificate to be trusted.
|
449 |
+
:param proxies: (optional) The proxies dictionary to apply to the request.
|
450 |
+
:rtype: requests.Response
|
451 |
+
"""
|
452 |
+
|
453 |
+
try:
|
454 |
+
conn = self.get_connection(request.url, proxies)
|
455 |
+
except LocationValueError as e:
|
456 |
+
raise InvalidURL(e, request=request)
|
457 |
+
|
458 |
+
self.cert_verify(conn, request.url, verify, cert)
|
459 |
+
url = self.request_url(request, proxies)
|
460 |
+
self.add_headers(
|
461 |
+
request,
|
462 |
+
stream=stream,
|
463 |
+
timeout=timeout,
|
464 |
+
verify=verify,
|
465 |
+
cert=cert,
|
466 |
+
proxies=proxies,
|
467 |
+
)
|
468 |
+
|
469 |
+
chunked = not (request.body is None or "Content-Length" in request.headers)
|
470 |
+
|
471 |
+
if isinstance(timeout, tuple):
|
472 |
+
try:
|
473 |
+
connect, read = timeout
|
474 |
+
timeout = TimeoutSauce(connect=connect, read=read)
|
475 |
+
except ValueError:
|
476 |
+
raise ValueError(
|
477 |
+
f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
|
478 |
+
f"or a single float to set both timeouts to the same value."
|
479 |
+
)
|
480 |
+
elif isinstance(timeout, TimeoutSauce):
|
481 |
+
pass
|
482 |
+
else:
|
483 |
+
timeout = TimeoutSauce(connect=timeout, read=timeout)
|
484 |
+
|
485 |
+
try:
|
486 |
+
resp = conn.urlopen(
|
487 |
+
method=request.method,
|
488 |
+
url=url,
|
489 |
+
body=request.body,
|
490 |
+
headers=request.headers,
|
491 |
+
redirect=False,
|
492 |
+
assert_same_host=False,
|
493 |
+
preload_content=False,
|
494 |
+
decode_content=False,
|
495 |
+
retries=self.max_retries,
|
496 |
+
timeout=timeout,
|
497 |
+
chunked=chunked,
|
498 |
+
)
|
499 |
+
|
500 |
+
except (ProtocolError, OSError) as err:
|
501 |
+
raise ConnectionError(err, request=request)
|
502 |
+
|
503 |
+
except MaxRetryError as e:
|
504 |
+
if isinstance(e.reason, ConnectTimeoutError):
|
505 |
+
# TODO: Remove this in 3.0.0: see #2811
|
506 |
+
if not isinstance(e.reason, NewConnectionError):
|
507 |
+
raise ConnectTimeout(e, request=request)
|
508 |
+
|
509 |
+
if isinstance(e.reason, ResponseError):
|
510 |
+
raise RetryError(e, request=request)
|
511 |
+
|
512 |
+
if isinstance(e.reason, _ProxyError):
|
513 |
+
raise ProxyError(e, request=request)
|
514 |
+
|
515 |
+
if isinstance(e.reason, _SSLError):
|
516 |
+
# This branch is for urllib3 v1.22 and later.
|
517 |
+
raise SSLError(e, request=request)
|
518 |
+
|
519 |
+
raise ConnectionError(e, request=request)
|
520 |
+
|
521 |
+
except ClosedPoolError as e:
|
522 |
+
raise ConnectionError(e, request=request)
|
523 |
+
|
524 |
+
except _ProxyError as e:
|
525 |
+
raise ProxyError(e)
|
526 |
+
|
527 |
+
except (_SSLError, _HTTPError) as e:
|
528 |
+
if isinstance(e, _SSLError):
|
529 |
+
# This branch is for urllib3 versions earlier than v1.22
|
530 |
+
raise SSLError(e, request=request)
|
531 |
+
elif isinstance(e, ReadTimeoutError):
|
532 |
+
raise ReadTimeout(e, request=request)
|
533 |
+
elif isinstance(e, _InvalidHeader):
|
534 |
+
raise InvalidHeader(e, request=request)
|
535 |
+
else:
|
536 |
+
raise
|
537 |
+
|
538 |
+
return self.build_response(request, resp)
|
llmeval-env/lib/python3.10/site-packages/requests/api.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.api
|
3 |
+
~~~~~~~~~~~~
|
4 |
+
|
5 |
+
This module implements the Requests API.
|
6 |
+
|
7 |
+
:copyright: (c) 2012 by Kenneth Reitz.
|
8 |
+
:license: Apache2, see LICENSE for more details.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from . import sessions
|
12 |
+
|
13 |
+
|
14 |
+
def request(method, url, **kwargs):
|
15 |
+
"""Constructs and sends a :class:`Request <Request>`.
|
16 |
+
|
17 |
+
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
|
18 |
+
:param url: URL for the new :class:`Request` object.
|
19 |
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
20 |
+
in the query string for the :class:`Request`.
|
21 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
22 |
+
object to send in the body of the :class:`Request`.
|
23 |
+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
|
24 |
+
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
|
25 |
+
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
|
26 |
+
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
|
27 |
+
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
|
28 |
+
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
|
29 |
+
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
|
30 |
+
to add for the file.
|
31 |
+
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
|
32 |
+
:param timeout: (optional) How many seconds to wait for the server to send data
|
33 |
+
before giving up, as a float, or a :ref:`(connect timeout, read
|
34 |
+
timeout) <timeouts>` tuple.
|
35 |
+
:type timeout: float or tuple
|
36 |
+
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
|
37 |
+
:type allow_redirects: bool
|
38 |
+
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
|
39 |
+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
|
40 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
41 |
+
to a CA bundle to use. Defaults to ``True``.
|
42 |
+
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
|
43 |
+
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
|
44 |
+
:return: :class:`Response <Response>` object
|
45 |
+
:rtype: requests.Response
|
46 |
+
|
47 |
+
Usage::
|
48 |
+
|
49 |
+
>>> import requests
|
50 |
+
>>> req = requests.request('GET', 'https://httpbin.org/get')
|
51 |
+
>>> req
|
52 |
+
<Response [200]>
|
53 |
+
"""
|
54 |
+
|
55 |
+
# By using the 'with' statement we are sure the session is closed, thus we
|
56 |
+
# avoid leaving sockets open which can trigger a ResourceWarning in some
|
57 |
+
# cases, and look like a memory leak in others.
|
58 |
+
with sessions.Session() as session:
|
59 |
+
return session.request(method=method, url=url, **kwargs)
|
60 |
+
|
61 |
+
|
62 |
+
def get(url, params=None, **kwargs):
|
63 |
+
r"""Sends a GET request.
|
64 |
+
|
65 |
+
:param url: URL for the new :class:`Request` object.
|
66 |
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
67 |
+
in the query string for the :class:`Request`.
|
68 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
69 |
+
:return: :class:`Response <Response>` object
|
70 |
+
:rtype: requests.Response
|
71 |
+
"""
|
72 |
+
|
73 |
+
return request("get", url, params=params, **kwargs)
|
74 |
+
|
75 |
+
|
76 |
+
def options(url, **kwargs):
|
77 |
+
r"""Sends an OPTIONS request.
|
78 |
+
|
79 |
+
:param url: URL for the new :class:`Request` object.
|
80 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
81 |
+
:return: :class:`Response <Response>` object
|
82 |
+
:rtype: requests.Response
|
83 |
+
"""
|
84 |
+
|
85 |
+
return request("options", url, **kwargs)
|
86 |
+
|
87 |
+
|
88 |
+
def head(url, **kwargs):
|
89 |
+
r"""Sends a HEAD request.
|
90 |
+
|
91 |
+
:param url: URL for the new :class:`Request` object.
|
92 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes. If
|
93 |
+
`allow_redirects` is not provided, it will be set to `False` (as
|
94 |
+
opposed to the default :meth:`request` behavior).
|
95 |
+
:return: :class:`Response <Response>` object
|
96 |
+
:rtype: requests.Response
|
97 |
+
"""
|
98 |
+
|
99 |
+
kwargs.setdefault("allow_redirects", False)
|
100 |
+
return request("head", url, **kwargs)
|
101 |
+
|
102 |
+
|
103 |
+
def post(url, data=None, json=None, **kwargs):
|
104 |
+
r"""Sends a POST request.
|
105 |
+
|
106 |
+
:param url: URL for the new :class:`Request` object.
|
107 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
108 |
+
object to send in the body of the :class:`Request`.
|
109 |
+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
|
110 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
111 |
+
:return: :class:`Response <Response>` object
|
112 |
+
:rtype: requests.Response
|
113 |
+
"""
|
114 |
+
|
115 |
+
return request("post", url, data=data, json=json, **kwargs)
|
116 |
+
|
117 |
+
|
118 |
+
def put(url, data=None, **kwargs):
|
119 |
+
r"""Sends a PUT request.
|
120 |
+
|
121 |
+
:param url: URL for the new :class:`Request` object.
|
122 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
123 |
+
object to send in the body of the :class:`Request`.
|
124 |
+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
|
125 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
126 |
+
:return: :class:`Response <Response>` object
|
127 |
+
:rtype: requests.Response
|
128 |
+
"""
|
129 |
+
|
130 |
+
return request("put", url, data=data, **kwargs)
|
131 |
+
|
132 |
+
|
133 |
+
def patch(url, data=None, **kwargs):
|
134 |
+
r"""Sends a PATCH request.
|
135 |
+
|
136 |
+
:param url: URL for the new :class:`Request` object.
|
137 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
138 |
+
object to send in the body of the :class:`Request`.
|
139 |
+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
|
140 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
141 |
+
:return: :class:`Response <Response>` object
|
142 |
+
:rtype: requests.Response
|
143 |
+
"""
|
144 |
+
|
145 |
+
return request("patch", url, data=data, **kwargs)
|
146 |
+
|
147 |
+
|
148 |
+
def delete(url, **kwargs):
|
149 |
+
r"""Sends a DELETE request.
|
150 |
+
|
151 |
+
:param url: URL for the new :class:`Request` object.
|
152 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
153 |
+
:return: :class:`Response <Response>` object
|
154 |
+
:rtype: requests.Response
|
155 |
+
"""
|
156 |
+
|
157 |
+
return request("delete", url, **kwargs)
|
llmeval-env/lib/python3.10/site-packages/requests/auth.py
ADDED
@@ -0,0 +1,315 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.auth
|
3 |
+
~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
This module contains the authentication handlers for Requests.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import hashlib
|
9 |
+
import os
|
10 |
+
import re
|
11 |
+
import threading
|
12 |
+
import time
|
13 |
+
import warnings
|
14 |
+
from base64 import b64encode
|
15 |
+
|
16 |
+
from ._internal_utils import to_native_string
|
17 |
+
from .compat import basestring, str, urlparse
|
18 |
+
from .cookies import extract_cookies_to_jar
|
19 |
+
from .utils import parse_dict_header
|
20 |
+
|
21 |
+
CONTENT_TYPE_FORM_URLENCODED = "application/x-www-form-urlencoded"
|
22 |
+
CONTENT_TYPE_MULTI_PART = "multipart/form-data"
|
23 |
+
|
24 |
+
|
25 |
+
def _basic_auth_str(username, password):
|
26 |
+
"""Returns a Basic Auth string."""
|
27 |
+
|
28 |
+
# "I want us to put a big-ol' comment on top of it that
|
29 |
+
# says that this behaviour is dumb but we need to preserve
|
30 |
+
# it because people are relying on it."
|
31 |
+
# - Lukasa
|
32 |
+
#
|
33 |
+
# These are here solely to maintain backwards compatibility
|
34 |
+
# for things like ints. This will be removed in 3.0.0.
|
35 |
+
if not isinstance(username, basestring):
|
36 |
+
warnings.warn(
|
37 |
+
"Non-string usernames will no longer be supported in Requests "
|
38 |
+
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
39 |
+
"a string or bytes object in the near future to avoid "
|
40 |
+
"problems.".format(username),
|
41 |
+
category=DeprecationWarning,
|
42 |
+
)
|
43 |
+
username = str(username)
|
44 |
+
|
45 |
+
if not isinstance(password, basestring):
|
46 |
+
warnings.warn(
|
47 |
+
"Non-string passwords will no longer be supported in Requests "
|
48 |
+
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
49 |
+
"a string or bytes object in the near future to avoid "
|
50 |
+
"problems.".format(type(password)),
|
51 |
+
category=DeprecationWarning,
|
52 |
+
)
|
53 |
+
password = str(password)
|
54 |
+
# -- End Removal --
|
55 |
+
|
56 |
+
if isinstance(username, str):
|
57 |
+
username = username.encode("latin1")
|
58 |
+
|
59 |
+
if isinstance(password, str):
|
60 |
+
password = password.encode("latin1")
|
61 |
+
|
62 |
+
authstr = "Basic " + to_native_string(
|
63 |
+
b64encode(b":".join((username, password))).strip()
|
64 |
+
)
|
65 |
+
|
66 |
+
return authstr
|
67 |
+
|
68 |
+
|
69 |
+
class AuthBase:
|
70 |
+
"""Base class that all auth implementations derive from"""
|
71 |
+
|
72 |
+
def __call__(self, r):
|
73 |
+
raise NotImplementedError("Auth hooks must be callable.")
|
74 |
+
|
75 |
+
|
76 |
+
class HTTPBasicAuth(AuthBase):
|
77 |
+
"""Attaches HTTP Basic Authentication to the given Request object."""
|
78 |
+
|
79 |
+
def __init__(self, username, password):
|
80 |
+
self.username = username
|
81 |
+
self.password = password
|
82 |
+
|
83 |
+
def __eq__(self, other):
|
84 |
+
return all(
|
85 |
+
[
|
86 |
+
self.username == getattr(other, "username", None),
|
87 |
+
self.password == getattr(other, "password", None),
|
88 |
+
]
|
89 |
+
)
|
90 |
+
|
91 |
+
def __ne__(self, other):
|
92 |
+
return not self == other
|
93 |
+
|
94 |
+
def __call__(self, r):
|
95 |
+
r.headers["Authorization"] = _basic_auth_str(self.username, self.password)
|
96 |
+
return r
|
97 |
+
|
98 |
+
|
99 |
+
class HTTPProxyAuth(HTTPBasicAuth):
|
100 |
+
"""Attaches HTTP Proxy Authentication to a given Request object."""
|
101 |
+
|
102 |
+
def __call__(self, r):
|
103 |
+
r.headers["Proxy-Authorization"] = _basic_auth_str(self.username, self.password)
|
104 |
+
return r
|
105 |
+
|
106 |
+
|
107 |
+
class HTTPDigestAuth(AuthBase):
|
108 |
+
"""Attaches HTTP Digest Authentication to the given Request object."""
|
109 |
+
|
110 |
+
def __init__(self, username, password):
|
111 |
+
self.username = username
|
112 |
+
self.password = password
|
113 |
+
# Keep state in per-thread local storage
|
114 |
+
self._thread_local = threading.local()
|
115 |
+
|
116 |
+
def init_per_thread_state(self):
|
117 |
+
# Ensure state is initialized just once per-thread
|
118 |
+
if not hasattr(self._thread_local, "init"):
|
119 |
+
self._thread_local.init = True
|
120 |
+
self._thread_local.last_nonce = ""
|
121 |
+
self._thread_local.nonce_count = 0
|
122 |
+
self._thread_local.chal = {}
|
123 |
+
self._thread_local.pos = None
|
124 |
+
self._thread_local.num_401_calls = None
|
125 |
+
|
126 |
+
def build_digest_header(self, method, url):
|
127 |
+
"""
|
128 |
+
:rtype: str
|
129 |
+
"""
|
130 |
+
|
131 |
+
realm = self._thread_local.chal["realm"]
|
132 |
+
nonce = self._thread_local.chal["nonce"]
|
133 |
+
qop = self._thread_local.chal.get("qop")
|
134 |
+
algorithm = self._thread_local.chal.get("algorithm")
|
135 |
+
opaque = self._thread_local.chal.get("opaque")
|
136 |
+
hash_utf8 = None
|
137 |
+
|
138 |
+
if algorithm is None:
|
139 |
+
_algorithm = "MD5"
|
140 |
+
else:
|
141 |
+
_algorithm = algorithm.upper()
|
142 |
+
# lambdas assume digest modules are imported at the top level
|
143 |
+
if _algorithm == "MD5" or _algorithm == "MD5-SESS":
|
144 |
+
|
145 |
+
def md5_utf8(x):
|
146 |
+
if isinstance(x, str):
|
147 |
+
x = x.encode("utf-8")
|
148 |
+
return hashlib.md5(x).hexdigest()
|
149 |
+
|
150 |
+
hash_utf8 = md5_utf8
|
151 |
+
elif _algorithm == "SHA":
|
152 |
+
|
153 |
+
def sha_utf8(x):
|
154 |
+
if isinstance(x, str):
|
155 |
+
x = x.encode("utf-8")
|
156 |
+
return hashlib.sha1(x).hexdigest()
|
157 |
+
|
158 |
+
hash_utf8 = sha_utf8
|
159 |
+
elif _algorithm == "SHA-256":
|
160 |
+
|
161 |
+
def sha256_utf8(x):
|
162 |
+
if isinstance(x, str):
|
163 |
+
x = x.encode("utf-8")
|
164 |
+
return hashlib.sha256(x).hexdigest()
|
165 |
+
|
166 |
+
hash_utf8 = sha256_utf8
|
167 |
+
elif _algorithm == "SHA-512":
|
168 |
+
|
169 |
+
def sha512_utf8(x):
|
170 |
+
if isinstance(x, str):
|
171 |
+
x = x.encode("utf-8")
|
172 |
+
return hashlib.sha512(x).hexdigest()
|
173 |
+
|
174 |
+
hash_utf8 = sha512_utf8
|
175 |
+
|
176 |
+
KD = lambda s, d: hash_utf8(f"{s}:{d}") # noqa:E731
|
177 |
+
|
178 |
+
if hash_utf8 is None:
|
179 |
+
return None
|
180 |
+
|
181 |
+
# XXX not implemented yet
|
182 |
+
entdig = None
|
183 |
+
p_parsed = urlparse(url)
|
184 |
+
#: path is request-uri defined in RFC 2616 which should not be empty
|
185 |
+
path = p_parsed.path or "/"
|
186 |
+
if p_parsed.query:
|
187 |
+
path += f"?{p_parsed.query}"
|
188 |
+
|
189 |
+
A1 = f"{self.username}:{realm}:{self.password}"
|
190 |
+
A2 = f"{method}:{path}"
|
191 |
+
|
192 |
+
HA1 = hash_utf8(A1)
|
193 |
+
HA2 = hash_utf8(A2)
|
194 |
+
|
195 |
+
if nonce == self._thread_local.last_nonce:
|
196 |
+
self._thread_local.nonce_count += 1
|
197 |
+
else:
|
198 |
+
self._thread_local.nonce_count = 1
|
199 |
+
ncvalue = f"{self._thread_local.nonce_count:08x}"
|
200 |
+
s = str(self._thread_local.nonce_count).encode("utf-8")
|
201 |
+
s += nonce.encode("utf-8")
|
202 |
+
s += time.ctime().encode("utf-8")
|
203 |
+
s += os.urandom(8)
|
204 |
+
|
205 |
+
cnonce = hashlib.sha1(s).hexdigest()[:16]
|
206 |
+
if _algorithm == "MD5-SESS":
|
207 |
+
HA1 = hash_utf8(f"{HA1}:{nonce}:{cnonce}")
|
208 |
+
|
209 |
+
if not qop:
|
210 |
+
respdig = KD(HA1, f"{nonce}:{HA2}")
|
211 |
+
elif qop == "auth" or "auth" in qop.split(","):
|
212 |
+
noncebit = f"{nonce}:{ncvalue}:{cnonce}:auth:{HA2}"
|
213 |
+
respdig = KD(HA1, noncebit)
|
214 |
+
else:
|
215 |
+
# XXX handle auth-int.
|
216 |
+
return None
|
217 |
+
|
218 |
+
self._thread_local.last_nonce = nonce
|
219 |
+
|
220 |
+
# XXX should the partial digests be encoded too?
|
221 |
+
base = (
|
222 |
+
f'username="{self.username}", realm="{realm}", nonce="{nonce}", '
|
223 |
+
f'uri="{path}", response="{respdig}"'
|
224 |
+
)
|
225 |
+
if opaque:
|
226 |
+
base += f', opaque="{opaque}"'
|
227 |
+
if algorithm:
|
228 |
+
base += f', algorithm="{algorithm}"'
|
229 |
+
if entdig:
|
230 |
+
base += f', digest="{entdig}"'
|
231 |
+
if qop:
|
232 |
+
base += f', qop="auth", nc={ncvalue}, cnonce="{cnonce}"'
|
233 |
+
|
234 |
+
return f"Digest {base}"
|
235 |
+
|
236 |
+
def handle_redirect(self, r, **kwargs):
|
237 |
+
"""Reset num_401_calls counter on redirects."""
|
238 |
+
if r.is_redirect:
|
239 |
+
self._thread_local.num_401_calls = 1
|
240 |
+
|
241 |
+
def handle_401(self, r, **kwargs):
|
242 |
+
"""
|
243 |
+
Takes the given response and tries digest-auth, if needed.
|
244 |
+
|
245 |
+
:rtype: requests.Response
|
246 |
+
"""
|
247 |
+
|
248 |
+
# If response is not 4xx, do not auth
|
249 |
+
# See https://github.com/psf/requests/issues/3772
|
250 |
+
if not 400 <= r.status_code < 500:
|
251 |
+
self._thread_local.num_401_calls = 1
|
252 |
+
return r
|
253 |
+
|
254 |
+
if self._thread_local.pos is not None:
|
255 |
+
# Rewind the file position indicator of the body to where
|
256 |
+
# it was to resend the request.
|
257 |
+
r.request.body.seek(self._thread_local.pos)
|
258 |
+
s_auth = r.headers.get("www-authenticate", "")
|
259 |
+
|
260 |
+
if "digest" in s_auth.lower() and self._thread_local.num_401_calls < 2:
|
261 |
+
|
262 |
+
self._thread_local.num_401_calls += 1
|
263 |
+
pat = re.compile(r"digest ", flags=re.IGNORECASE)
|
264 |
+
self._thread_local.chal = parse_dict_header(pat.sub("", s_auth, count=1))
|
265 |
+
|
266 |
+
# Consume content and release the original connection
|
267 |
+
# to allow our new request to reuse the same one.
|
268 |
+
r.content
|
269 |
+
r.close()
|
270 |
+
prep = r.request.copy()
|
271 |
+
extract_cookies_to_jar(prep._cookies, r.request, r.raw)
|
272 |
+
prep.prepare_cookies(prep._cookies)
|
273 |
+
|
274 |
+
prep.headers["Authorization"] = self.build_digest_header(
|
275 |
+
prep.method, prep.url
|
276 |
+
)
|
277 |
+
_r = r.connection.send(prep, **kwargs)
|
278 |
+
_r.history.append(r)
|
279 |
+
_r.request = prep
|
280 |
+
|
281 |
+
return _r
|
282 |
+
|
283 |
+
self._thread_local.num_401_calls = 1
|
284 |
+
return r
|
285 |
+
|
286 |
+
def __call__(self, r):
|
287 |
+
# Initialize per-thread state, if needed
|
288 |
+
self.init_per_thread_state()
|
289 |
+
# If we have a saved nonce, skip the 401
|
290 |
+
if self._thread_local.last_nonce:
|
291 |
+
r.headers["Authorization"] = self.build_digest_header(r.method, r.url)
|
292 |
+
try:
|
293 |
+
self._thread_local.pos = r.body.tell()
|
294 |
+
except AttributeError:
|
295 |
+
# In the case of HTTPDigestAuth being reused and the body of
|
296 |
+
# the previous request was a file-like object, pos has the
|
297 |
+
# file position of the previous body. Ensure it's set to
|
298 |
+
# None.
|
299 |
+
self._thread_local.pos = None
|
300 |
+
r.register_hook("response", self.handle_401)
|
301 |
+
r.register_hook("response", self.handle_redirect)
|
302 |
+
self._thread_local.num_401_calls = 1
|
303 |
+
|
304 |
+
return r
|
305 |
+
|
306 |
+
def __eq__(self, other):
|
307 |
+
return all(
|
308 |
+
[
|
309 |
+
self.username == getattr(other, "username", None),
|
310 |
+
self.password == getattr(other, "password", None),
|
311 |
+
]
|
312 |
+
)
|
313 |
+
|
314 |
+
def __ne__(self, other):
|
315 |
+
return not self == other
|
llmeval-env/lib/python3.10/site-packages/requests/certs.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.certs
|
5 |
+
~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module returns the preferred default CA certificate bundle. There is
|
8 |
+
only one — the one from the certifi package.
|
9 |
+
|
10 |
+
If you are packaging Requests, e.g., for a Linux distribution or a managed
|
11 |
+
environment, you can change the definition of where() to return a separately
|
12 |
+
packaged CA bundle.
|
13 |
+
"""
|
14 |
+
from certifi import where
|
15 |
+
|
16 |
+
if __name__ == "__main__":
|
17 |
+
print(where())
|
llmeval-env/lib/python3.10/site-packages/requests/compat.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.compat
|
3 |
+
~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
This module previously handled import compatibility issues
|
6 |
+
between Python 2 and Python 3. It remains for backwards
|
7 |
+
compatibility until the next major version.
|
8 |
+
"""
|
9 |
+
|
10 |
+
try:
|
11 |
+
import chardet
|
12 |
+
except ImportError:
|
13 |
+
import charset_normalizer as chardet
|
14 |
+
|
15 |
+
import sys
|
16 |
+
|
17 |
+
# -------
|
18 |
+
# Pythons
|
19 |
+
# -------
|
20 |
+
|
21 |
+
# Syntax sugar.
|
22 |
+
_ver = sys.version_info
|
23 |
+
|
24 |
+
#: Python 2.x?
|
25 |
+
is_py2 = _ver[0] == 2
|
26 |
+
|
27 |
+
#: Python 3.x?
|
28 |
+
is_py3 = _ver[0] == 3
|
29 |
+
|
30 |
+
# json/simplejson module import resolution
|
31 |
+
has_simplejson = False
|
32 |
+
try:
|
33 |
+
import simplejson as json
|
34 |
+
|
35 |
+
has_simplejson = True
|
36 |
+
except ImportError:
|
37 |
+
import json
|
38 |
+
|
39 |
+
if has_simplejson:
|
40 |
+
from simplejson import JSONDecodeError
|
41 |
+
else:
|
42 |
+
from json import JSONDecodeError
|
43 |
+
|
44 |
+
# Keep OrderedDict for backwards compatibility.
|
45 |
+
from collections import OrderedDict
|
46 |
+
from collections.abc import Callable, Mapping, MutableMapping
|
47 |
+
from http import cookiejar as cookielib
|
48 |
+
from http.cookies import Morsel
|
49 |
+
from io import StringIO
|
50 |
+
|
51 |
+
# --------------
|
52 |
+
# Legacy Imports
|
53 |
+
# --------------
|
54 |
+
from urllib.parse import (
|
55 |
+
quote,
|
56 |
+
quote_plus,
|
57 |
+
unquote,
|
58 |
+
unquote_plus,
|
59 |
+
urldefrag,
|
60 |
+
urlencode,
|
61 |
+
urljoin,
|
62 |
+
urlparse,
|
63 |
+
urlsplit,
|
64 |
+
urlunparse,
|
65 |
+
)
|
66 |
+
from urllib.request import (
|
67 |
+
getproxies,
|
68 |
+
getproxies_environment,
|
69 |
+
parse_http_list,
|
70 |
+
proxy_bypass,
|
71 |
+
proxy_bypass_environment,
|
72 |
+
)
|
73 |
+
|
74 |
+
builtin_str = str
|
75 |
+
str = str
|
76 |
+
bytes = bytes
|
77 |
+
basestring = (str, bytes)
|
78 |
+
numeric_types = (int, float)
|
79 |
+
integer_types = (int,)
|
llmeval-env/lib/python3.10/site-packages/requests/exceptions.py
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.exceptions
|
3 |
+
~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
This module contains the set of Requests' exceptions.
|
6 |
+
"""
|
7 |
+
from urllib3.exceptions import HTTPError as BaseHTTPError
|
8 |
+
|
9 |
+
from .compat import JSONDecodeError as CompatJSONDecodeError
|
10 |
+
|
11 |
+
|
12 |
+
class RequestException(IOError):
|
13 |
+
"""There was an ambiguous exception that occurred while handling your
|
14 |
+
request.
|
15 |
+
"""
|
16 |
+
|
17 |
+
def __init__(self, *args, **kwargs):
|
18 |
+
"""Initialize RequestException with `request` and `response` objects."""
|
19 |
+
response = kwargs.pop("response", None)
|
20 |
+
self.response = response
|
21 |
+
self.request = kwargs.pop("request", None)
|
22 |
+
if response is not None and not self.request and hasattr(response, "request"):
|
23 |
+
self.request = self.response.request
|
24 |
+
super().__init__(*args, **kwargs)
|
25 |
+
|
26 |
+
|
27 |
+
class InvalidJSONError(RequestException):
|
28 |
+
"""A JSON error occurred."""
|
29 |
+
|
30 |
+
|
31 |
+
class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
|
32 |
+
"""Couldn't decode the text into json"""
|
33 |
+
|
34 |
+
def __init__(self, *args, **kwargs):
|
35 |
+
"""
|
36 |
+
Construct the JSONDecodeError instance first with all
|
37 |
+
args. Then use it's args to construct the IOError so that
|
38 |
+
the json specific args aren't used as IOError specific args
|
39 |
+
and the error message from JSONDecodeError is preserved.
|
40 |
+
"""
|
41 |
+
CompatJSONDecodeError.__init__(self, *args)
|
42 |
+
InvalidJSONError.__init__(self, *self.args, **kwargs)
|
43 |
+
|
44 |
+
|
45 |
+
class HTTPError(RequestException):
|
46 |
+
"""An HTTP error occurred."""
|
47 |
+
|
48 |
+
|
49 |
+
class ConnectionError(RequestException):
|
50 |
+
"""A Connection error occurred."""
|
51 |
+
|
52 |
+
|
53 |
+
class ProxyError(ConnectionError):
|
54 |
+
"""A proxy error occurred."""
|
55 |
+
|
56 |
+
|
57 |
+
class SSLError(ConnectionError):
|
58 |
+
"""An SSL error occurred."""
|
59 |
+
|
60 |
+
|
61 |
+
class Timeout(RequestException):
|
62 |
+
"""The request timed out.
|
63 |
+
|
64 |
+
Catching this error will catch both
|
65 |
+
:exc:`~requests.exceptions.ConnectTimeout` and
|
66 |
+
:exc:`~requests.exceptions.ReadTimeout` errors.
|
67 |
+
"""
|
68 |
+
|
69 |
+
|
70 |
+
class ConnectTimeout(ConnectionError, Timeout):
|
71 |
+
"""The request timed out while trying to connect to the remote server.
|
72 |
+
|
73 |
+
Requests that produced this error are safe to retry.
|
74 |
+
"""
|
75 |
+
|
76 |
+
|
77 |
+
class ReadTimeout(Timeout):
|
78 |
+
"""The server did not send any data in the allotted amount of time."""
|
79 |
+
|
80 |
+
|
81 |
+
class URLRequired(RequestException):
|
82 |
+
"""A valid URL is required to make a request."""
|
83 |
+
|
84 |
+
|
85 |
+
class TooManyRedirects(RequestException):
|
86 |
+
"""Too many redirects."""
|
87 |
+
|
88 |
+
|
89 |
+
class MissingSchema(RequestException, ValueError):
|
90 |
+
"""The URL scheme (e.g. http or https) is missing."""
|
91 |
+
|
92 |
+
|
93 |
+
class InvalidSchema(RequestException, ValueError):
|
94 |
+
"""The URL scheme provided is either invalid or unsupported."""
|
95 |
+
|
96 |
+
|
97 |
+
class InvalidURL(RequestException, ValueError):
|
98 |
+
"""The URL provided was somehow invalid."""
|
99 |
+
|
100 |
+
|
101 |
+
class InvalidHeader(RequestException, ValueError):
|
102 |
+
"""The header value provided was somehow invalid."""
|
103 |
+
|
104 |
+
|
105 |
+
class InvalidProxyURL(InvalidURL):
|
106 |
+
"""The proxy URL provided is invalid."""
|
107 |
+
|
108 |
+
|
109 |
+
class ChunkedEncodingError(RequestException):
|
110 |
+
"""The server declared chunked encoding but sent an invalid chunk."""
|
111 |
+
|
112 |
+
|
113 |
+
class ContentDecodingError(RequestException, BaseHTTPError):
|
114 |
+
"""Failed to decode response content."""
|
115 |
+
|
116 |
+
|
117 |
+
class StreamConsumedError(RequestException, TypeError):
|
118 |
+
"""The content for this response was already consumed."""
|
119 |
+
|
120 |
+
|
121 |
+
class RetryError(RequestException):
|
122 |
+
"""Custom retries logic failed"""
|
123 |
+
|
124 |
+
|
125 |
+
class UnrewindableBodyError(RequestException):
|
126 |
+
"""Requests encountered an error when trying to rewind a body."""
|
127 |
+
|
128 |
+
|
129 |
+
# Warnings
|
130 |
+
|
131 |
+
|
132 |
+
class RequestsWarning(Warning):
|
133 |
+
"""Base warning for Requests."""
|
134 |
+
|
135 |
+
|
136 |
+
class FileModeWarning(RequestsWarning, DeprecationWarning):
|
137 |
+
"""A file was opened in text mode, but Requests determined its binary length."""
|
138 |
+
|
139 |
+
|
140 |
+
class RequestsDependencyWarning(RequestsWarning):
|
141 |
+
"""An imported dependency doesn't match the expected version range."""
|
llmeval-env/lib/python3.10/site-packages/requests/help.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Module containing bug report helper(s)."""
|
2 |
+
|
3 |
+
import json
|
4 |
+
import platform
|
5 |
+
import ssl
|
6 |
+
import sys
|
7 |
+
|
8 |
+
import idna
|
9 |
+
import urllib3
|
10 |
+
|
11 |
+
from . import __version__ as requests_version
|
12 |
+
|
13 |
+
try:
|
14 |
+
import charset_normalizer
|
15 |
+
except ImportError:
|
16 |
+
charset_normalizer = None
|
17 |
+
|
18 |
+
try:
|
19 |
+
import chardet
|
20 |
+
except ImportError:
|
21 |
+
chardet = None
|
22 |
+
|
23 |
+
try:
|
24 |
+
from urllib3.contrib import pyopenssl
|
25 |
+
except ImportError:
|
26 |
+
pyopenssl = None
|
27 |
+
OpenSSL = None
|
28 |
+
cryptography = None
|
29 |
+
else:
|
30 |
+
import cryptography
|
31 |
+
import OpenSSL
|
32 |
+
|
33 |
+
|
34 |
+
def _implementation():
|
35 |
+
"""Return a dict with the Python implementation and version.
|
36 |
+
|
37 |
+
Provide both the name and the version of the Python implementation
|
38 |
+
currently running. For example, on CPython 3.10.3 it will return
|
39 |
+
{'name': 'CPython', 'version': '3.10.3'}.
|
40 |
+
|
41 |
+
This function works best on CPython and PyPy: in particular, it probably
|
42 |
+
doesn't work for Jython or IronPython. Future investigation should be done
|
43 |
+
to work out the correct shape of the code for those platforms.
|
44 |
+
"""
|
45 |
+
implementation = platform.python_implementation()
|
46 |
+
|
47 |
+
if implementation == "CPython":
|
48 |
+
implementation_version = platform.python_version()
|
49 |
+
elif implementation == "PyPy":
|
50 |
+
implementation_version = "{}.{}.{}".format(
|
51 |
+
sys.pypy_version_info.major,
|
52 |
+
sys.pypy_version_info.minor,
|
53 |
+
sys.pypy_version_info.micro,
|
54 |
+
)
|
55 |
+
if sys.pypy_version_info.releaselevel != "final":
|
56 |
+
implementation_version = "".join(
|
57 |
+
[implementation_version, sys.pypy_version_info.releaselevel]
|
58 |
+
)
|
59 |
+
elif implementation == "Jython":
|
60 |
+
implementation_version = platform.python_version() # Complete Guess
|
61 |
+
elif implementation == "IronPython":
|
62 |
+
implementation_version = platform.python_version() # Complete Guess
|
63 |
+
else:
|
64 |
+
implementation_version = "Unknown"
|
65 |
+
|
66 |
+
return {"name": implementation, "version": implementation_version}
|
67 |
+
|
68 |
+
|
69 |
+
def info():
|
70 |
+
"""Generate information for a bug report."""
|
71 |
+
try:
|
72 |
+
platform_info = {
|
73 |
+
"system": platform.system(),
|
74 |
+
"release": platform.release(),
|
75 |
+
}
|
76 |
+
except OSError:
|
77 |
+
platform_info = {
|
78 |
+
"system": "Unknown",
|
79 |
+
"release": "Unknown",
|
80 |
+
}
|
81 |
+
|
82 |
+
implementation_info = _implementation()
|
83 |
+
urllib3_info = {"version": urllib3.__version__}
|
84 |
+
charset_normalizer_info = {"version": None}
|
85 |
+
chardet_info = {"version": None}
|
86 |
+
if charset_normalizer:
|
87 |
+
charset_normalizer_info = {"version": charset_normalizer.__version__}
|
88 |
+
if chardet:
|
89 |
+
chardet_info = {"version": chardet.__version__}
|
90 |
+
|
91 |
+
pyopenssl_info = {
|
92 |
+
"version": None,
|
93 |
+
"openssl_version": "",
|
94 |
+
}
|
95 |
+
if OpenSSL:
|
96 |
+
pyopenssl_info = {
|
97 |
+
"version": OpenSSL.__version__,
|
98 |
+
"openssl_version": f"{OpenSSL.SSL.OPENSSL_VERSION_NUMBER:x}",
|
99 |
+
}
|
100 |
+
cryptography_info = {
|
101 |
+
"version": getattr(cryptography, "__version__", ""),
|
102 |
+
}
|
103 |
+
idna_info = {
|
104 |
+
"version": getattr(idna, "__version__", ""),
|
105 |
+
}
|
106 |
+
|
107 |
+
system_ssl = ssl.OPENSSL_VERSION_NUMBER
|
108 |
+
system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""}
|
109 |
+
|
110 |
+
return {
|
111 |
+
"platform": platform_info,
|
112 |
+
"implementation": implementation_info,
|
113 |
+
"system_ssl": system_ssl_info,
|
114 |
+
"using_pyopenssl": pyopenssl is not None,
|
115 |
+
"using_charset_normalizer": chardet is None,
|
116 |
+
"pyOpenSSL": pyopenssl_info,
|
117 |
+
"urllib3": urllib3_info,
|
118 |
+
"chardet": chardet_info,
|
119 |
+
"charset_normalizer": charset_normalizer_info,
|
120 |
+
"cryptography": cryptography_info,
|
121 |
+
"idna": idna_info,
|
122 |
+
"requests": {
|
123 |
+
"version": requests_version,
|
124 |
+
},
|
125 |
+
}
|
126 |
+
|
127 |
+
|
128 |
+
def main():
|
129 |
+
"""Pretty-print the bug information as JSON."""
|
130 |
+
print(json.dumps(info(), sort_keys=True, indent=2))
|
131 |
+
|
132 |
+
|
133 |
+
if __name__ == "__main__":
|
134 |
+
main()
|
llmeval-env/lib/python3.10/site-packages/requests/packages.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
|
3 |
+
try:
|
4 |
+
import chardet
|
5 |
+
except ImportError:
|
6 |
+
import warnings
|
7 |
+
|
8 |
+
import charset_normalizer as chardet
|
9 |
+
|
10 |
+
warnings.filterwarnings("ignore", "Trying to detect", module="charset_normalizer")
|
11 |
+
|
12 |
+
# This code exists for backwards compatibility reasons.
|
13 |
+
# I don't like it either. Just look the other way. :)
|
14 |
+
|
15 |
+
for package in ("urllib3", "idna"):
|
16 |
+
locals()[package] = __import__(package)
|
17 |
+
# This traversal is apparently necessary such that the identities are
|
18 |
+
# preserved (requests.packages.urllib3.* is urllib3.*)
|
19 |
+
for mod in list(sys.modules):
|
20 |
+
if mod == package or mod.startswith(f"{package}."):
|
21 |
+
sys.modules[f"requests.packages.{mod}"] = sys.modules[mod]
|
22 |
+
|
23 |
+
target = chardet.__name__
|
24 |
+
for mod in list(sys.modules):
|
25 |
+
if mod == target or mod.startswith(f"{target}."):
|
26 |
+
target = target.replace(target, "chardet")
|
27 |
+
sys.modules[f"requests.packages.{target}"] = sys.modules[mod]
|
28 |
+
# Kinda cool, though, right?
|
llmeval-env/lib/python3.10/site-packages/requests/status_codes.py
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
r"""
|
2 |
+
The ``codes`` object defines a mapping from common names for HTTP statuses
|
3 |
+
to their numerical codes, accessible either as attributes or as dictionary
|
4 |
+
items.
|
5 |
+
|
6 |
+
Example::
|
7 |
+
|
8 |
+
>>> import requests
|
9 |
+
>>> requests.codes['temporary_redirect']
|
10 |
+
307
|
11 |
+
>>> requests.codes.teapot
|
12 |
+
418
|
13 |
+
>>> requests.codes['\o/']
|
14 |
+
200
|
15 |
+
|
16 |
+
Some codes have multiple names, and both upper- and lower-case versions of
|
17 |
+
the names are allowed. For example, ``codes.ok``, ``codes.OK``, and
|
18 |
+
``codes.okay`` all correspond to the HTTP status code 200.
|
19 |
+
"""
|
20 |
+
|
21 |
+
from .structures import LookupDict
|
22 |
+
|
23 |
+
_codes = {
|
24 |
+
# Informational.
|
25 |
+
100: ("continue",),
|
26 |
+
101: ("switching_protocols",),
|
27 |
+
102: ("processing",),
|
28 |
+
103: ("checkpoint",),
|
29 |
+
122: ("uri_too_long", "request_uri_too_long"),
|
30 |
+
200: ("ok", "okay", "all_ok", "all_okay", "all_good", "\\o/", "✓"),
|
31 |
+
201: ("created",),
|
32 |
+
202: ("accepted",),
|
33 |
+
203: ("non_authoritative_info", "non_authoritative_information"),
|
34 |
+
204: ("no_content",),
|
35 |
+
205: ("reset_content", "reset"),
|
36 |
+
206: ("partial_content", "partial"),
|
37 |
+
207: ("multi_status", "multiple_status", "multi_stati", "multiple_stati"),
|
38 |
+
208: ("already_reported",),
|
39 |
+
226: ("im_used",),
|
40 |
+
# Redirection.
|
41 |
+
300: ("multiple_choices",),
|
42 |
+
301: ("moved_permanently", "moved", "\\o-"),
|
43 |
+
302: ("found",),
|
44 |
+
303: ("see_other", "other"),
|
45 |
+
304: ("not_modified",),
|
46 |
+
305: ("use_proxy",),
|
47 |
+
306: ("switch_proxy",),
|
48 |
+
307: ("temporary_redirect", "temporary_moved", "temporary"),
|
49 |
+
308: (
|
50 |
+
"permanent_redirect",
|
51 |
+
"resume_incomplete",
|
52 |
+
"resume",
|
53 |
+
), # "resume" and "resume_incomplete" to be removed in 3.0
|
54 |
+
# Client Error.
|
55 |
+
400: ("bad_request", "bad"),
|
56 |
+
401: ("unauthorized",),
|
57 |
+
402: ("payment_required", "payment"),
|
58 |
+
403: ("forbidden",),
|
59 |
+
404: ("not_found", "-o-"),
|
60 |
+
405: ("method_not_allowed", "not_allowed"),
|
61 |
+
406: ("not_acceptable",),
|
62 |
+
407: ("proxy_authentication_required", "proxy_auth", "proxy_authentication"),
|
63 |
+
408: ("request_timeout", "timeout"),
|
64 |
+
409: ("conflict",),
|
65 |
+
410: ("gone",),
|
66 |
+
411: ("length_required",),
|
67 |
+
412: ("precondition_failed", "precondition"),
|
68 |
+
413: ("request_entity_too_large",),
|
69 |
+
414: ("request_uri_too_large",),
|
70 |
+
415: ("unsupported_media_type", "unsupported_media", "media_type"),
|
71 |
+
416: (
|
72 |
+
"requested_range_not_satisfiable",
|
73 |
+
"requested_range",
|
74 |
+
"range_not_satisfiable",
|
75 |
+
),
|
76 |
+
417: ("expectation_failed",),
|
77 |
+
418: ("im_a_teapot", "teapot", "i_am_a_teapot"),
|
78 |
+
421: ("misdirected_request",),
|
79 |
+
422: ("unprocessable_entity", "unprocessable"),
|
80 |
+
423: ("locked",),
|
81 |
+
424: ("failed_dependency", "dependency"),
|
82 |
+
425: ("unordered_collection", "unordered"),
|
83 |
+
426: ("upgrade_required", "upgrade"),
|
84 |
+
428: ("precondition_required", "precondition"),
|
85 |
+
429: ("too_many_requests", "too_many"),
|
86 |
+
431: ("header_fields_too_large", "fields_too_large"),
|
87 |
+
444: ("no_response", "none"),
|
88 |
+
449: ("retry_with", "retry"),
|
89 |
+
450: ("blocked_by_windows_parental_controls", "parental_controls"),
|
90 |
+
451: ("unavailable_for_legal_reasons", "legal_reasons"),
|
91 |
+
499: ("client_closed_request",),
|
92 |
+
# Server Error.
|
93 |
+
500: ("internal_server_error", "server_error", "/o\\", "✗"),
|
94 |
+
501: ("not_implemented",),
|
95 |
+
502: ("bad_gateway",),
|
96 |
+
503: ("service_unavailable", "unavailable"),
|
97 |
+
504: ("gateway_timeout",),
|
98 |
+
505: ("http_version_not_supported", "http_version"),
|
99 |
+
506: ("variant_also_negotiates",),
|
100 |
+
507: ("insufficient_storage",),
|
101 |
+
509: ("bandwidth_limit_exceeded", "bandwidth"),
|
102 |
+
510: ("not_extended",),
|
103 |
+
511: ("network_authentication_required", "network_auth", "network_authentication"),
|
104 |
+
}
|
105 |
+
|
106 |
+
codes = LookupDict(name="status_codes")
|
107 |
+
|
108 |
+
|
109 |
+
def _init():
|
110 |
+
for code, titles in _codes.items():
|
111 |
+
for title in titles:
|
112 |
+
setattr(codes, title, code)
|
113 |
+
if not title.startswith(("\\", "/")):
|
114 |
+
setattr(codes, title.upper(), code)
|
115 |
+
|
116 |
+
def doc(code):
|
117 |
+
names = ", ".join(f"``{n}``" for n in _codes[code])
|
118 |
+
return "* %d: %s" % (code, names)
|
119 |
+
|
120 |
+
global __doc__
|
121 |
+
__doc__ = (
|
122 |
+
__doc__ + "\n" + "\n".join(doc(code) for code in sorted(_codes))
|
123 |
+
if __doc__ is not None
|
124 |
+
else None
|
125 |
+
)
|
126 |
+
|
127 |
+
|
128 |
+
_init()
|
llmeval-env/lib/python3.10/site-packages/requests/structures.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
requests.structures
|
3 |
+
~~~~~~~~~~~~~~~~~~~
|
4 |
+
|
5 |
+
Data structures that power Requests.
|
6 |
+
"""
|
7 |
+
|
8 |
+
from collections import OrderedDict
|
9 |
+
|
10 |
+
from .compat import Mapping, MutableMapping
|
11 |
+
|
12 |
+
|
13 |
+
class CaseInsensitiveDict(MutableMapping):
|
14 |
+
"""A case-insensitive ``dict``-like object.
|
15 |
+
|
16 |
+
Implements all methods and operations of
|
17 |
+
``MutableMapping`` as well as dict's ``copy``. Also
|
18 |
+
provides ``lower_items``.
|
19 |
+
|
20 |
+
All keys are expected to be strings. The structure remembers the
|
21 |
+
case of the last key to be set, and ``iter(instance)``,
|
22 |
+
``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
|
23 |
+
will contain case-sensitive keys. However, querying and contains
|
24 |
+
testing is case insensitive::
|
25 |
+
|
26 |
+
cid = CaseInsensitiveDict()
|
27 |
+
cid['Accept'] = 'application/json'
|
28 |
+
cid['aCCEPT'] == 'application/json' # True
|
29 |
+
list(cid) == ['Accept'] # True
|
30 |
+
|
31 |
+
For example, ``headers['content-encoding']`` will return the
|
32 |
+
value of a ``'Content-Encoding'`` response header, regardless
|
33 |
+
of how the header name was originally stored.
|
34 |
+
|
35 |
+
If the constructor, ``.update``, or equality comparison
|
36 |
+
operations are given keys that have equal ``.lower()``s, the
|
37 |
+
behavior is undefined.
|
38 |
+
"""
|
39 |
+
|
40 |
+
def __init__(self, data=None, **kwargs):
|
41 |
+
self._store = OrderedDict()
|
42 |
+
if data is None:
|
43 |
+
data = {}
|
44 |
+
self.update(data, **kwargs)
|
45 |
+
|
46 |
+
def __setitem__(self, key, value):
|
47 |
+
# Use the lowercased key for lookups, but store the actual
|
48 |
+
# key alongside the value.
|
49 |
+
self._store[key.lower()] = (key, value)
|
50 |
+
|
51 |
+
def __getitem__(self, key):
|
52 |
+
return self._store[key.lower()][1]
|
53 |
+
|
54 |
+
def __delitem__(self, key):
|
55 |
+
del self._store[key.lower()]
|
56 |
+
|
57 |
+
def __iter__(self):
|
58 |
+
return (casedkey for casedkey, mappedvalue in self._store.values())
|
59 |
+
|
60 |
+
def __len__(self):
|
61 |
+
return len(self._store)
|
62 |
+
|
63 |
+
def lower_items(self):
|
64 |
+
"""Like iteritems(), but with all lowercase keys."""
|
65 |
+
return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())
|
66 |
+
|
67 |
+
def __eq__(self, other):
|
68 |
+
if isinstance(other, Mapping):
|
69 |
+
other = CaseInsensitiveDict(other)
|
70 |
+
else:
|
71 |
+
return NotImplemented
|
72 |
+
# Compare insensitively
|
73 |
+
return dict(self.lower_items()) == dict(other.lower_items())
|
74 |
+
|
75 |
+
# Copy is required
|
76 |
+
def copy(self):
|
77 |
+
return CaseInsensitiveDict(self._store.values())
|
78 |
+
|
79 |
+
def __repr__(self):
|
80 |
+
return str(dict(self.items()))
|
81 |
+
|
82 |
+
|
83 |
+
class LookupDict(dict):
|
84 |
+
"""Dictionary lookup object."""
|
85 |
+
|
86 |
+
def __init__(self, name=None):
|
87 |
+
self.name = name
|
88 |
+
super().__init__()
|
89 |
+
|
90 |
+
def __repr__(self):
|
91 |
+
return f"<lookup '{self.name}'>"
|
92 |
+
|
93 |
+
def __getitem__(self, key):
|
94 |
+
# We allow fall-through here, so values default to None
|
95 |
+
|
96 |
+
return self.__dict__.get(key, None)
|
97 |
+
|
98 |
+
def get(self, key, default=None):
|
99 |
+
return self.__dict__.get(key, default)
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_common.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import decimal
|
6 |
+
import math
|
7 |
+
|
8 |
+
|
9 |
+
def isstring(value):
|
10 |
+
return isinstance(value, (str,) + (str, bytes))
|
11 |
+
|
12 |
+
|
13 |
+
def isinf(value):
|
14 |
+
try:
|
15 |
+
return decimal.Decimal(value).is_infinite()
|
16 |
+
except OverflowError:
|
17 |
+
return True
|
18 |
+
except TypeError:
|
19 |
+
return False
|
20 |
+
except (ValueError, decimal.InvalidOperation):
|
21 |
+
return False
|
22 |
+
|
23 |
+
|
24 |
+
def isnan(value):
|
25 |
+
try:
|
26 |
+
return math.isnan(value)
|
27 |
+
except (TypeError, OverflowError):
|
28 |
+
return False
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_dictionary.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._checker import CheckerFactory, TypeCheckerBase, TypeCheckerDelegator
|
6 |
+
|
7 |
+
|
8 |
+
class DictionaryTypeCheckerStrictLevel0(TypeCheckerBase):
|
9 |
+
def is_instance(self):
|
10 |
+
return isinstance(self._value, dict)
|
11 |
+
|
12 |
+
def is_valid_after_convert(self, converted_value):
|
13 |
+
return isinstance(converted_value, dict) and converted_value
|
14 |
+
|
15 |
+
|
16 |
+
class DictionaryTypeCheckerStrictLevel1(DictionaryTypeCheckerStrictLevel0):
|
17 |
+
def is_exclude_instance(self):
|
18 |
+
return not isinstance(self._value, dict)
|
19 |
+
|
20 |
+
|
21 |
+
_factory = CheckerFactory(
|
22 |
+
checker_mapping={0: DictionaryTypeCheckerStrictLevel0, 1: DictionaryTypeCheckerStrictLevel1}
|
23 |
+
)
|
24 |
+
|
25 |
+
|
26 |
+
class DictionaryTypeChecker(TypeCheckerDelegator):
|
27 |
+
def __init__(self, value, strict_level):
|
28 |
+
super().__init__(value=value, checker_factory=_factory, strict_level=strict_level)
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_infinity.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._checker import CheckerFactory, TypeCheckerBase, TypeCheckerDelegator
|
6 |
+
from ._common import isinf, isstring
|
7 |
+
|
8 |
+
|
9 |
+
class InfinityCheckerStrictLevel0(TypeCheckerBase):
|
10 |
+
def is_instance(self):
|
11 |
+
return isinf(self._value)
|
12 |
+
|
13 |
+
def is_valid_after_convert(self, converted_value):
|
14 |
+
try:
|
15 |
+
return converted_value.is_infinite()
|
16 |
+
except AttributeError:
|
17 |
+
return False
|
18 |
+
|
19 |
+
|
20 |
+
class InfinityCheckerStrictLevel1(InfinityCheckerStrictLevel0):
|
21 |
+
def is_exclude_instance(self):
|
22 |
+
return isstring(self._value)
|
23 |
+
|
24 |
+
|
25 |
+
_factory = CheckerFactory(
|
26 |
+
checker_mapping={0: InfinityCheckerStrictLevel0, 1: InfinityCheckerStrictLevel1}
|
27 |
+
)
|
28 |
+
|
29 |
+
|
30 |
+
class InfinityTypeChecker(TypeCheckerDelegator):
|
31 |
+
def __init__(self, value, strict_level):
|
32 |
+
super().__init__(value=value, checker_factory=_factory, strict_level=strict_level)
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_interface.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import abc
|
6 |
+
|
7 |
+
|
8 |
+
class TypeCheckerInterface(metaclass=abc.ABCMeta):
|
9 |
+
@abc.abstractmethod
|
10 |
+
def is_type(self) -> bool: # pragma: no cover
|
11 |
+
pass
|
12 |
+
|
13 |
+
@abc.abstractmethod
|
14 |
+
def validate(self) -> None: # pragma: no cover
|
15 |
+
pass
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_ipaddress.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._checker import CheckerFactory, TypeCheckerBase, TypeCheckerDelegator
|
6 |
+
from ._common import isstring
|
7 |
+
|
8 |
+
|
9 |
+
class IpAddressTypeCheckerStrictLevel0(TypeCheckerBase):
|
10 |
+
def is_instance(self):
|
11 |
+
return self._is_ipaddress(self._value)
|
12 |
+
|
13 |
+
def is_valid_after_convert(self, converted_value):
|
14 |
+
return self._is_ipaddress(converted_value)
|
15 |
+
|
16 |
+
@staticmethod
|
17 |
+
def _is_ipaddress(value):
|
18 |
+
import ipaddress
|
19 |
+
|
20 |
+
return isinstance(value, (ipaddress.IPv4Address, ipaddress.IPv6Address))
|
21 |
+
|
22 |
+
|
23 |
+
class IpAddressTypeCheckerStrictLevel1(IpAddressTypeCheckerStrictLevel0):
|
24 |
+
def is_exclude_instance(self):
|
25 |
+
return isstring(self._value) or super().is_exclude_instance()
|
26 |
+
|
27 |
+
|
28 |
+
_factory = CheckerFactory(
|
29 |
+
checker_mapping={0: IpAddressTypeCheckerStrictLevel0, 1: IpAddressTypeCheckerStrictLevel1}
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
class IpAddressTypeChecker(TypeCheckerDelegator):
|
34 |
+
def __init__(self, value, strict_level):
|
35 |
+
super().__init__(value=value, checker_factory=_factory, strict_level=strict_level)
|
llmeval-env/lib/python3.10/site-packages/typepy/checker/_list.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._checker import CheckerFactory, TypeCheckerBase, TypeCheckerDelegator
|
6 |
+
from ._common import isstring
|
7 |
+
|
8 |
+
|
9 |
+
class ListTypeCheckerStrictLevel0(TypeCheckerBase):
|
10 |
+
def is_instance(self):
|
11 |
+
return isinstance(self._value, list)
|
12 |
+
|
13 |
+
def is_valid_after_convert(self, converted_value):
|
14 |
+
return isinstance(converted_value, list) and converted_value
|
15 |
+
|
16 |
+
def is_exclude_instance(self):
|
17 |
+
return isstring(self._value)
|
18 |
+
|
19 |
+
|
20 |
+
class ListTypeCheckerStrictLevel1(ListTypeCheckerStrictLevel0):
|
21 |
+
def is_exclude_instance(self):
|
22 |
+
return super().is_exclude_instance() or not isinstance(self._value, list)
|
23 |
+
|
24 |
+
|
25 |
+
_factory = CheckerFactory(
|
26 |
+
checker_mapping={0: ListTypeCheckerStrictLevel0, 1: ListTypeCheckerStrictLevel1}
|
27 |
+
)
|
28 |
+
|
29 |
+
|
30 |
+
class ListTypeChecker(TypeCheckerDelegator):
|
31 |
+
def __init__(self, value, strict_level):
|
32 |
+
super().__init__(value=value, checker_factory=_factory, strict_level=strict_level)
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__init__.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._base import AbstractType
|
6 |
+
from ._binary import Binary
|
7 |
+
from ._bool import Bool
|
8 |
+
from ._bytes import Bytes
|
9 |
+
from ._datetime import DateTime
|
10 |
+
from ._dictionary import Dictionary
|
11 |
+
from ._infinity import Infinity
|
12 |
+
from ._integer import Integer
|
13 |
+
from ._ipaddress import IpAddress
|
14 |
+
from ._list import List
|
15 |
+
from ._nan import Nan
|
16 |
+
from ._none import NoneType
|
17 |
+
from ._realnumber import RealNumber
|
18 |
+
from ._string import NullString, String
|
19 |
+
|
20 |
+
|
21 |
+
__all__ = (
|
22 |
+
"AbstractType",
|
23 |
+
"Binary",
|
24 |
+
"Bool",
|
25 |
+
"Bytes",
|
26 |
+
"DateTime",
|
27 |
+
"Dictionary",
|
28 |
+
"Infinity",
|
29 |
+
"Integer",
|
30 |
+
"IpAddress",
|
31 |
+
"List",
|
32 |
+
"Nan",
|
33 |
+
"NoneType",
|
34 |
+
"NullString",
|
35 |
+
"RealNumber",
|
36 |
+
"String",
|
37 |
+
)
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (931 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_base.cpython-310.pyc
ADDED
Binary file (3.84 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_binary.cpython-310.pyc
ADDED
Binary file (1.49 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_bool.cpython-310.pyc
ADDED
Binary file (1.53 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_bytes.cpython-310.pyc
ADDED
Binary file (1.48 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_datetime.cpython-310.pyc
ADDED
Binary file (1.56 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_dictionary.cpython-310.pyc
ADDED
Binary file (1.58 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/typepy/type/__pycache__/_infinity.cpython-310.pyc
ADDED
Binary file (1.55 kB). View file
|
|