rsquests 2.34.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rsquests/__init__.py ADDED
@@ -0,0 +1,219 @@
1
+ # __
2
+ # /__) _ _ _ _ _/ _
3
+ # / ( (- (/ (/ (- _) / _)
4
+ # /
5
+
6
+ """
7
+ Requests HTTP Library
8
+ ~~~~~~~~~~~~~~~~~~~~~
9
+
10
+ Requests is an HTTP library, written in Python, for human beings.
11
+ Basic GET usage:
12
+
13
+ >>> import requests
14
+ >>> r = requests.get('https://www.python.org')
15
+ >>> r.status_code
16
+ 200
17
+ >>> b'Python is a programming language' in r.content
18
+ True
19
+
20
+ ... or POST:
21
+
22
+ >>> payload = dict(key1='value1', key2='value2')
23
+ >>> r = requests.post('https://httpbin.org/post', data=payload)
24
+ >>> print(r.text)
25
+ {
26
+ ...
27
+ "form": {
28
+ "key1": "value1",
29
+ "key2": "value2"
30
+ },
31
+ ...
32
+ }
33
+
34
+ The other HTTP methods are supported - see `requests.api`. Full documentation
35
+ is at <https://requests.readthedocs.io>.
36
+
37
+ :copyright: (c) 2017 by Kenneth Reitz.
38
+ :license: Apache 2.0, see LICENSE for more details.
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+ import warnings
44
+
45
+ import urllib3
46
+
47
+ from .exceptions import RequestsDependencyWarning
48
+
49
+ try:
50
+ from charset_normalizer import __version__ as charset_normalizer_version
51
+ except ImportError:
52
+ charset_normalizer_version = None
53
+
54
+ try:
55
+ from chardet import __version__ as chardet_version # type: ignore[import-not-found]
56
+ except ImportError:
57
+ chardet_version = None
58
+
59
+
60
+ def check_compatibility(
61
+ urllib3_version: str,
62
+ chardet_version: str | None,
63
+ charset_normalizer_version: str | None,
64
+ ) -> None:
65
+ urllib3_version_list = urllib3_version.split(".")[:3]
66
+ assert urllib3_version_list != ["dev"] # Verify urllib3 isn't installed from git.
67
+
68
+ # Sometimes, urllib3 only reports its version as 16.1.
69
+ if len(urllib3_version_list) == 2:
70
+ urllib3_version_list.append("0")
71
+
72
+ # Check urllib3 for compatibility.
73
+ major, minor, patch = urllib3_version_list # noqa: F811
74
+ major, minor, patch = int(major), int(minor), int(patch)
75
+ # urllib3 >= 1.21.1
76
+ assert major >= 1
77
+ if major == 1:
78
+ assert minor >= 21
79
+
80
+ # Check charset_normalizer for compatibility.
81
+ if chardet_version:
82
+ major, minor, patch = chardet_version.split(".")[:3]
83
+ major, minor, patch = int(major), int(minor), int(patch)
84
+ # chardet_version >= 3.0.2, < 8.0.0
85
+ assert (3, 0, 2) <= (major, minor, patch) < (8, 0, 0)
86
+ elif charset_normalizer_version:
87
+ major, minor, patch = charset_normalizer_version.split(".")[:3]
88
+ major, minor, patch = int(major), int(minor), int(patch)
89
+ # charset_normalizer >= 2.0.0 < 4.0.0
90
+ assert (2, 0, 0) <= (major, minor, patch) < (4, 0, 0)
91
+ else:
92
+ warnings.warn(
93
+ "Unable to find acceptable character detection dependency "
94
+ "(chardet or charset_normalizer).",
95
+ RequestsDependencyWarning,
96
+ )
97
+
98
+
99
+ def _check_cryptography(cryptography_version: str) -> None:
100
+ # cryptography < 1.3.4
101
+ try:
102
+ cryptography_version_list = list(map(int, cryptography_version.split(".")))
103
+ except ValueError:
104
+ return
105
+
106
+ if cryptography_version_list < [1, 3, 4]:
107
+ warning = f"Old version of cryptography ({cryptography_version_list}) may cause slowdown."
108
+ warnings.warn(warning, RequestsDependencyWarning)
109
+
110
+
111
+ # Check imported dependencies for compatibility.
112
+ try:
113
+ check_compatibility(
114
+ urllib3.__version__, # type: ignore[reportPrivateImportUsage]
115
+ chardet_version, # type: ignore[reportUnknownArgumentType]
116
+ charset_normalizer_version,
117
+ )
118
+ except (AssertionError, ValueError):
119
+ warnings.warn(
120
+ f"urllib3 ({urllib3.__version__}) or chardet " # type: ignore[reportPrivateImportUsage]
121
+ f"({chardet_version})/charset_normalizer ({charset_normalizer_version}) "
122
+ "doesn't match a supported version!",
123
+ RequestsDependencyWarning,
124
+ )
125
+
126
+ # Attempt to enable urllib3's fallback for SNI support
127
+ # if the standard library doesn't support SNI or the
128
+ # 'ssl' library isn't available.
129
+ try:
130
+ try:
131
+ import ssl
132
+ except ImportError:
133
+ ssl = None
134
+
135
+ if not getattr(ssl, "HAS_SNI", False):
136
+ from urllib3.contrib import pyopenssl
137
+
138
+ pyopenssl.inject_into_urllib3()
139
+
140
+ # Check cryptography version
141
+ from cryptography import ( # type: ignore[reportMissingImports]
142
+ __version__ as cryptography_version, # type: ignore[reportUnknownVariableType]
143
+ )
144
+
145
+ _check_cryptography(cryptography_version) # type: ignore[reportUnknownArgumentType]
146
+ except ImportError:
147
+ pass
148
+
149
+ # urllib3's DependencyWarnings should be silenced.
150
+ from urllib3.exceptions import DependencyWarning
151
+
152
+ warnings.simplefilter("ignore", DependencyWarning)
153
+
154
+ # Set default logging handler to avoid "No handler found" warnings.
155
+ import logging
156
+ from logging import NullHandler
157
+
158
+ from . import packages, utils
159
+ from .__version__ import (
160
+ __author__,
161
+ __author_email__,
162
+ __build__,
163
+ __cake__,
164
+ __copyright__,
165
+ __description__,
166
+ __license__,
167
+ __title__,
168
+ __url__,
169
+ __version__,
170
+ )
171
+ from .api import delete, get, head, options, patch, post, put, request
172
+ from .exceptions import (
173
+ ConnectionError,
174
+ ConnectTimeout,
175
+ FileModeWarning,
176
+ HTTPError,
177
+ JSONDecodeError,
178
+ ReadTimeout,
179
+ RequestException,
180
+ Timeout,
181
+ TooManyRedirects,
182
+ URLRequired,
183
+ )
184
+ from .models import PreparedRequest, Request, Response
185
+ from .sessions import Session, session
186
+ from .status_codes import codes
187
+
188
+ __all__ = (
189
+ "ConnectionError",
190
+ "ConnectTimeout",
191
+ "HTTPError",
192
+ "JSONDecodeError",
193
+ "PreparedRequest",
194
+ "ReadTimeout",
195
+ "Request",
196
+ "RequestException",
197
+ "Response",
198
+ "Session",
199
+ "Timeout",
200
+ "TooManyRedirects",
201
+ "URLRequired",
202
+ "codes",
203
+ "delete",
204
+ "get",
205
+ "head",
206
+ "options",
207
+ "packages",
208
+ "patch",
209
+ "post",
210
+ "put",
211
+ "request",
212
+ "session",
213
+ "utils",
214
+ )
215
+
216
+ logging.getLogger(__name__).addHandler(NullHandler())
217
+
218
+ # FileModeWarnings go off per the default.
219
+ warnings.simplefilter("default", FileModeWarning, append=True)
@@ -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.34.2"
9
+ __build__ = 0x023402
10
+ __author__ = "Kenneth Reitz"
11
+ __author_email__ = "me@kennethreitz.org"
12
+ __license__ = "Apache-2.0"
13
+ __copyright__ = "Copyright Kenneth Reitz"
14
+ __cake__ = "\u2728 \U0001f370 \u2728"
@@ -0,0 +1,51 @@
1
+ """
2
+ requests._internal_utils
3
+ ~~~~~~~~~~~~~~
4
+
5
+ Provides utility functions that are consumed internally by Requests
6
+ which depend on extremely few external helpers (such as compat)
7
+ """
8
+
9
+ import re
10
+
11
+ from .compat import builtin_str
12
+
13
+ _VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*\Z")
14
+ _VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*\Z")
15
+ _VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*\Z|^\Z")
16
+ _VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*\Z|^\Z")
17
+
18
+ _HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
19
+ _HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
20
+ HEADER_VALIDATORS = {
21
+ bytes: _HEADER_VALIDATORS_BYTE,
22
+ str: _HEADER_VALIDATORS_STR,
23
+ }
24
+
25
+
26
+ def to_native_string(string: str | bytes, encoding: str = "ascii") -> str:
27
+ """Given a string object, regardless of type, returns a representation of
28
+ that string in the native string type, encoding and decoding where
29
+ necessary. This assumes ASCII unless told otherwise.
30
+ """
31
+ if isinstance(string, builtin_str):
32
+ out = string
33
+ else:
34
+ out = string.decode(encoding)
35
+
36
+ return out
37
+
38
+
39
+ def unicode_is_ascii(u_string: str) -> bool:
40
+ """Determine if unicode string only contains ASCII characters.
41
+
42
+ :param str u_string: unicode string to check. Must be unicode
43
+ and not Python 2 `str`.
44
+ :rtype: bool
45
+ """
46
+ assert isinstance(u_string, str)
47
+ try:
48
+ u_string.encode("ascii")
49
+ return True
50
+ except UnicodeEncodeError:
51
+ return False
rsquests/_types.py ADDED
@@ -0,0 +1,183 @@
1
+ """
2
+ requests._types
3
+ ~~~~~~~~~~~~~~~
4
+
5
+ This module contains type aliases used internally by the Requests library.
6
+ These types are not part of the public API and must not be relied upon
7
+ by external code.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence
13
+ from typing import (
14
+ TYPE_CHECKING,
15
+ Any,
16
+ Protocol,
17
+ TypeAlias,
18
+ TypeVar,
19
+ runtime_checkable,
20
+ )
21
+
22
+ _T_co = TypeVar("_T_co", covariant=True)
23
+ _KT_co = TypeVar("_KT_co", covariant=True)
24
+ _VT_co = TypeVar("_VT_co", covariant=True)
25
+
26
+
27
+ @runtime_checkable
28
+ class SupportsRead(Protocol[_T_co]):
29
+ def read(self, length: int = ..., /) -> _T_co: ...
30
+
31
+
32
+ @runtime_checkable
33
+ class SupportsItems(Protocol[_KT_co, _VT_co]):
34
+ def items(self) -> Iterable[tuple[_KT_co, _VT_co]]: ...
35
+
36
+
37
+ # These are needed at runtime for default_hooks() return type
38
+ HookType: TypeAlias = Callable[["Response"], Any]
39
+ HooksInputType: TypeAlias = Mapping[str, Iterable[HookType] | HookType]
40
+
41
+
42
+ def is_prepared(request: PreparedRequest) -> TypeIs[_ValidatedRequest]:
43
+ """Verify a PreparedRequest has been fully prepared."""
44
+ if TYPE_CHECKING:
45
+ return request.url is not None and request.method is not None
46
+ # noop at runtime to avoid AssertionError
47
+ return True
48
+
49
+
50
+ if TYPE_CHECKING:
51
+ from http.cookiejar import CookieJar
52
+ from typing import TypeAlias, TypedDict
53
+
54
+ from typing_extensions import (
55
+ Buffer, # TODO: move to collections.abc when Python >= 3.12
56
+ TypeIs, # TODO: move to typing when Python >= 3.13
57
+ )
58
+
59
+ from .auth import AuthBase
60
+ from .cookies import RequestsCookieJar
61
+ from .models import PreparedRequest, Response
62
+ from .structures import CaseInsensitiveDict
63
+
64
+ class _ValidatedRequest(PreparedRequest):
65
+ """Subtype asserting a PreparedRequest has been fully prepared before calling.
66
+
67
+ The override suppression is required because mutable attribute types are
68
+ invariant (Liskov), but we only narrow after preparation is complete. This
69
+ is the explicit contract for Requests but Python's typing doesn't have a
70
+ better way to represent the requirement.
71
+ """
72
+
73
+ url: str # type: ignore[reportIncompatibleVariableOverride]
74
+ method: str # type: ignore[reportIncompatibleVariableOverride]
75
+
76
+ # Type aliases for core API concepts (ordered by request() signature)
77
+ UriType: TypeAlias = str | bytes
78
+
79
+ _ParamsMappingKeyType: TypeAlias = str | bytes | int | float
80
+ _ParamsMappingValueType: TypeAlias = (
81
+ str | bytes | int | float | Iterable[str | bytes | int | float] | None
82
+ )
83
+ ParamsType: TypeAlias = (
84
+ SupportsItems[_ParamsMappingKeyType, _ParamsMappingValueType]
85
+ | tuple[tuple[_ParamsMappingKeyType, _ParamsMappingValueType], ...]
86
+ | Iterable[tuple[_ParamsMappingKeyType, _ParamsMappingValueType]]
87
+ | str
88
+ | bytes
89
+ | None
90
+ )
91
+
92
+ KVDataType: TypeAlias = Iterable[tuple[Any, Any]] | SupportsItems[Any, Any]
93
+
94
+ RawDataType: TypeAlias = KVDataType | str | bytes
95
+ StreamDataType: TypeAlias = SupportsRead[str | bytes]
96
+ EncodableDataType: TypeAlias = RawDataType | StreamDataType
97
+
98
+ DataType: TypeAlias = (
99
+ KVDataType
100
+ | Iterable[bytes | str]
101
+ | str
102
+ | bytes
103
+ | Buffer
104
+ | SupportsRead[str | bytes]
105
+ | None
106
+ )
107
+
108
+ BodyType: TypeAlias = (
109
+ bytes | str | Iterable[bytes | str] | SupportsRead[bytes | str] | None
110
+ )
111
+
112
+ HeadersType: TypeAlias = Mapping[str, str | bytes] | None
113
+
114
+ CookiesType: TypeAlias = RequestsCookieJar | Mapping[str, str]
115
+
116
+ # Building blocks for FilesType
117
+ _FileName: TypeAlias = str | None
118
+ _FileContent: TypeAlias = SupportsRead[str | bytes] | str | bytes
119
+ _FileSpecBasic: TypeAlias = tuple[_FileName, _FileContent]
120
+ _FileSpecWithContentType: TypeAlias = tuple[_FileName, _FileContent, str]
121
+ _FileSpecWithHeaders: TypeAlias = tuple[
122
+ _FileName, _FileContent, str, CaseInsensitiveDict[str] | Mapping[str, str]
123
+ ]
124
+ _FileSpec: TypeAlias = (
125
+ _FileContent | _FileSpecBasic | _FileSpecWithContentType | _FileSpecWithHeaders
126
+ )
127
+ FilesType: TypeAlias = (
128
+ Mapping[str, _FileSpec] | Iterable[tuple[str, _FileSpec]] | None
129
+ )
130
+
131
+ AuthType: TypeAlias = (
132
+ tuple[str, str] | AuthBase | Callable[[PreparedRequest], PreparedRequest] | None
133
+ )
134
+
135
+ TimeoutType: TypeAlias = float | tuple[float | None, float | None] | None
136
+ ProxiesType: TypeAlias = MutableMapping[str, str]
137
+ HooksType: TypeAlias = dict[str, list[HookType]] | None
138
+ VerifyType: TypeAlias = bool | str
139
+ CertType: TypeAlias = str | tuple[str, str] | None
140
+ JsonType: TypeAlias = (
141
+ None
142
+ | bool
143
+ | int
144
+ | float
145
+ | str
146
+ | Sequence["JsonType"]
147
+ | Mapping[str, "JsonType"]
148
+ )
149
+
150
+ # TypedDicts for Unpack kwargs (PEP 692)
151
+
152
+ class BaseRequestKwargs(TypedDict, total=False):
153
+ headers: HeadersType
154
+ cookies: RequestsCookieJar | CookieJar | dict[str, str] | None
155
+ files: FilesType
156
+ auth: AuthType
157
+ timeout: TimeoutType
158
+ allow_redirects: bool
159
+ proxies: dict[str, str] | None
160
+ hooks: HooksInputType | None
161
+ stream: bool | None
162
+ verify: VerifyType | None
163
+ cert: CertType
164
+
165
+ class RequestKwargs(BaseRequestKwargs, total=False):
166
+ """kwargs for request(), options(), head(), delete()."""
167
+
168
+ params: ParamsType
169
+ data: DataType
170
+ json: JsonType
171
+
172
+ class GetKwargs(BaseRequestKwargs, total=False):
173
+ data: DataType
174
+ json: JsonType
175
+
176
+ class PostKwargs(BaseRequestKwargs, total=False):
177
+ params: ParamsType
178
+
179
+ class DataKwargs(BaseRequestKwargs, total=False):
180
+ """kwargs for put(), patch()."""
181
+
182
+ params: ParamsType
183
+ json: JsonType