Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__main__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/cmdline.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/filter.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/formatter.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/lexer.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/modeline.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/plugin.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/regexopt.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/scanner.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/sphinxext.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/token.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/groff.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/html.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/other.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/pangomarkup.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__init__.py +154 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/__version__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/_internal_utils.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/adapters.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/api.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/auth.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/certs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/compat.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/cookies.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/exceptions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/help.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/hooks.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/models.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/packages.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/sessions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/status_codes.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/structures.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/utils.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__version__.py +14 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/_internal_utils.py +42 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/adapters.py +538 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/api.py +159 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/auth.py +305 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/certs.py +18 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/compat.py +77 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/cookies.py +549 -0
- llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/exceptions.py +133 -0
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (2.99 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (589 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/cmdline.cpython-310.pyc
ADDED
Binary file (15.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/filter.cpython-310.pyc
ADDED
Binary file (2.66 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/formatter.cpython-310.pyc
ADDED
Binary file (3.01 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/lexer.cpython-310.pyc
ADDED
Binary file (24.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/modeline.cpython-310.pyc
ADDED
Binary file (1.19 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/plugin.cpython-310.pyc
ADDED
Binary file (2.05 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/regexopt.cpython-310.pyc
ADDED
Binary file (2.96 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/scanner.cpython-310.pyc
ADDED
Binary file (3.56 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/sphinxext.cpython-310.pyc
ADDED
Binary file (4.54 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/__pycache__/token.cpython-310.pyc
ADDED
Binary file (4.65 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (4.67 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/_mapping.cpython-310.pyc
ADDED
Binary file (5.54 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/bbcode.cpython-310.pyc
ADDED
Binary file (3.09 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/groff.cpython-310.pyc
ADDED
Binary file (4.36 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/html.cpython-310.pyc
ADDED
Binary file (29.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/latex.cpython-310.pyc
ADDED
Binary file (13.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/other.cpython-310.pyc
ADDED
Binary file (4.81 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/pangomarkup.cpython-310.pyc
ADDED
Binary file (2.11 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/rtf.cpython-310.pyc
ADDED
Binary file (4.14 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/pygments/formatters/__pycache__/terminal.cpython-310.pyc
ADDED
Binary file (4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__init__.py
ADDED
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
# __
|
4 |
+
# /__) _ _ _ _ _/ _
|
5 |
+
# / ( (- (/ (/ (- _) / _)
|
6 |
+
# /
|
7 |
+
|
8 |
+
"""
|
9 |
+
Requests HTTP Library
|
10 |
+
~~~~~~~~~~~~~~~~~~~~~
|
11 |
+
|
12 |
+
Requests is an HTTP library, written in Python, for human beings.
|
13 |
+
Basic GET usage:
|
14 |
+
|
15 |
+
>>> import requests
|
16 |
+
>>> r = requests.get('https://www.python.org')
|
17 |
+
>>> r.status_code
|
18 |
+
200
|
19 |
+
>>> b'Python is a programming language' in r.content
|
20 |
+
True
|
21 |
+
|
22 |
+
... or POST:
|
23 |
+
|
24 |
+
>>> payload = dict(key1='value1', key2='value2')
|
25 |
+
>>> r = requests.post('https://httpbin.org/post', data=payload)
|
26 |
+
>>> print(r.text)
|
27 |
+
{
|
28 |
+
...
|
29 |
+
"form": {
|
30 |
+
"key1": "value1",
|
31 |
+
"key2": "value2"
|
32 |
+
},
|
33 |
+
...
|
34 |
+
}
|
35 |
+
|
36 |
+
The other HTTP methods are supported - see `requests.api`. Full documentation
|
37 |
+
is at <https://requests.readthedocs.io>.
|
38 |
+
|
39 |
+
:copyright: (c) 2017 by Kenneth Reitz.
|
40 |
+
:license: Apache 2.0, see LICENSE for more details.
|
41 |
+
"""
|
42 |
+
|
43 |
+
from pip._vendor import urllib3
|
44 |
+
import warnings
|
45 |
+
from .exceptions import RequestsDependencyWarning
|
46 |
+
|
47 |
+
charset_normalizer_version = None
|
48 |
+
|
49 |
+
try:
|
50 |
+
from pip._vendor.chardet import __version__ as chardet_version
|
51 |
+
except ImportError:
|
52 |
+
chardet_version = None
|
53 |
+
|
54 |
+
def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
|
55 |
+
urllib3_version = urllib3_version.split('.')
|
56 |
+
assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.
|
57 |
+
|
58 |
+
# Sometimes, urllib3 only reports its version as 16.1.
|
59 |
+
if len(urllib3_version) == 2:
|
60 |
+
urllib3_version.append('0')
|
61 |
+
|
62 |
+
# Check urllib3 for compatibility.
|
63 |
+
major, minor, patch = urllib3_version # noqa: F811
|
64 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
65 |
+
# urllib3 >= 1.21.1, <= 1.26
|
66 |
+
assert major == 1
|
67 |
+
assert minor >= 21
|
68 |
+
assert minor <= 26
|
69 |
+
|
70 |
+
# Check charset_normalizer for compatibility.
|
71 |
+
if chardet_version:
|
72 |
+
major, minor, patch = chardet_version.split('.')[:3]
|
73 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
74 |
+
# chardet_version >= 3.0.2, < 5.0.0
|
75 |
+
assert (3, 0, 2) <= (major, minor, patch) < (5, 0, 0)
|
76 |
+
elif charset_normalizer_version:
|
77 |
+
major, minor, patch = charset_normalizer_version.split('.')[:3]
|
78 |
+
major, minor, patch = int(major), int(minor), int(patch)
|
79 |
+
# charset_normalizer >= 2.0.0 < 3.0.0
|
80 |
+
assert (2, 0, 0) <= (major, minor, patch) < (3, 0, 0)
|
81 |
+
else:
|
82 |
+
raise Exception("You need either charset_normalizer or chardet installed")
|
83 |
+
|
84 |
+
def _check_cryptography(cryptography_version):
|
85 |
+
# cryptography < 1.3.4
|
86 |
+
try:
|
87 |
+
cryptography_version = list(map(int, cryptography_version.split('.')))
|
88 |
+
except ValueError:
|
89 |
+
return
|
90 |
+
|
91 |
+
if cryptography_version < [1, 3, 4]:
|
92 |
+
warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
|
93 |
+
warnings.warn(warning, RequestsDependencyWarning)
|
94 |
+
|
95 |
+
# Check imported dependencies for compatibility.
|
96 |
+
try:
|
97 |
+
check_compatibility(urllib3.__version__, chardet_version, charset_normalizer_version)
|
98 |
+
except (AssertionError, ValueError):
|
99 |
+
warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
|
100 |
+
"version!".format(urllib3.__version__, chardet_version, charset_normalizer_version),
|
101 |
+
RequestsDependencyWarning)
|
102 |
+
|
103 |
+
# Attempt to enable urllib3's fallback for SNI support
|
104 |
+
# if the standard library doesn't support SNI or the
|
105 |
+
# 'ssl' library isn't available.
|
106 |
+
try:
|
107 |
+
# Note: This logic prevents upgrading cryptography on Windows, if imported
|
108 |
+
# as part of pip.
|
109 |
+
from pip._internal.utils.compat import WINDOWS
|
110 |
+
if not WINDOWS:
|
111 |
+
raise ImportError("pip internals: don't import cryptography on Windows")
|
112 |
+
try:
|
113 |
+
import ssl
|
114 |
+
except ImportError:
|
115 |
+
ssl = None
|
116 |
+
|
117 |
+
if not getattr(ssl, "HAS_SNI", False):
|
118 |
+
from pip._vendor.urllib3.contrib import pyopenssl
|
119 |
+
pyopenssl.inject_into_urllib3()
|
120 |
+
|
121 |
+
# Check cryptography version
|
122 |
+
from cryptography import __version__ as cryptography_version
|
123 |
+
_check_cryptography(cryptography_version)
|
124 |
+
except ImportError:
|
125 |
+
pass
|
126 |
+
|
127 |
+
# urllib3's DependencyWarnings should be silenced.
|
128 |
+
from pip._vendor.urllib3.exceptions import DependencyWarning
|
129 |
+
warnings.simplefilter('ignore', DependencyWarning)
|
130 |
+
|
131 |
+
from .__version__ import __title__, __description__, __url__, __version__
|
132 |
+
from .__version__ import __build__, __author__, __author_email__, __license__
|
133 |
+
from .__version__ import __copyright__, __cake__
|
134 |
+
|
135 |
+
from . import utils
|
136 |
+
from . import packages
|
137 |
+
from .models import Request, Response, PreparedRequest
|
138 |
+
from .api import request, get, head, post, patch, put, delete, options
|
139 |
+
from .sessions import session, Session
|
140 |
+
from .status_codes import codes
|
141 |
+
from .exceptions import (
|
142 |
+
RequestException, Timeout, URLRequired,
|
143 |
+
TooManyRedirects, HTTPError, ConnectionError,
|
144 |
+
FileModeWarning, ConnectTimeout, ReadTimeout, JSONDecodeError
|
145 |
+
)
|
146 |
+
|
147 |
+
# Set default logging handler to avoid "No handler found" warnings.
|
148 |
+
import logging
|
149 |
+
from logging import NullHandler
|
150 |
+
|
151 |
+
logging.getLogger(__name__).addHandler(NullHandler())
|
152 |
+
|
153 |
+
# FileModeWarnings go off per the default.
|
154 |
+
warnings.simplefilter('default', FileModeWarning, append=True)
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (4.04 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/__version__.cpython-310.pyc
ADDED
Binary file (556 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/_internal_utils.cpython-310.pyc
ADDED
Binary file (1.31 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/adapters.cpython-310.pyc
ADDED
Binary file (17 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/api.cpython-310.pyc
ADDED
Binary file (6.66 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/auth.cpython-310.pyc
ADDED
Binary file (8.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/certs.cpython-310.pyc
ADDED
Binary file (640 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/compat.cpython-310.pyc
ADDED
Binary file (1.68 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/cookies.cpython-310.pyc
ADDED
Binary file (18.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/exceptions.cpython-310.pyc
ADDED
Binary file (5.25 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/help.cpython-310.pyc
ADDED
Binary file (2.91 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/hooks.cpython-310.pyc
ADDED
Binary file (995 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/models.cpython-310.pyc
ADDED
Binary file (24.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/packages.cpython-310.pyc
ADDED
Binary file (509 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/sessions.cpython-310.pyc
ADDED
Binary file (19.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/status_codes.cpython-310.pyc
ADDED
Binary file (4.67 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/structures.cpython-310.pyc
ADDED
Binary file (4.45 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/__pycache__/utils.cpython-310.pyc
ADDED
Binary file (24.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/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.27.1'
|
9 |
+
__build__ = 0x022701
|
10 |
+
__author__ = 'Kenneth Reitz'
|
11 |
+
__author_email__ = '[email protected]'
|
12 |
+
__license__ = 'Apache 2.0'
|
13 |
+
__copyright__ = 'Copyright 2022 Kenneth Reitz'
|
14 |
+
__cake__ = u'\u2728 \U0001f370 \u2728'
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/_internal_utils.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests._internal_utils
|
5 |
+
~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
Provides utility functions that are consumed internally by Requests
|
8 |
+
which depend on extremely few external helpers (such as compat)
|
9 |
+
"""
|
10 |
+
|
11 |
+
from .compat import is_py2, builtin_str, str
|
12 |
+
|
13 |
+
|
14 |
+
def to_native_string(string, encoding='ascii'):
|
15 |
+
"""Given a string object, regardless of type, returns a representation of
|
16 |
+
that string in the native string type, encoding and decoding where
|
17 |
+
necessary. This assumes ASCII unless told otherwise.
|
18 |
+
"""
|
19 |
+
if isinstance(string, builtin_str):
|
20 |
+
out = string
|
21 |
+
else:
|
22 |
+
if is_py2:
|
23 |
+
out = string.encode(encoding)
|
24 |
+
else:
|
25 |
+
out = string.decode(encoding)
|
26 |
+
|
27 |
+
return out
|
28 |
+
|
29 |
+
|
30 |
+
def unicode_is_ascii(u_string):
|
31 |
+
"""Determine if unicode string only contains ASCII characters.
|
32 |
+
|
33 |
+
:param str u_string: unicode string to check. Must be unicode
|
34 |
+
and not Python 2 `str`.
|
35 |
+
:rtype: bool
|
36 |
+
"""
|
37 |
+
assert isinstance(u_string, str)
|
38 |
+
try:
|
39 |
+
u_string.encode('ascii')
|
40 |
+
return True
|
41 |
+
except UnicodeEncodeError:
|
42 |
+
return False
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/adapters.py
ADDED
@@ -0,0 +1,538 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.adapters
|
5 |
+
~~~~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module contains the transport adapters that Requests uses to define
|
8 |
+
and maintain connections.
|
9 |
+
"""
|
10 |
+
|
11 |
+
import os.path
|
12 |
+
import socket
|
13 |
+
|
14 |
+
from pip._vendor.urllib3.poolmanager import PoolManager, proxy_from_url
|
15 |
+
from pip._vendor.urllib3.response import HTTPResponse
|
16 |
+
from pip._vendor.urllib3.util import parse_url
|
17 |
+
from pip._vendor.urllib3.util import Timeout as TimeoutSauce
|
18 |
+
from pip._vendor.urllib3.util.retry import Retry
|
19 |
+
from pip._vendor.urllib3.exceptions import ClosedPoolError
|
20 |
+
from pip._vendor.urllib3.exceptions import ConnectTimeoutError
|
21 |
+
from pip._vendor.urllib3.exceptions import HTTPError as _HTTPError
|
22 |
+
from pip._vendor.urllib3.exceptions import InvalidHeader as _InvalidHeader
|
23 |
+
from pip._vendor.urllib3.exceptions import MaxRetryError
|
24 |
+
from pip._vendor.urllib3.exceptions import NewConnectionError
|
25 |
+
from pip._vendor.urllib3.exceptions import ProxyError as _ProxyError
|
26 |
+
from pip._vendor.urllib3.exceptions import ProtocolError
|
27 |
+
from pip._vendor.urllib3.exceptions import ReadTimeoutError
|
28 |
+
from pip._vendor.urllib3.exceptions import SSLError as _SSLError
|
29 |
+
from pip._vendor.urllib3.exceptions import ResponseError
|
30 |
+
from pip._vendor.urllib3.exceptions import LocationValueError
|
31 |
+
|
32 |
+
from .models import Response
|
33 |
+
from .compat import urlparse, basestring
|
34 |
+
from .utils import (DEFAULT_CA_BUNDLE_PATH, extract_zipped_paths,
|
35 |
+
get_encoding_from_headers, prepend_scheme_if_needed,
|
36 |
+
get_auth_from_url, urldefragauth, select_proxy)
|
37 |
+
from .structures import CaseInsensitiveDict
|
38 |
+
from .cookies import extract_cookies_to_jar
|
39 |
+
from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,
|
40 |
+
ProxyError, RetryError, InvalidSchema, InvalidProxyURL,
|
41 |
+
InvalidURL, InvalidHeader)
|
42 |
+
from .auth import _basic_auth_str
|
43 |
+
|
44 |
+
try:
|
45 |
+
from pip._vendor.urllib3.contrib.socks import SOCKSProxyManager
|
46 |
+
except ImportError:
|
47 |
+
def SOCKSProxyManager(*args, **kwargs):
|
48 |
+
raise InvalidSchema("Missing dependencies for SOCKS support.")
|
49 |
+
|
50 |
+
DEFAULT_POOLBLOCK = False
|
51 |
+
DEFAULT_POOLSIZE = 10
|
52 |
+
DEFAULT_RETRIES = 0
|
53 |
+
DEFAULT_POOL_TIMEOUT = None
|
54 |
+
|
55 |
+
|
56 |
+
class BaseAdapter(object):
|
57 |
+
"""The Base Transport Adapter"""
|
58 |
+
|
59 |
+
def __init__(self):
|
60 |
+
super(BaseAdapter, self).__init__()
|
61 |
+
|
62 |
+
def send(self, request, stream=False, timeout=None, verify=True,
|
63 |
+
cert=None, proxies=None):
|
64 |
+
"""Sends PreparedRequest object. Returns Response object.
|
65 |
+
|
66 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
67 |
+
:param stream: (optional) Whether to stream the request content.
|
68 |
+
:param timeout: (optional) How long to wait for the server to send
|
69 |
+
data before giving up, as a float, or a :ref:`(connect timeout,
|
70 |
+
read timeout) <timeouts>` tuple.
|
71 |
+
:type timeout: float or tuple
|
72 |
+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
|
73 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
74 |
+
to a CA bundle to use
|
75 |
+
:param cert: (optional) Any user-provided SSL certificate to be trusted.
|
76 |
+
:param proxies: (optional) The proxies dictionary to apply to the request.
|
77 |
+
"""
|
78 |
+
raise NotImplementedError
|
79 |
+
|
80 |
+
def close(self):
|
81 |
+
"""Cleans up adapter specific items."""
|
82 |
+
raise NotImplementedError
|
83 |
+
|
84 |
+
|
85 |
+
class HTTPAdapter(BaseAdapter):
|
86 |
+
"""The built-in HTTP Adapter for urllib3.
|
87 |
+
|
88 |
+
Provides a general-case interface for Requests sessions to contact HTTP and
|
89 |
+
HTTPS urls by implementing the Transport Adapter interface. This class will
|
90 |
+
usually be created by the :class:`Session <Session>` class under the
|
91 |
+
covers.
|
92 |
+
|
93 |
+
:param pool_connections: The number of urllib3 connection pools to cache.
|
94 |
+
:param pool_maxsize: The maximum number of connections to save in the pool.
|
95 |
+
:param max_retries: The maximum number of retries each connection
|
96 |
+
should attempt. Note, this applies only to failed DNS lookups, socket
|
97 |
+
connections and connection timeouts, never to requests where data has
|
98 |
+
made it to the server. By default, Requests does not retry failed
|
99 |
+
connections. If you need granular control over the conditions under
|
100 |
+
which we retry a request, import urllib3's ``Retry`` class and pass
|
101 |
+
that instead.
|
102 |
+
:param pool_block: Whether the connection pool should block for connections.
|
103 |
+
|
104 |
+
Usage::
|
105 |
+
|
106 |
+
>>> import requests
|
107 |
+
>>> s = requests.Session()
|
108 |
+
>>> a = requests.adapters.HTTPAdapter(max_retries=3)
|
109 |
+
>>> s.mount('http://', a)
|
110 |
+
"""
|
111 |
+
__attrs__ = ['max_retries', 'config', '_pool_connections', '_pool_maxsize',
|
112 |
+
'_pool_block']
|
113 |
+
|
114 |
+
def __init__(self, pool_connections=DEFAULT_POOLSIZE,
|
115 |
+
pool_maxsize=DEFAULT_POOLSIZE, max_retries=DEFAULT_RETRIES,
|
116 |
+
pool_block=DEFAULT_POOLBLOCK):
|
117 |
+
if max_retries == DEFAULT_RETRIES:
|
118 |
+
self.max_retries = Retry(0, read=False)
|
119 |
+
else:
|
120 |
+
self.max_retries = Retry.from_int(max_retries)
|
121 |
+
self.config = {}
|
122 |
+
self.proxy_manager = {}
|
123 |
+
|
124 |
+
super(HTTPAdapter, self).__init__()
|
125 |
+
|
126 |
+
self._pool_connections = pool_connections
|
127 |
+
self._pool_maxsize = pool_maxsize
|
128 |
+
self._pool_block = pool_block
|
129 |
+
|
130 |
+
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
|
131 |
+
|
132 |
+
def __getstate__(self):
|
133 |
+
return {attr: getattr(self, attr, None) for attr in self.__attrs__}
|
134 |
+
|
135 |
+
def __setstate__(self, state):
|
136 |
+
# Can't handle by adding 'proxy_manager' to self.__attrs__ because
|
137 |
+
# self.poolmanager uses a lambda function, which isn't pickleable.
|
138 |
+
self.proxy_manager = {}
|
139 |
+
self.config = {}
|
140 |
+
|
141 |
+
for attr, value in state.items():
|
142 |
+
setattr(self, attr, value)
|
143 |
+
|
144 |
+
self.init_poolmanager(self._pool_connections, self._pool_maxsize,
|
145 |
+
block=self._pool_block)
|
146 |
+
|
147 |
+
def init_poolmanager(self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs):
|
148 |
+
"""Initializes a urllib3 PoolManager.
|
149 |
+
|
150 |
+
This method should not be called from user code, and is only
|
151 |
+
exposed for use when subclassing the
|
152 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
153 |
+
|
154 |
+
:param connections: The number of urllib3 connection pools to cache.
|
155 |
+
:param maxsize: The maximum number of connections to save in the pool.
|
156 |
+
:param block: Block when no free connections are available.
|
157 |
+
:param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
|
158 |
+
"""
|
159 |
+
# save these values for pickling
|
160 |
+
self._pool_connections = connections
|
161 |
+
self._pool_maxsize = maxsize
|
162 |
+
self._pool_block = block
|
163 |
+
|
164 |
+
self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize,
|
165 |
+
block=block, strict=True, **pool_kwargs)
|
166 |
+
|
167 |
+
def proxy_manager_for(self, proxy, **proxy_kwargs):
|
168 |
+
"""Return urllib3 ProxyManager for the given proxy.
|
169 |
+
|
170 |
+
This method should not be called from user code, and is only
|
171 |
+
exposed for use when subclassing the
|
172 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
173 |
+
|
174 |
+
:param proxy: The proxy to return a urllib3 ProxyManager for.
|
175 |
+
:param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
|
176 |
+
:returns: ProxyManager
|
177 |
+
:rtype: urllib3.ProxyManager
|
178 |
+
"""
|
179 |
+
if proxy in self.proxy_manager:
|
180 |
+
manager = self.proxy_manager[proxy]
|
181 |
+
elif proxy.lower().startswith('socks'):
|
182 |
+
username, password = get_auth_from_url(proxy)
|
183 |
+
manager = self.proxy_manager[proxy] = SOCKSProxyManager(
|
184 |
+
proxy,
|
185 |
+
username=username,
|
186 |
+
password=password,
|
187 |
+
num_pools=self._pool_connections,
|
188 |
+
maxsize=self._pool_maxsize,
|
189 |
+
block=self._pool_block,
|
190 |
+
**proxy_kwargs
|
191 |
+
)
|
192 |
+
else:
|
193 |
+
proxy_headers = self.proxy_headers(proxy)
|
194 |
+
manager = self.proxy_manager[proxy] = proxy_from_url(
|
195 |
+
proxy,
|
196 |
+
proxy_headers=proxy_headers,
|
197 |
+
num_pools=self._pool_connections,
|
198 |
+
maxsize=self._pool_maxsize,
|
199 |
+
block=self._pool_block,
|
200 |
+
**proxy_kwargs)
|
201 |
+
|
202 |
+
return manager
|
203 |
+
|
204 |
+
def cert_verify(self, conn, url, verify, cert):
|
205 |
+
"""Verify a SSL certificate. This method should not be called from user
|
206 |
+
code, and is only exposed for use when subclassing the
|
207 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
208 |
+
|
209 |
+
:param conn: The urllib3 connection object associated with the cert.
|
210 |
+
:param url: The requested URL.
|
211 |
+
:param verify: Either a boolean, in which case it controls whether we verify
|
212 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
213 |
+
to a CA bundle to use
|
214 |
+
:param cert: The SSL certificate to verify.
|
215 |
+
"""
|
216 |
+
if url.lower().startswith('https') and verify:
|
217 |
+
|
218 |
+
cert_loc = None
|
219 |
+
|
220 |
+
# Allow self-specified cert location.
|
221 |
+
if verify is not True:
|
222 |
+
cert_loc = verify
|
223 |
+
|
224 |
+
if not cert_loc:
|
225 |
+
cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
|
226 |
+
|
227 |
+
if not cert_loc or not os.path.exists(cert_loc):
|
228 |
+
raise IOError("Could not find a suitable TLS CA certificate bundle, "
|
229 |
+
"invalid path: {}".format(cert_loc))
|
230 |
+
|
231 |
+
conn.cert_reqs = 'CERT_REQUIRED'
|
232 |
+
|
233 |
+
if not os.path.isdir(cert_loc):
|
234 |
+
conn.ca_certs = cert_loc
|
235 |
+
else:
|
236 |
+
conn.ca_cert_dir = cert_loc
|
237 |
+
else:
|
238 |
+
conn.cert_reqs = 'CERT_NONE'
|
239 |
+
conn.ca_certs = None
|
240 |
+
conn.ca_cert_dir = None
|
241 |
+
|
242 |
+
if cert:
|
243 |
+
if not isinstance(cert, basestring):
|
244 |
+
conn.cert_file = cert[0]
|
245 |
+
conn.key_file = cert[1]
|
246 |
+
else:
|
247 |
+
conn.cert_file = cert
|
248 |
+
conn.key_file = None
|
249 |
+
if conn.cert_file and not os.path.exists(conn.cert_file):
|
250 |
+
raise IOError("Could not find the TLS certificate file, "
|
251 |
+
"invalid path: {}".format(conn.cert_file))
|
252 |
+
if conn.key_file and not os.path.exists(conn.key_file):
|
253 |
+
raise IOError("Could not find the TLS key file, "
|
254 |
+
"invalid path: {}".format(conn.key_file))
|
255 |
+
|
256 |
+
def build_response(self, req, resp):
|
257 |
+
"""Builds a :class:`Response <requests.Response>` object from a urllib3
|
258 |
+
response. This should not be called from user code, and is only exposed
|
259 |
+
for use when subclassing the
|
260 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
|
261 |
+
|
262 |
+
:param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
|
263 |
+
:param resp: The urllib3 response object.
|
264 |
+
:rtype: requests.Response
|
265 |
+
"""
|
266 |
+
response = Response()
|
267 |
+
|
268 |
+
# Fallback to None if there's no status_code, for whatever reason.
|
269 |
+
response.status_code = getattr(resp, 'status', None)
|
270 |
+
|
271 |
+
# Make headers case-insensitive.
|
272 |
+
response.headers = CaseInsensitiveDict(getattr(resp, 'headers', {}))
|
273 |
+
|
274 |
+
# Set encoding.
|
275 |
+
response.encoding = get_encoding_from_headers(response.headers)
|
276 |
+
response.raw = resp
|
277 |
+
response.reason = response.raw.reason
|
278 |
+
|
279 |
+
if isinstance(req.url, bytes):
|
280 |
+
response.url = req.url.decode('utf-8')
|
281 |
+
else:
|
282 |
+
response.url = req.url
|
283 |
+
|
284 |
+
# Add new cookies from the server.
|
285 |
+
extract_cookies_to_jar(response.cookies, req, resp)
|
286 |
+
|
287 |
+
# Give the Response some context.
|
288 |
+
response.request = req
|
289 |
+
response.connection = self
|
290 |
+
|
291 |
+
return response
|
292 |
+
|
293 |
+
def get_connection(self, url, proxies=None):
|
294 |
+
"""Returns a urllib3 connection for the given URL. This should not be
|
295 |
+
called from user code, and is only exposed for use when subclassing the
|
296 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
297 |
+
|
298 |
+
:param url: The URL to connect to.
|
299 |
+
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
|
300 |
+
:rtype: urllib3.ConnectionPool
|
301 |
+
"""
|
302 |
+
proxy = select_proxy(url, proxies)
|
303 |
+
|
304 |
+
if proxy:
|
305 |
+
proxy = prepend_scheme_if_needed(proxy, 'http')
|
306 |
+
proxy_url = parse_url(proxy)
|
307 |
+
if not proxy_url.host:
|
308 |
+
raise InvalidProxyURL("Please check proxy URL. It is malformed"
|
309 |
+
" and could be missing the host.")
|
310 |
+
proxy_manager = self.proxy_manager_for(proxy)
|
311 |
+
conn = proxy_manager.connection_from_url(url)
|
312 |
+
else:
|
313 |
+
# Only scheme should be lower case
|
314 |
+
parsed = urlparse(url)
|
315 |
+
url = parsed.geturl()
|
316 |
+
conn = self.poolmanager.connection_from_url(url)
|
317 |
+
|
318 |
+
return conn
|
319 |
+
|
320 |
+
def close(self):
|
321 |
+
"""Disposes of any internal state.
|
322 |
+
|
323 |
+
Currently, this closes the PoolManager and any active ProxyManager,
|
324 |
+
which closes any pooled connections.
|
325 |
+
"""
|
326 |
+
self.poolmanager.clear()
|
327 |
+
for proxy in self.proxy_manager.values():
|
328 |
+
proxy.clear()
|
329 |
+
|
330 |
+
def request_url(self, request, proxies):
|
331 |
+
"""Obtain the url to use when making the final request.
|
332 |
+
|
333 |
+
If the message is being sent through a HTTP proxy, the full URL has to
|
334 |
+
be used. Otherwise, we should only use the path portion of the URL.
|
335 |
+
|
336 |
+
This should not be called from user code, and is only exposed for use
|
337 |
+
when subclassing the
|
338 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
339 |
+
|
340 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
341 |
+
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
|
342 |
+
:rtype: str
|
343 |
+
"""
|
344 |
+
proxy = select_proxy(request.url, proxies)
|
345 |
+
scheme = urlparse(request.url).scheme
|
346 |
+
|
347 |
+
is_proxied_http_request = (proxy and scheme != 'https')
|
348 |
+
using_socks_proxy = False
|
349 |
+
if proxy:
|
350 |
+
proxy_scheme = urlparse(proxy).scheme.lower()
|
351 |
+
using_socks_proxy = proxy_scheme.startswith('socks')
|
352 |
+
|
353 |
+
url = request.path_url
|
354 |
+
if is_proxied_http_request and not using_socks_proxy:
|
355 |
+
url = urldefragauth(request.url)
|
356 |
+
|
357 |
+
return url
|
358 |
+
|
359 |
+
def add_headers(self, request, **kwargs):
|
360 |
+
"""Add any headers needed by the connection. As of v2.0 this does
|
361 |
+
nothing by default, but is left for overriding by users that subclass
|
362 |
+
the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
363 |
+
|
364 |
+
This should not be called from user code, and is only exposed for use
|
365 |
+
when subclassing the
|
366 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
367 |
+
|
368 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
|
369 |
+
:param kwargs: The keyword arguments from the call to send().
|
370 |
+
"""
|
371 |
+
pass
|
372 |
+
|
373 |
+
def proxy_headers(self, proxy):
|
374 |
+
"""Returns a dictionary of the headers to add to any request sent
|
375 |
+
through a proxy. This works with urllib3 magic to ensure that they are
|
376 |
+
correctly sent to the proxy, rather than in a tunnelled request if
|
377 |
+
CONNECT is being used.
|
378 |
+
|
379 |
+
This should not be called from user code, and is only exposed for use
|
380 |
+
when subclassing the
|
381 |
+
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
|
382 |
+
|
383 |
+
:param proxy: The url of the proxy being used for this request.
|
384 |
+
:rtype: dict
|
385 |
+
"""
|
386 |
+
headers = {}
|
387 |
+
username, password = get_auth_from_url(proxy)
|
388 |
+
|
389 |
+
if username:
|
390 |
+
headers['Proxy-Authorization'] = _basic_auth_str(username,
|
391 |
+
password)
|
392 |
+
|
393 |
+
return headers
|
394 |
+
|
395 |
+
def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
|
396 |
+
"""Sends PreparedRequest object. Returns Response object.
|
397 |
+
|
398 |
+
:param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
|
399 |
+
:param stream: (optional) Whether to stream the request content.
|
400 |
+
:param timeout: (optional) How long to wait for the server to send
|
401 |
+
data before giving up, as a float, or a :ref:`(connect timeout,
|
402 |
+
read timeout) <timeouts>` tuple.
|
403 |
+
:type timeout: float or tuple or urllib3 Timeout object
|
404 |
+
:param verify: (optional) Either a boolean, in which case it controls whether
|
405 |
+
we verify the server's TLS certificate, or a string, in which case it
|
406 |
+
must be a path to a CA bundle to use
|
407 |
+
:param cert: (optional) Any user-provided SSL certificate to be trusted.
|
408 |
+
:param proxies: (optional) The proxies dictionary to apply to the request.
|
409 |
+
:rtype: requests.Response
|
410 |
+
"""
|
411 |
+
|
412 |
+
try:
|
413 |
+
conn = self.get_connection(request.url, proxies)
|
414 |
+
except LocationValueError as e:
|
415 |
+
raise InvalidURL(e, request=request)
|
416 |
+
|
417 |
+
self.cert_verify(conn, request.url, verify, cert)
|
418 |
+
url = self.request_url(request, proxies)
|
419 |
+
self.add_headers(request, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
|
420 |
+
|
421 |
+
chunked = not (request.body is None or 'Content-Length' in request.headers)
|
422 |
+
|
423 |
+
if isinstance(timeout, tuple):
|
424 |
+
try:
|
425 |
+
connect, read = timeout
|
426 |
+
timeout = TimeoutSauce(connect=connect, read=read)
|
427 |
+
except ValueError as e:
|
428 |
+
# this may raise a string formatting error.
|
429 |
+
err = ("Invalid timeout {}. Pass a (connect, read) "
|
430 |
+
"timeout tuple, or a single float to set "
|
431 |
+
"both timeouts to the same value".format(timeout))
|
432 |
+
raise ValueError(err)
|
433 |
+
elif isinstance(timeout, TimeoutSauce):
|
434 |
+
pass
|
435 |
+
else:
|
436 |
+
timeout = TimeoutSauce(connect=timeout, read=timeout)
|
437 |
+
|
438 |
+
try:
|
439 |
+
if not chunked:
|
440 |
+
resp = conn.urlopen(
|
441 |
+
method=request.method,
|
442 |
+
url=url,
|
443 |
+
body=request.body,
|
444 |
+
headers=request.headers,
|
445 |
+
redirect=False,
|
446 |
+
assert_same_host=False,
|
447 |
+
preload_content=False,
|
448 |
+
decode_content=False,
|
449 |
+
retries=self.max_retries,
|
450 |
+
timeout=timeout
|
451 |
+
)
|
452 |
+
|
453 |
+
# Send the request.
|
454 |
+
else:
|
455 |
+
if hasattr(conn, 'proxy_pool'):
|
456 |
+
conn = conn.proxy_pool
|
457 |
+
|
458 |
+
low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)
|
459 |
+
|
460 |
+
try:
|
461 |
+
skip_host = 'Host' in request.headers
|
462 |
+
low_conn.putrequest(request.method,
|
463 |
+
url,
|
464 |
+
skip_accept_encoding=True,
|
465 |
+
skip_host=skip_host)
|
466 |
+
|
467 |
+
for header, value in request.headers.items():
|
468 |
+
low_conn.putheader(header, value)
|
469 |
+
|
470 |
+
low_conn.endheaders()
|
471 |
+
|
472 |
+
for i in request.body:
|
473 |
+
low_conn.send(hex(len(i))[2:].encode('utf-8'))
|
474 |
+
low_conn.send(b'\r\n')
|
475 |
+
low_conn.send(i)
|
476 |
+
low_conn.send(b'\r\n')
|
477 |
+
low_conn.send(b'0\r\n\r\n')
|
478 |
+
|
479 |
+
# Receive the response from the server
|
480 |
+
try:
|
481 |
+
# For Python 2.7, use buffering of HTTP responses
|
482 |
+
r = low_conn.getresponse(buffering=True)
|
483 |
+
except TypeError:
|
484 |
+
# For compatibility with Python 3.3+
|
485 |
+
r = low_conn.getresponse()
|
486 |
+
|
487 |
+
resp = HTTPResponse.from_httplib(
|
488 |
+
r,
|
489 |
+
pool=conn,
|
490 |
+
connection=low_conn,
|
491 |
+
preload_content=False,
|
492 |
+
decode_content=False
|
493 |
+
)
|
494 |
+
except:
|
495 |
+
# If we hit any problems here, clean up the connection.
|
496 |
+
# Then, reraise so that we can handle the actual exception.
|
497 |
+
low_conn.close()
|
498 |
+
raise
|
499 |
+
|
500 |
+
except (ProtocolError, socket.error) 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/pip/_vendor/requests/api.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.api
|
5 |
+
~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module implements the Requests API.
|
8 |
+
|
9 |
+
:copyright: (c) 2012 by Kenneth Reitz.
|
10 |
+
:license: Apache2, see LICENSE for more details.
|
11 |
+
"""
|
12 |
+
|
13 |
+
from . import sessions
|
14 |
+
|
15 |
+
|
16 |
+
def request(method, url, **kwargs):
|
17 |
+
"""Constructs and sends a :class:`Request <Request>`.
|
18 |
+
|
19 |
+
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
|
20 |
+
:param url: URL for the new :class:`Request` object.
|
21 |
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
22 |
+
in the query string for the :class:`Request`.
|
23 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
24 |
+
object to send in the body of the :class:`Request`.
|
25 |
+
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
|
26 |
+
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
|
27 |
+
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
|
28 |
+
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
|
29 |
+
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
|
30 |
+
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
|
31 |
+
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
|
32 |
+
to add for the file.
|
33 |
+
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
|
34 |
+
:param timeout: (optional) How many seconds to wait for the server to send data
|
35 |
+
before giving up, as a float, or a :ref:`(connect timeout, read
|
36 |
+
timeout) <timeouts>` tuple.
|
37 |
+
:type timeout: float or tuple
|
38 |
+
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
|
39 |
+
:type allow_redirects: bool
|
40 |
+
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
|
41 |
+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
|
42 |
+
the server's TLS certificate, or a string, in which case it must be a path
|
43 |
+
to a CA bundle to use. Defaults to ``True``.
|
44 |
+
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
|
45 |
+
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
|
46 |
+
:return: :class:`Response <Response>` object
|
47 |
+
:rtype: requests.Response
|
48 |
+
|
49 |
+
Usage::
|
50 |
+
|
51 |
+
>>> import requests
|
52 |
+
>>> req = requests.request('GET', 'https://httpbin.org/get')
|
53 |
+
>>> req
|
54 |
+
<Response [200]>
|
55 |
+
"""
|
56 |
+
|
57 |
+
# By using the 'with' statement we are sure the session is closed, thus we
|
58 |
+
# avoid leaving sockets open which can trigger a ResourceWarning in some
|
59 |
+
# cases, and look like a memory leak in others.
|
60 |
+
with sessions.Session() as session:
|
61 |
+
return session.request(method=method, url=url, **kwargs)
|
62 |
+
|
63 |
+
|
64 |
+
def get(url, params=None, **kwargs):
|
65 |
+
r"""Sends a GET request.
|
66 |
+
|
67 |
+
:param url: URL for the new :class:`Request` object.
|
68 |
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
69 |
+
in the query string for the :class:`Request`.
|
70 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
71 |
+
:return: :class:`Response <Response>` object
|
72 |
+
:rtype: requests.Response
|
73 |
+
"""
|
74 |
+
|
75 |
+
return request('get', url, params=params, **kwargs)
|
76 |
+
|
77 |
+
|
78 |
+
def options(url, **kwargs):
|
79 |
+
r"""Sends an OPTIONS request.
|
80 |
+
|
81 |
+
:param url: URL for the new :class:`Request` object.
|
82 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
83 |
+
:return: :class:`Response <Response>` object
|
84 |
+
:rtype: requests.Response
|
85 |
+
"""
|
86 |
+
|
87 |
+
return request('options', url, **kwargs)
|
88 |
+
|
89 |
+
|
90 |
+
def head(url, **kwargs):
|
91 |
+
r"""Sends a HEAD request.
|
92 |
+
|
93 |
+
:param url: URL for the new :class:`Request` object.
|
94 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes. If
|
95 |
+
`allow_redirects` is not provided, it will be set to `False` (as
|
96 |
+
opposed to the default :meth:`request` behavior).
|
97 |
+
:return: :class:`Response <Response>` object
|
98 |
+
:rtype: requests.Response
|
99 |
+
"""
|
100 |
+
|
101 |
+
kwargs.setdefault('allow_redirects', False)
|
102 |
+
return request('head', url, **kwargs)
|
103 |
+
|
104 |
+
|
105 |
+
def post(url, data=None, json=None, **kwargs):
|
106 |
+
r"""Sends a POST request.
|
107 |
+
|
108 |
+
:param url: URL for the new :class:`Request` object.
|
109 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
110 |
+
object to send in the body of the :class:`Request`.
|
111 |
+
:param json: (optional) json data to send in the body of the :class:`Request`.
|
112 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
113 |
+
:return: :class:`Response <Response>` object
|
114 |
+
:rtype: requests.Response
|
115 |
+
"""
|
116 |
+
|
117 |
+
return request('post', url, data=data, json=json, **kwargs)
|
118 |
+
|
119 |
+
|
120 |
+
def put(url, data=None, **kwargs):
|
121 |
+
r"""Sends a PUT request.
|
122 |
+
|
123 |
+
:param url: URL for the new :class:`Request` object.
|
124 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
125 |
+
object to send in the body of the :class:`Request`.
|
126 |
+
:param json: (optional) json data to send in the body of the :class:`Request`.
|
127 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
128 |
+
:return: :class:`Response <Response>` object
|
129 |
+
:rtype: requests.Response
|
130 |
+
"""
|
131 |
+
|
132 |
+
return request('put', url, data=data, **kwargs)
|
133 |
+
|
134 |
+
|
135 |
+
def patch(url, data=None, **kwargs):
|
136 |
+
r"""Sends a PATCH request.
|
137 |
+
|
138 |
+
:param url: URL for the new :class:`Request` object.
|
139 |
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
140 |
+
object to send in the body of the :class:`Request`.
|
141 |
+
:param json: (optional) json data to send in the body of the :class:`Request`.
|
142 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
143 |
+
:return: :class:`Response <Response>` object
|
144 |
+
:rtype: requests.Response
|
145 |
+
"""
|
146 |
+
|
147 |
+
return request('patch', url, data=data, **kwargs)
|
148 |
+
|
149 |
+
|
150 |
+
def delete(url, **kwargs):
|
151 |
+
r"""Sends a DELETE request.
|
152 |
+
|
153 |
+
:param url: URL for the new :class:`Request` object.
|
154 |
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
155 |
+
:return: :class:`Response <Response>` object
|
156 |
+
:rtype: requests.Response
|
157 |
+
"""
|
158 |
+
|
159 |
+
return request('delete', url, **kwargs)
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/auth.py
ADDED
@@ -0,0 +1,305 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.auth
|
5 |
+
~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module contains the authentication handlers for Requests.
|
8 |
+
"""
|
9 |
+
|
10 |
+
import os
|
11 |
+
import re
|
12 |
+
import time
|
13 |
+
import hashlib
|
14 |
+
import threading
|
15 |
+
import warnings
|
16 |
+
|
17 |
+
from base64 import b64encode
|
18 |
+
|
19 |
+
from .compat import urlparse, str, basestring
|
20 |
+
from .cookies import extract_cookies_to_jar
|
21 |
+
from ._internal_utils import to_native_string
|
22 |
+
from .utils import parse_dict_header
|
23 |
+
|
24 |
+
CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
|
25 |
+
CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
|
26 |
+
|
27 |
+
|
28 |
+
def _basic_auth_str(username, password):
|
29 |
+
"""Returns a Basic Auth string."""
|
30 |
+
|
31 |
+
# "I want us to put a big-ol' comment on top of it that
|
32 |
+
# says that this behaviour is dumb but we need to preserve
|
33 |
+
# it because people are relying on it."
|
34 |
+
# - Lukasa
|
35 |
+
#
|
36 |
+
# These are here solely to maintain backwards compatibility
|
37 |
+
# for things like ints. This will be removed in 3.0.0.
|
38 |
+
if not isinstance(username, basestring):
|
39 |
+
warnings.warn(
|
40 |
+
"Non-string usernames will no longer be supported in Requests "
|
41 |
+
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
42 |
+
"a string or bytes object in the near future to avoid "
|
43 |
+
"problems.".format(username),
|
44 |
+
category=DeprecationWarning,
|
45 |
+
)
|
46 |
+
username = str(username)
|
47 |
+
|
48 |
+
if not isinstance(password, basestring):
|
49 |
+
warnings.warn(
|
50 |
+
"Non-string passwords will no longer be supported in Requests "
|
51 |
+
"3.0.0. Please convert the object you've passed in ({!r}) to "
|
52 |
+
"a string or bytes object in the near future to avoid "
|
53 |
+
"problems.".format(type(password)),
|
54 |
+
category=DeprecationWarning,
|
55 |
+
)
|
56 |
+
password = str(password)
|
57 |
+
# -- End Removal --
|
58 |
+
|
59 |
+
if isinstance(username, str):
|
60 |
+
username = username.encode('latin1')
|
61 |
+
|
62 |
+
if isinstance(password, str):
|
63 |
+
password = password.encode('latin1')
|
64 |
+
|
65 |
+
authstr = 'Basic ' + to_native_string(
|
66 |
+
b64encode(b':'.join((username, password))).strip()
|
67 |
+
)
|
68 |
+
|
69 |
+
return authstr
|
70 |
+
|
71 |
+
|
72 |
+
class AuthBase(object):
|
73 |
+
"""Base class that all auth implementations derive from"""
|
74 |
+
|
75 |
+
def __call__(self, r):
|
76 |
+
raise NotImplementedError('Auth hooks must be callable.')
|
77 |
+
|
78 |
+
|
79 |
+
class HTTPBasicAuth(AuthBase):
|
80 |
+
"""Attaches HTTP Basic Authentication to the given Request object."""
|
81 |
+
|
82 |
+
def __init__(self, username, password):
|
83 |
+
self.username = username
|
84 |
+
self.password = password
|
85 |
+
|
86 |
+
def __eq__(self, other):
|
87 |
+
return all([
|
88 |
+
self.username == getattr(other, 'username', None),
|
89 |
+
self.password == getattr(other, 'password', None)
|
90 |
+
])
|
91 |
+
|
92 |
+
def __ne__(self, other):
|
93 |
+
return not self == other
|
94 |
+
|
95 |
+
def __call__(self, r):
|
96 |
+
r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
|
97 |
+
return r
|
98 |
+
|
99 |
+
|
100 |
+
class HTTPProxyAuth(HTTPBasicAuth):
|
101 |
+
"""Attaches HTTP Proxy Authentication to a given Request object."""
|
102 |
+
|
103 |
+
def __call__(self, r):
|
104 |
+
r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)
|
105 |
+
return r
|
106 |
+
|
107 |
+
|
108 |
+
class HTTPDigestAuth(AuthBase):
|
109 |
+
"""Attaches HTTP Digest Authentication to the given Request object."""
|
110 |
+
|
111 |
+
def __init__(self, username, password):
|
112 |
+
self.username = username
|
113 |
+
self.password = password
|
114 |
+
# Keep state in per-thread local storage
|
115 |
+
self._thread_local = threading.local()
|
116 |
+
|
117 |
+
def init_per_thread_state(self):
|
118 |
+
# Ensure state is initialized just once per-thread
|
119 |
+
if not hasattr(self._thread_local, 'init'):
|
120 |
+
self._thread_local.init = True
|
121 |
+
self._thread_local.last_nonce = ''
|
122 |
+
self._thread_local.nonce_count = 0
|
123 |
+
self._thread_local.chal = {}
|
124 |
+
self._thread_local.pos = None
|
125 |
+
self._thread_local.num_401_calls = None
|
126 |
+
|
127 |
+
def build_digest_header(self, method, url):
|
128 |
+
"""
|
129 |
+
:rtype: str
|
130 |
+
"""
|
131 |
+
|
132 |
+
realm = self._thread_local.chal['realm']
|
133 |
+
nonce = self._thread_local.chal['nonce']
|
134 |
+
qop = self._thread_local.chal.get('qop')
|
135 |
+
algorithm = self._thread_local.chal.get('algorithm')
|
136 |
+
opaque = self._thread_local.chal.get('opaque')
|
137 |
+
hash_utf8 = None
|
138 |
+
|
139 |
+
if algorithm is None:
|
140 |
+
_algorithm = 'MD5'
|
141 |
+
else:
|
142 |
+
_algorithm = algorithm.upper()
|
143 |
+
# lambdas assume digest modules are imported at the top level
|
144 |
+
if _algorithm == 'MD5' or _algorithm == 'MD5-SESS':
|
145 |
+
def md5_utf8(x):
|
146 |
+
if isinstance(x, str):
|
147 |
+
x = x.encode('utf-8')
|
148 |
+
return hashlib.md5(x).hexdigest()
|
149 |
+
hash_utf8 = md5_utf8
|
150 |
+
elif _algorithm == 'SHA':
|
151 |
+
def sha_utf8(x):
|
152 |
+
if isinstance(x, str):
|
153 |
+
x = x.encode('utf-8')
|
154 |
+
return hashlib.sha1(x).hexdigest()
|
155 |
+
hash_utf8 = sha_utf8
|
156 |
+
elif _algorithm == 'SHA-256':
|
157 |
+
def sha256_utf8(x):
|
158 |
+
if isinstance(x, str):
|
159 |
+
x = x.encode('utf-8')
|
160 |
+
return hashlib.sha256(x).hexdigest()
|
161 |
+
hash_utf8 = sha256_utf8
|
162 |
+
elif _algorithm == 'SHA-512':
|
163 |
+
def sha512_utf8(x):
|
164 |
+
if isinstance(x, str):
|
165 |
+
x = x.encode('utf-8')
|
166 |
+
return hashlib.sha512(x).hexdigest()
|
167 |
+
hash_utf8 = sha512_utf8
|
168 |
+
|
169 |
+
KD = lambda s, d: hash_utf8("%s:%s" % (s, d))
|
170 |
+
|
171 |
+
if hash_utf8 is None:
|
172 |
+
return None
|
173 |
+
|
174 |
+
# XXX not implemented yet
|
175 |
+
entdig = None
|
176 |
+
p_parsed = urlparse(url)
|
177 |
+
#: path is request-uri defined in RFC 2616 which should not be empty
|
178 |
+
path = p_parsed.path or "/"
|
179 |
+
if p_parsed.query:
|
180 |
+
path += '?' + p_parsed.query
|
181 |
+
|
182 |
+
A1 = '%s:%s:%s' % (self.username, realm, self.password)
|
183 |
+
A2 = '%s:%s' % (method, path)
|
184 |
+
|
185 |
+
HA1 = hash_utf8(A1)
|
186 |
+
HA2 = hash_utf8(A2)
|
187 |
+
|
188 |
+
if nonce == self._thread_local.last_nonce:
|
189 |
+
self._thread_local.nonce_count += 1
|
190 |
+
else:
|
191 |
+
self._thread_local.nonce_count = 1
|
192 |
+
ncvalue = '%08x' % self._thread_local.nonce_count
|
193 |
+
s = str(self._thread_local.nonce_count).encode('utf-8')
|
194 |
+
s += nonce.encode('utf-8')
|
195 |
+
s += time.ctime().encode('utf-8')
|
196 |
+
s += os.urandom(8)
|
197 |
+
|
198 |
+
cnonce = (hashlib.sha1(s).hexdigest()[:16])
|
199 |
+
if _algorithm == 'MD5-SESS':
|
200 |
+
HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce))
|
201 |
+
|
202 |
+
if not qop:
|
203 |
+
respdig = KD(HA1, "%s:%s" % (nonce, HA2))
|
204 |
+
elif qop == 'auth' or 'auth' in qop.split(','):
|
205 |
+
noncebit = "%s:%s:%s:%s:%s" % (
|
206 |
+
nonce, ncvalue, cnonce, 'auth', HA2
|
207 |
+
)
|
208 |
+
respdig = KD(HA1, noncebit)
|
209 |
+
else:
|
210 |
+
# XXX handle auth-int.
|
211 |
+
return None
|
212 |
+
|
213 |
+
self._thread_local.last_nonce = nonce
|
214 |
+
|
215 |
+
# XXX should the partial digests be encoded too?
|
216 |
+
base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
|
217 |
+
'response="%s"' % (self.username, realm, nonce, path, respdig)
|
218 |
+
if opaque:
|
219 |
+
base += ', opaque="%s"' % opaque
|
220 |
+
if algorithm:
|
221 |
+
base += ', algorithm="%s"' % algorithm
|
222 |
+
if entdig:
|
223 |
+
base += ', digest="%s"' % entdig
|
224 |
+
if qop:
|
225 |
+
base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce)
|
226 |
+
|
227 |
+
return 'Digest %s' % (base)
|
228 |
+
|
229 |
+
def handle_redirect(self, r, **kwargs):
|
230 |
+
"""Reset num_401_calls counter on redirects."""
|
231 |
+
if r.is_redirect:
|
232 |
+
self._thread_local.num_401_calls = 1
|
233 |
+
|
234 |
+
def handle_401(self, r, **kwargs):
|
235 |
+
"""
|
236 |
+
Takes the given response and tries digest-auth, if needed.
|
237 |
+
|
238 |
+
:rtype: requests.Response
|
239 |
+
"""
|
240 |
+
|
241 |
+
# If response is not 4xx, do not auth
|
242 |
+
# See https://github.com/psf/requests/issues/3772
|
243 |
+
if not 400 <= r.status_code < 500:
|
244 |
+
self._thread_local.num_401_calls = 1
|
245 |
+
return r
|
246 |
+
|
247 |
+
if self._thread_local.pos is not None:
|
248 |
+
# Rewind the file position indicator of the body to where
|
249 |
+
# it was to resend the request.
|
250 |
+
r.request.body.seek(self._thread_local.pos)
|
251 |
+
s_auth = r.headers.get('www-authenticate', '')
|
252 |
+
|
253 |
+
if 'digest' in s_auth.lower() and self._thread_local.num_401_calls < 2:
|
254 |
+
|
255 |
+
self._thread_local.num_401_calls += 1
|
256 |
+
pat = re.compile(r'digest ', flags=re.IGNORECASE)
|
257 |
+
self._thread_local.chal = parse_dict_header(pat.sub('', s_auth, count=1))
|
258 |
+
|
259 |
+
# Consume content and release the original connection
|
260 |
+
# to allow our new request to reuse the same one.
|
261 |
+
r.content
|
262 |
+
r.close()
|
263 |
+
prep = r.request.copy()
|
264 |
+
extract_cookies_to_jar(prep._cookies, r.request, r.raw)
|
265 |
+
prep.prepare_cookies(prep._cookies)
|
266 |
+
|
267 |
+
prep.headers['Authorization'] = self.build_digest_header(
|
268 |
+
prep.method, prep.url)
|
269 |
+
_r = r.connection.send(prep, **kwargs)
|
270 |
+
_r.history.append(r)
|
271 |
+
_r.request = prep
|
272 |
+
|
273 |
+
return _r
|
274 |
+
|
275 |
+
self._thread_local.num_401_calls = 1
|
276 |
+
return r
|
277 |
+
|
278 |
+
def __call__(self, r):
|
279 |
+
# Initialize per-thread state, if needed
|
280 |
+
self.init_per_thread_state()
|
281 |
+
# If we have a saved nonce, skip the 401
|
282 |
+
if self._thread_local.last_nonce:
|
283 |
+
r.headers['Authorization'] = self.build_digest_header(r.method, r.url)
|
284 |
+
try:
|
285 |
+
self._thread_local.pos = r.body.tell()
|
286 |
+
except AttributeError:
|
287 |
+
# In the case of HTTPDigestAuth being reused and the body of
|
288 |
+
# the previous request was a file-like object, pos has the
|
289 |
+
# file position of the previous body. Ensure it's set to
|
290 |
+
# None.
|
291 |
+
self._thread_local.pos = None
|
292 |
+
r.register_hook('response', self.handle_401)
|
293 |
+
r.register_hook('response', self.handle_redirect)
|
294 |
+
self._thread_local.num_401_calls = 1
|
295 |
+
|
296 |
+
return r
|
297 |
+
|
298 |
+
def __eq__(self, other):
|
299 |
+
return all([
|
300 |
+
self.username == getattr(other, 'username', None),
|
301 |
+
self.password == getattr(other, 'password', None)
|
302 |
+
])
|
303 |
+
|
304 |
+
def __ne__(self, other):
|
305 |
+
return not self == other
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/certs.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
|
4 |
+
"""
|
5 |
+
requests.certs
|
6 |
+
~~~~~~~~~~~~~~
|
7 |
+
|
8 |
+
This module returns the preferred default CA certificate bundle. There is
|
9 |
+
only one — the one from the certifi package.
|
10 |
+
|
11 |
+
If you are packaging Requests, e.g., for a Linux distribution or a managed
|
12 |
+
environment, you can change the definition of where() to return a separately
|
13 |
+
packaged CA bundle.
|
14 |
+
"""
|
15 |
+
from pip._vendor.certifi import where
|
16 |
+
|
17 |
+
if __name__ == '__main__':
|
18 |
+
print(where())
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/compat.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.compat
|
5 |
+
~~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module handles import compatibility issues between Python 2 and
|
8 |
+
Python 3.
|
9 |
+
"""
|
10 |
+
|
11 |
+
from pip._vendor import chardet
|
12 |
+
|
13 |
+
import sys
|
14 |
+
|
15 |
+
# -------
|
16 |
+
# Pythons
|
17 |
+
# -------
|
18 |
+
|
19 |
+
# Syntax sugar.
|
20 |
+
_ver = sys.version_info
|
21 |
+
|
22 |
+
#: Python 2.x?
|
23 |
+
is_py2 = (_ver[0] == 2)
|
24 |
+
|
25 |
+
#: Python 3.x?
|
26 |
+
is_py3 = (_ver[0] == 3)
|
27 |
+
|
28 |
+
# Note: We've patched out simplejson support in pip because it prevents
|
29 |
+
# upgrading simplejson on Windows.
|
30 |
+
# try:
|
31 |
+
# import simplejson as json
|
32 |
+
# except (ImportError, SyntaxError):
|
33 |
+
# # simplejson does not support Python 3.2, it throws a SyntaxError
|
34 |
+
# # because of u'...' Unicode literals.
|
35 |
+
import json
|
36 |
+
|
37 |
+
# ---------
|
38 |
+
# Specifics
|
39 |
+
# ---------
|
40 |
+
|
41 |
+
if is_py2:
|
42 |
+
from urllib import (
|
43 |
+
quote, unquote, quote_plus, unquote_plus, urlencode, getproxies,
|
44 |
+
proxy_bypass, proxy_bypass_environment, getproxies_environment)
|
45 |
+
from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
|
46 |
+
from urllib2 import parse_http_list
|
47 |
+
import cookielib
|
48 |
+
from Cookie import Morsel
|
49 |
+
from StringIO import StringIO
|
50 |
+
# Keep OrderedDict for backwards compatibility.
|
51 |
+
from collections import Callable, Mapping, MutableMapping, OrderedDict
|
52 |
+
|
53 |
+
builtin_str = str
|
54 |
+
bytes = str
|
55 |
+
str = unicode
|
56 |
+
basestring = basestring
|
57 |
+
numeric_types = (int, long, float)
|
58 |
+
integer_types = (int, long)
|
59 |
+
JSONDecodeError = ValueError
|
60 |
+
|
61 |
+
elif is_py3:
|
62 |
+
from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
|
63 |
+
from urllib.request import parse_http_list, getproxies, proxy_bypass, proxy_bypass_environment, getproxies_environment
|
64 |
+
from http import cookiejar as cookielib
|
65 |
+
from http.cookies import Morsel
|
66 |
+
from io import StringIO
|
67 |
+
# Keep OrderedDict for backwards compatibility.
|
68 |
+
from collections import OrderedDict
|
69 |
+
from collections.abc import Callable, Mapping, MutableMapping
|
70 |
+
from json import JSONDecodeError
|
71 |
+
|
72 |
+
builtin_str = str
|
73 |
+
str = str
|
74 |
+
bytes = bytes
|
75 |
+
basestring = (str, bytes)
|
76 |
+
numeric_types = (int, float)
|
77 |
+
integer_types = (int,)
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/cookies.py
ADDED
@@ -0,0 +1,549 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.cookies
|
5 |
+
~~~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
Compatibility code to be able to use `cookielib.CookieJar` with requests.
|
8 |
+
|
9 |
+
requests.utils imports from here, so be careful with imports.
|
10 |
+
"""
|
11 |
+
|
12 |
+
import copy
|
13 |
+
import time
|
14 |
+
import calendar
|
15 |
+
|
16 |
+
from ._internal_utils import to_native_string
|
17 |
+
from .compat import cookielib, urlparse, urlunparse, Morsel, MutableMapping
|
18 |
+
|
19 |
+
try:
|
20 |
+
import threading
|
21 |
+
except ImportError:
|
22 |
+
import dummy_threading as threading
|
23 |
+
|
24 |
+
|
25 |
+
class MockRequest(object):
|
26 |
+
"""Wraps a `requests.Request` to mimic a `urllib2.Request`.
|
27 |
+
|
28 |
+
The code in `cookielib.CookieJar` expects this interface in order to correctly
|
29 |
+
manage cookie policies, i.e., determine whether a cookie can be set, given the
|
30 |
+
domains of the request and the cookie.
|
31 |
+
|
32 |
+
The original request object is read-only. The client is responsible for collecting
|
33 |
+
the new headers via `get_new_headers()` and interpreting them appropriately. You
|
34 |
+
probably want `get_cookie_header`, defined below.
|
35 |
+
"""
|
36 |
+
|
37 |
+
def __init__(self, request):
|
38 |
+
self._r = request
|
39 |
+
self._new_headers = {}
|
40 |
+
self.type = urlparse(self._r.url).scheme
|
41 |
+
|
42 |
+
def get_type(self):
|
43 |
+
return self.type
|
44 |
+
|
45 |
+
def get_host(self):
|
46 |
+
return urlparse(self._r.url).netloc
|
47 |
+
|
48 |
+
def get_origin_req_host(self):
|
49 |
+
return self.get_host()
|
50 |
+
|
51 |
+
def get_full_url(self):
|
52 |
+
# Only return the response's URL if the user hadn't set the Host
|
53 |
+
# header
|
54 |
+
if not self._r.headers.get('Host'):
|
55 |
+
return self._r.url
|
56 |
+
# If they did set it, retrieve it and reconstruct the expected domain
|
57 |
+
host = to_native_string(self._r.headers['Host'], encoding='utf-8')
|
58 |
+
parsed = urlparse(self._r.url)
|
59 |
+
# Reconstruct the URL as we expect it
|
60 |
+
return urlunparse([
|
61 |
+
parsed.scheme, host, parsed.path, parsed.params, parsed.query,
|
62 |
+
parsed.fragment
|
63 |
+
])
|
64 |
+
|
65 |
+
def is_unverifiable(self):
|
66 |
+
return True
|
67 |
+
|
68 |
+
def has_header(self, name):
|
69 |
+
return name in self._r.headers or name in self._new_headers
|
70 |
+
|
71 |
+
def get_header(self, name, default=None):
|
72 |
+
return self._r.headers.get(name, self._new_headers.get(name, default))
|
73 |
+
|
74 |
+
def add_header(self, key, val):
|
75 |
+
"""cookielib has no legitimate use for this method; add it back if you find one."""
|
76 |
+
raise NotImplementedError("Cookie headers should be added with add_unredirected_header()")
|
77 |
+
|
78 |
+
def add_unredirected_header(self, name, value):
|
79 |
+
self._new_headers[name] = value
|
80 |
+
|
81 |
+
def get_new_headers(self):
|
82 |
+
return self._new_headers
|
83 |
+
|
84 |
+
@property
|
85 |
+
def unverifiable(self):
|
86 |
+
return self.is_unverifiable()
|
87 |
+
|
88 |
+
@property
|
89 |
+
def origin_req_host(self):
|
90 |
+
return self.get_origin_req_host()
|
91 |
+
|
92 |
+
@property
|
93 |
+
def host(self):
|
94 |
+
return self.get_host()
|
95 |
+
|
96 |
+
|
97 |
+
class MockResponse(object):
|
98 |
+
"""Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
|
99 |
+
|
100 |
+
...what? Basically, expose the parsed HTTP headers from the server response
|
101 |
+
the way `cookielib` expects to see them.
|
102 |
+
"""
|
103 |
+
|
104 |
+
def __init__(self, headers):
|
105 |
+
"""Make a MockResponse for `cookielib` to read.
|
106 |
+
|
107 |
+
:param headers: a httplib.HTTPMessage or analogous carrying the headers
|
108 |
+
"""
|
109 |
+
self._headers = headers
|
110 |
+
|
111 |
+
def info(self):
|
112 |
+
return self._headers
|
113 |
+
|
114 |
+
def getheaders(self, name):
|
115 |
+
self._headers.getheaders(name)
|
116 |
+
|
117 |
+
|
118 |
+
def extract_cookies_to_jar(jar, request, response):
|
119 |
+
"""Extract the cookies from the response into a CookieJar.
|
120 |
+
|
121 |
+
:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
|
122 |
+
:param request: our own requests.Request object
|
123 |
+
:param response: urllib3.HTTPResponse object
|
124 |
+
"""
|
125 |
+
if not (hasattr(response, '_original_response') and
|
126 |
+
response._original_response):
|
127 |
+
return
|
128 |
+
# the _original_response field is the wrapped httplib.HTTPResponse object,
|
129 |
+
req = MockRequest(request)
|
130 |
+
# pull out the HTTPMessage with the headers and put it in the mock:
|
131 |
+
res = MockResponse(response._original_response.msg)
|
132 |
+
jar.extract_cookies(res, req)
|
133 |
+
|
134 |
+
|
135 |
+
def get_cookie_header(jar, request):
|
136 |
+
"""
|
137 |
+
Produce an appropriate Cookie header string to be sent with `request`, or None.
|
138 |
+
|
139 |
+
:rtype: str
|
140 |
+
"""
|
141 |
+
r = MockRequest(request)
|
142 |
+
jar.add_cookie_header(r)
|
143 |
+
return r.get_new_headers().get('Cookie')
|
144 |
+
|
145 |
+
|
146 |
+
def remove_cookie_by_name(cookiejar, name, domain=None, path=None):
|
147 |
+
"""Unsets a cookie by name, by default over all domains and paths.
|
148 |
+
|
149 |
+
Wraps CookieJar.clear(), is O(n).
|
150 |
+
"""
|
151 |
+
clearables = []
|
152 |
+
for cookie in cookiejar:
|
153 |
+
if cookie.name != name:
|
154 |
+
continue
|
155 |
+
if domain is not None and domain != cookie.domain:
|
156 |
+
continue
|
157 |
+
if path is not None and path != cookie.path:
|
158 |
+
continue
|
159 |
+
clearables.append((cookie.domain, cookie.path, cookie.name))
|
160 |
+
|
161 |
+
for domain, path, name in clearables:
|
162 |
+
cookiejar.clear(domain, path, name)
|
163 |
+
|
164 |
+
|
165 |
+
class CookieConflictError(RuntimeError):
|
166 |
+
"""There are two cookies that meet the criteria specified in the cookie jar.
|
167 |
+
Use .get and .set and include domain and path args in order to be more specific.
|
168 |
+
"""
|
169 |
+
|
170 |
+
|
171 |
+
class RequestsCookieJar(cookielib.CookieJar, MutableMapping):
|
172 |
+
"""Compatibility class; is a cookielib.CookieJar, but exposes a dict
|
173 |
+
interface.
|
174 |
+
|
175 |
+
This is the CookieJar we create by default for requests and sessions that
|
176 |
+
don't specify one, since some clients may expect response.cookies and
|
177 |
+
session.cookies to support dict operations.
|
178 |
+
|
179 |
+
Requests does not use the dict interface internally; it's just for
|
180 |
+
compatibility with external client code. All requests code should work
|
181 |
+
out of the box with externally provided instances of ``CookieJar``, e.g.
|
182 |
+
``LWPCookieJar`` and ``FileCookieJar``.
|
183 |
+
|
184 |
+
Unlike a regular CookieJar, this class is pickleable.
|
185 |
+
|
186 |
+
.. warning:: dictionary operations that are normally O(1) may be O(n).
|
187 |
+
"""
|
188 |
+
|
189 |
+
def get(self, name, default=None, domain=None, path=None):
|
190 |
+
"""Dict-like get() that also supports optional domain and path args in
|
191 |
+
order to resolve naming collisions from using one cookie jar over
|
192 |
+
multiple domains.
|
193 |
+
|
194 |
+
.. warning:: operation is O(n), not O(1).
|
195 |
+
"""
|
196 |
+
try:
|
197 |
+
return self._find_no_duplicates(name, domain, path)
|
198 |
+
except KeyError:
|
199 |
+
return default
|
200 |
+
|
201 |
+
def set(self, name, value, **kwargs):
|
202 |
+
"""Dict-like set() that also supports optional domain and path args in
|
203 |
+
order to resolve naming collisions from using one cookie jar over
|
204 |
+
multiple domains.
|
205 |
+
"""
|
206 |
+
# support client code that unsets cookies by assignment of a None value:
|
207 |
+
if value is None:
|
208 |
+
remove_cookie_by_name(self, name, domain=kwargs.get('domain'), path=kwargs.get('path'))
|
209 |
+
return
|
210 |
+
|
211 |
+
if isinstance(value, Morsel):
|
212 |
+
c = morsel_to_cookie(value)
|
213 |
+
else:
|
214 |
+
c = create_cookie(name, value, **kwargs)
|
215 |
+
self.set_cookie(c)
|
216 |
+
return c
|
217 |
+
|
218 |
+
def iterkeys(self):
|
219 |
+
"""Dict-like iterkeys() that returns an iterator of names of cookies
|
220 |
+
from the jar.
|
221 |
+
|
222 |
+
.. seealso:: itervalues() and iteritems().
|
223 |
+
"""
|
224 |
+
for cookie in iter(self):
|
225 |
+
yield cookie.name
|
226 |
+
|
227 |
+
def keys(self):
|
228 |
+
"""Dict-like keys() that returns a list of names of cookies from the
|
229 |
+
jar.
|
230 |
+
|
231 |
+
.. seealso:: values() and items().
|
232 |
+
"""
|
233 |
+
return list(self.iterkeys())
|
234 |
+
|
235 |
+
def itervalues(self):
|
236 |
+
"""Dict-like itervalues() that returns an iterator of values of cookies
|
237 |
+
from the jar.
|
238 |
+
|
239 |
+
.. seealso:: iterkeys() and iteritems().
|
240 |
+
"""
|
241 |
+
for cookie in iter(self):
|
242 |
+
yield cookie.value
|
243 |
+
|
244 |
+
def values(self):
|
245 |
+
"""Dict-like values() that returns a list of values of cookies from the
|
246 |
+
jar.
|
247 |
+
|
248 |
+
.. seealso:: keys() and items().
|
249 |
+
"""
|
250 |
+
return list(self.itervalues())
|
251 |
+
|
252 |
+
def iteritems(self):
|
253 |
+
"""Dict-like iteritems() that returns an iterator of name-value tuples
|
254 |
+
from the jar.
|
255 |
+
|
256 |
+
.. seealso:: iterkeys() and itervalues().
|
257 |
+
"""
|
258 |
+
for cookie in iter(self):
|
259 |
+
yield cookie.name, cookie.value
|
260 |
+
|
261 |
+
def items(self):
|
262 |
+
"""Dict-like items() that returns a list of name-value tuples from the
|
263 |
+
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
|
264 |
+
vanilla python dict of key value pairs.
|
265 |
+
|
266 |
+
.. seealso:: keys() and values().
|
267 |
+
"""
|
268 |
+
return list(self.iteritems())
|
269 |
+
|
270 |
+
def list_domains(self):
|
271 |
+
"""Utility method to list all the domains in the jar."""
|
272 |
+
domains = []
|
273 |
+
for cookie in iter(self):
|
274 |
+
if cookie.domain not in domains:
|
275 |
+
domains.append(cookie.domain)
|
276 |
+
return domains
|
277 |
+
|
278 |
+
def list_paths(self):
|
279 |
+
"""Utility method to list all the paths in the jar."""
|
280 |
+
paths = []
|
281 |
+
for cookie in iter(self):
|
282 |
+
if cookie.path not in paths:
|
283 |
+
paths.append(cookie.path)
|
284 |
+
return paths
|
285 |
+
|
286 |
+
def multiple_domains(self):
|
287 |
+
"""Returns True if there are multiple domains in the jar.
|
288 |
+
Returns False otherwise.
|
289 |
+
|
290 |
+
:rtype: bool
|
291 |
+
"""
|
292 |
+
domains = []
|
293 |
+
for cookie in iter(self):
|
294 |
+
if cookie.domain is not None and cookie.domain in domains:
|
295 |
+
return True
|
296 |
+
domains.append(cookie.domain)
|
297 |
+
return False # there is only one domain in jar
|
298 |
+
|
299 |
+
def get_dict(self, domain=None, path=None):
|
300 |
+
"""Takes as an argument an optional domain and path and returns a plain
|
301 |
+
old Python dict of name-value pairs of cookies that meet the
|
302 |
+
requirements.
|
303 |
+
|
304 |
+
:rtype: dict
|
305 |
+
"""
|
306 |
+
dictionary = {}
|
307 |
+
for cookie in iter(self):
|
308 |
+
if (
|
309 |
+
(domain is None or cookie.domain == domain) and
|
310 |
+
(path is None or cookie.path == path)
|
311 |
+
):
|
312 |
+
dictionary[cookie.name] = cookie.value
|
313 |
+
return dictionary
|
314 |
+
|
315 |
+
def __contains__(self, name):
|
316 |
+
try:
|
317 |
+
return super(RequestsCookieJar, self).__contains__(name)
|
318 |
+
except CookieConflictError:
|
319 |
+
return True
|
320 |
+
|
321 |
+
def __getitem__(self, name):
|
322 |
+
"""Dict-like __getitem__() for compatibility with client code. Throws
|
323 |
+
exception if there are more than one cookie with name. In that case,
|
324 |
+
use the more explicit get() method instead.
|
325 |
+
|
326 |
+
.. warning:: operation is O(n), not O(1).
|
327 |
+
"""
|
328 |
+
return self._find_no_duplicates(name)
|
329 |
+
|
330 |
+
def __setitem__(self, name, value):
|
331 |
+
"""Dict-like __setitem__ for compatibility with client code. Throws
|
332 |
+
exception if there is already a cookie of that name in the jar. In that
|
333 |
+
case, use the more explicit set() method instead.
|
334 |
+
"""
|
335 |
+
self.set(name, value)
|
336 |
+
|
337 |
+
def __delitem__(self, name):
|
338 |
+
"""Deletes a cookie given a name. Wraps ``cookielib.CookieJar``'s
|
339 |
+
``remove_cookie_by_name()``.
|
340 |
+
"""
|
341 |
+
remove_cookie_by_name(self, name)
|
342 |
+
|
343 |
+
def set_cookie(self, cookie, *args, **kwargs):
|
344 |
+
if hasattr(cookie.value, 'startswith') and cookie.value.startswith('"') and cookie.value.endswith('"'):
|
345 |
+
cookie.value = cookie.value.replace('\\"', '')
|
346 |
+
return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs)
|
347 |
+
|
348 |
+
def update(self, other):
|
349 |
+
"""Updates this jar with cookies from another CookieJar or dict-like"""
|
350 |
+
if isinstance(other, cookielib.CookieJar):
|
351 |
+
for cookie in other:
|
352 |
+
self.set_cookie(copy.copy(cookie))
|
353 |
+
else:
|
354 |
+
super(RequestsCookieJar, self).update(other)
|
355 |
+
|
356 |
+
def _find(self, name, domain=None, path=None):
|
357 |
+
"""Requests uses this method internally to get cookie values.
|
358 |
+
|
359 |
+
If there are conflicting cookies, _find arbitrarily chooses one.
|
360 |
+
See _find_no_duplicates if you want an exception thrown if there are
|
361 |
+
conflicting cookies.
|
362 |
+
|
363 |
+
:param name: a string containing name of cookie
|
364 |
+
:param domain: (optional) string containing domain of cookie
|
365 |
+
:param path: (optional) string containing path of cookie
|
366 |
+
:return: cookie.value
|
367 |
+
"""
|
368 |
+
for cookie in iter(self):
|
369 |
+
if cookie.name == name:
|
370 |
+
if domain is None or cookie.domain == domain:
|
371 |
+
if path is None or cookie.path == path:
|
372 |
+
return cookie.value
|
373 |
+
|
374 |
+
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
|
375 |
+
|
376 |
+
def _find_no_duplicates(self, name, domain=None, path=None):
|
377 |
+
"""Both ``__get_item__`` and ``get`` call this function: it's never
|
378 |
+
used elsewhere in Requests.
|
379 |
+
|
380 |
+
:param name: a string containing name of cookie
|
381 |
+
:param domain: (optional) string containing domain of cookie
|
382 |
+
:param path: (optional) string containing path of cookie
|
383 |
+
:raises KeyError: if cookie is not found
|
384 |
+
:raises CookieConflictError: if there are multiple cookies
|
385 |
+
that match name and optionally domain and path
|
386 |
+
:return: cookie.value
|
387 |
+
"""
|
388 |
+
toReturn = None
|
389 |
+
for cookie in iter(self):
|
390 |
+
if cookie.name == name:
|
391 |
+
if domain is None or cookie.domain == domain:
|
392 |
+
if path is None or cookie.path == path:
|
393 |
+
if toReturn is not None: # if there are multiple cookies that meet passed in criteria
|
394 |
+
raise CookieConflictError('There are multiple cookies with name, %r' % (name))
|
395 |
+
toReturn = cookie.value # we will eventually return this as long as no cookie conflict
|
396 |
+
|
397 |
+
if toReturn:
|
398 |
+
return toReturn
|
399 |
+
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
|
400 |
+
|
401 |
+
def __getstate__(self):
|
402 |
+
"""Unlike a normal CookieJar, this class is pickleable."""
|
403 |
+
state = self.__dict__.copy()
|
404 |
+
# remove the unpickleable RLock object
|
405 |
+
state.pop('_cookies_lock')
|
406 |
+
return state
|
407 |
+
|
408 |
+
def __setstate__(self, state):
|
409 |
+
"""Unlike a normal CookieJar, this class is pickleable."""
|
410 |
+
self.__dict__.update(state)
|
411 |
+
if '_cookies_lock' not in self.__dict__:
|
412 |
+
self._cookies_lock = threading.RLock()
|
413 |
+
|
414 |
+
def copy(self):
|
415 |
+
"""Return a copy of this RequestsCookieJar."""
|
416 |
+
new_cj = RequestsCookieJar()
|
417 |
+
new_cj.set_policy(self.get_policy())
|
418 |
+
new_cj.update(self)
|
419 |
+
return new_cj
|
420 |
+
|
421 |
+
def get_policy(self):
|
422 |
+
"""Return the CookiePolicy instance used."""
|
423 |
+
return self._policy
|
424 |
+
|
425 |
+
|
426 |
+
def _copy_cookie_jar(jar):
|
427 |
+
if jar is None:
|
428 |
+
return None
|
429 |
+
|
430 |
+
if hasattr(jar, 'copy'):
|
431 |
+
# We're dealing with an instance of RequestsCookieJar
|
432 |
+
return jar.copy()
|
433 |
+
# We're dealing with a generic CookieJar instance
|
434 |
+
new_jar = copy.copy(jar)
|
435 |
+
new_jar.clear()
|
436 |
+
for cookie in jar:
|
437 |
+
new_jar.set_cookie(copy.copy(cookie))
|
438 |
+
return new_jar
|
439 |
+
|
440 |
+
|
441 |
+
def create_cookie(name, value, **kwargs):
|
442 |
+
"""Make a cookie from underspecified parameters.
|
443 |
+
|
444 |
+
By default, the pair of `name` and `value` will be set for the domain ''
|
445 |
+
and sent on every request (this is sometimes called a "supercookie").
|
446 |
+
"""
|
447 |
+
result = {
|
448 |
+
'version': 0,
|
449 |
+
'name': name,
|
450 |
+
'value': value,
|
451 |
+
'port': None,
|
452 |
+
'domain': '',
|
453 |
+
'path': '/',
|
454 |
+
'secure': False,
|
455 |
+
'expires': None,
|
456 |
+
'discard': True,
|
457 |
+
'comment': None,
|
458 |
+
'comment_url': None,
|
459 |
+
'rest': {'HttpOnly': None},
|
460 |
+
'rfc2109': False,
|
461 |
+
}
|
462 |
+
|
463 |
+
badargs = set(kwargs) - set(result)
|
464 |
+
if badargs:
|
465 |
+
err = 'create_cookie() got unexpected keyword arguments: %s'
|
466 |
+
raise TypeError(err % list(badargs))
|
467 |
+
|
468 |
+
result.update(kwargs)
|
469 |
+
result['port_specified'] = bool(result['port'])
|
470 |
+
result['domain_specified'] = bool(result['domain'])
|
471 |
+
result['domain_initial_dot'] = result['domain'].startswith('.')
|
472 |
+
result['path_specified'] = bool(result['path'])
|
473 |
+
|
474 |
+
return cookielib.Cookie(**result)
|
475 |
+
|
476 |
+
|
477 |
+
def morsel_to_cookie(morsel):
|
478 |
+
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
|
479 |
+
|
480 |
+
expires = None
|
481 |
+
if morsel['max-age']:
|
482 |
+
try:
|
483 |
+
expires = int(time.time() + int(morsel['max-age']))
|
484 |
+
except ValueError:
|
485 |
+
raise TypeError('max-age: %s must be integer' % morsel['max-age'])
|
486 |
+
elif morsel['expires']:
|
487 |
+
time_template = '%a, %d-%b-%Y %H:%M:%S GMT'
|
488 |
+
expires = calendar.timegm(
|
489 |
+
time.strptime(morsel['expires'], time_template)
|
490 |
+
)
|
491 |
+
return create_cookie(
|
492 |
+
comment=morsel['comment'],
|
493 |
+
comment_url=bool(morsel['comment']),
|
494 |
+
discard=False,
|
495 |
+
domain=morsel['domain'],
|
496 |
+
expires=expires,
|
497 |
+
name=morsel.key,
|
498 |
+
path=morsel['path'],
|
499 |
+
port=None,
|
500 |
+
rest={'HttpOnly': morsel['httponly']},
|
501 |
+
rfc2109=False,
|
502 |
+
secure=bool(morsel['secure']),
|
503 |
+
value=morsel.value,
|
504 |
+
version=morsel['version'] or 0,
|
505 |
+
)
|
506 |
+
|
507 |
+
|
508 |
+
def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
|
509 |
+
"""Returns a CookieJar from a key/value dictionary.
|
510 |
+
|
511 |
+
:param cookie_dict: Dict of key/values to insert into CookieJar.
|
512 |
+
:param cookiejar: (optional) A cookiejar to add the cookies to.
|
513 |
+
:param overwrite: (optional) If False, will not replace cookies
|
514 |
+
already in the jar with new ones.
|
515 |
+
:rtype: CookieJar
|
516 |
+
"""
|
517 |
+
if cookiejar is None:
|
518 |
+
cookiejar = RequestsCookieJar()
|
519 |
+
|
520 |
+
if cookie_dict is not None:
|
521 |
+
names_from_jar = [cookie.name for cookie in cookiejar]
|
522 |
+
for name in cookie_dict:
|
523 |
+
if overwrite or (name not in names_from_jar):
|
524 |
+
cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
|
525 |
+
|
526 |
+
return cookiejar
|
527 |
+
|
528 |
+
|
529 |
+
def merge_cookies(cookiejar, cookies):
|
530 |
+
"""Add cookies to cookiejar and returns a merged CookieJar.
|
531 |
+
|
532 |
+
:param cookiejar: CookieJar object to add the cookies to.
|
533 |
+
:param cookies: Dictionary or CookieJar object to be added.
|
534 |
+
:rtype: CookieJar
|
535 |
+
"""
|
536 |
+
if not isinstance(cookiejar, cookielib.CookieJar):
|
537 |
+
raise ValueError('You can only merge into CookieJar')
|
538 |
+
|
539 |
+
if isinstance(cookies, dict):
|
540 |
+
cookiejar = cookiejar_from_dict(
|
541 |
+
cookies, cookiejar=cookiejar, overwrite=False)
|
542 |
+
elif isinstance(cookies, cookielib.CookieJar):
|
543 |
+
try:
|
544 |
+
cookiejar.update(cookies)
|
545 |
+
except AttributeError:
|
546 |
+
for cookie_in_jar in cookies:
|
547 |
+
cookiejar.set_cookie(cookie_in_jar)
|
548 |
+
|
549 |
+
return cookiejar
|
llmeval-env/lib/python3.10/site-packages/pip/_vendor/requests/exceptions.py
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
"""
|
4 |
+
requests.exceptions
|
5 |
+
~~~~~~~~~~~~~~~~~~~
|
6 |
+
|
7 |
+
This module contains the set of Requests' exceptions.
|
8 |
+
"""
|
9 |
+
from pip._vendor.urllib3.exceptions import HTTPError as BaseHTTPError
|
10 |
+
|
11 |
+
from .compat import JSONDecodeError as CompatJSONDecodeError
|
12 |
+
|
13 |
+
|
14 |
+
class RequestException(IOError):
|
15 |
+
"""There was an ambiguous exception that occurred while handling your
|
16 |
+
request.
|
17 |
+
"""
|
18 |
+
|
19 |
+
def __init__(self, *args, **kwargs):
|
20 |
+
"""Initialize RequestException with `request` and `response` objects."""
|
21 |
+
response = kwargs.pop('response', None)
|
22 |
+
self.response = response
|
23 |
+
self.request = kwargs.pop('request', None)
|
24 |
+
if (response is not None and not self.request and
|
25 |
+
hasattr(response, 'request')):
|
26 |
+
self.request = self.response.request
|
27 |
+
super(RequestException, self).__init__(*args, **kwargs)
|
28 |
+
|
29 |
+
|
30 |
+
class InvalidJSONError(RequestException):
|
31 |
+
"""A JSON error occurred."""
|
32 |
+
|
33 |
+
|
34 |
+
class JSONDecodeError(InvalidJSONError, CompatJSONDecodeError):
|
35 |
+
"""Couldn't decode the text into json"""
|
36 |
+
|
37 |
+
|
38 |
+
class HTTPError(RequestException):
|
39 |
+
"""An HTTP error occurred."""
|
40 |
+
|
41 |
+
|
42 |
+
class ConnectionError(RequestException):
|
43 |
+
"""A Connection error occurred."""
|
44 |
+
|
45 |
+
|
46 |
+
class ProxyError(ConnectionError):
|
47 |
+
"""A proxy error occurred."""
|
48 |
+
|
49 |
+
|
50 |
+
class SSLError(ConnectionError):
|
51 |
+
"""An SSL error occurred."""
|
52 |
+
|
53 |
+
|
54 |
+
class Timeout(RequestException):
|
55 |
+
"""The request timed out.
|
56 |
+
|
57 |
+
Catching this error will catch both
|
58 |
+
:exc:`~requests.exceptions.ConnectTimeout` and
|
59 |
+
:exc:`~requests.exceptions.ReadTimeout` errors.
|
60 |
+
"""
|
61 |
+
|
62 |
+
|
63 |
+
class ConnectTimeout(ConnectionError, Timeout):
|
64 |
+
"""The request timed out while trying to connect to the remote server.
|
65 |
+
|
66 |
+
Requests that produced this error are safe to retry.
|
67 |
+
"""
|
68 |
+
|
69 |
+
|
70 |
+
class ReadTimeout(Timeout):
|
71 |
+
"""The server did not send any data in the allotted amount of time."""
|
72 |
+
|
73 |
+
|
74 |
+
class URLRequired(RequestException):
|
75 |
+
"""A valid URL is required to make a request."""
|
76 |
+
|
77 |
+
|
78 |
+
class TooManyRedirects(RequestException):
|
79 |
+
"""Too many redirects."""
|
80 |
+
|
81 |
+
|
82 |
+
class MissingSchema(RequestException, ValueError):
|
83 |
+
"""The URL scheme (e.g. http or https) is missing."""
|
84 |
+
|
85 |
+
|
86 |
+
class InvalidSchema(RequestException, ValueError):
|
87 |
+
"""The URL scheme provided is either invalid or unsupported."""
|
88 |
+
|
89 |
+
|
90 |
+
class InvalidURL(RequestException, ValueError):
|
91 |
+
"""The URL provided was somehow invalid."""
|
92 |
+
|
93 |
+
|
94 |
+
class InvalidHeader(RequestException, ValueError):
|
95 |
+
"""The header value provided was somehow invalid."""
|
96 |
+
|
97 |
+
|
98 |
+
class InvalidProxyURL(InvalidURL):
|
99 |
+
"""The proxy URL provided is invalid."""
|
100 |
+
|
101 |
+
|
102 |
+
class ChunkedEncodingError(RequestException):
|
103 |
+
"""The server declared chunked encoding but sent an invalid chunk."""
|
104 |
+
|
105 |
+
|
106 |
+
class ContentDecodingError(RequestException, BaseHTTPError):
|
107 |
+
"""Failed to decode response content."""
|
108 |
+
|
109 |
+
|
110 |
+
class StreamConsumedError(RequestException, TypeError):
|
111 |
+
"""The content for this response was already consumed."""
|
112 |
+
|
113 |
+
|
114 |
+
class RetryError(RequestException):
|
115 |
+
"""Custom retries logic failed"""
|
116 |
+
|
117 |
+
|
118 |
+
class UnrewindableBodyError(RequestException):
|
119 |
+
"""Requests encountered an error when trying to rewind a body."""
|
120 |
+
|
121 |
+
# Warnings
|
122 |
+
|
123 |
+
|
124 |
+
class RequestsWarning(Warning):
|
125 |
+
"""Base warning for Requests."""
|
126 |
+
|
127 |
+
|
128 |
+
class FileModeWarning(RequestsWarning, DeprecationWarning):
|
129 |
+
"""A file was opened in text mode, but Requests determined its binary length."""
|
130 |
+
|
131 |
+
|
132 |
+
class RequestsDependencyWarning(RequestsWarning):
|
133 |
+
"""An imported dependency doesn't match the expected version range."""
|