snowflake-connector-python 3.16.0__cp313-cp313-win_amd64.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.
Files changed (246) hide show
  1. snowflake/connector/__init__.py +96 -0
  2. snowflake/connector/_query_context_cache.py +276 -0
  3. snowflake/connector/_sql_util.py +48 -0
  4. snowflake/connector/_utils.py +70 -0
  5. snowflake/connector/arrow_context.py +203 -0
  6. snowflake/connector/auth/__init__.py +53 -0
  7. snowflake/connector/auth/_auth.py +586 -0
  8. snowflake/connector/auth/_http_server.py +220 -0
  9. snowflake/connector/auth/_oauth_base.py +400 -0
  10. snowflake/connector/auth/by_plugin.py +219 -0
  11. snowflake/connector/auth/default.py +36 -0
  12. snowflake/connector/auth/idtoken.py +72 -0
  13. snowflake/connector/auth/keypair.py +222 -0
  14. snowflake/connector/auth/no_auth.py +39 -0
  15. snowflake/connector/auth/oauth.py +49 -0
  16. snowflake/connector/auth/oauth_code.py +479 -0
  17. snowflake/connector/auth/oauth_credentials.py +66 -0
  18. snowflake/connector/auth/okta.py +335 -0
  19. snowflake/connector/auth/pat.py +39 -0
  20. snowflake/connector/auth/usrpwdmfa.py +69 -0
  21. snowflake/connector/auth/webbrowser.py +502 -0
  22. snowflake/connector/auth/workload_identity.py +94 -0
  23. snowflake/connector/azure_storage_client.py +276 -0
  24. snowflake/connector/backoff_policies.py +141 -0
  25. snowflake/connector/bind_upload_agent.py +89 -0
  26. snowflake/connector/cache.py +696 -0
  27. snowflake/connector/compat.py +127 -0
  28. snowflake/connector/config_manager.py +496 -0
  29. snowflake/connector/connection.py +2273 -0
  30. snowflake/connector/connection_diagnostic.py +776 -0
  31. snowflake/connector/constants.py +442 -0
  32. snowflake/connector/converter.py +785 -0
  33. snowflake/connector/converter_issue23517.py +87 -0
  34. snowflake/connector/converter_null.py +14 -0
  35. snowflake/connector/converter_snowsql.py +205 -0
  36. snowflake/connector/cursor.py +1951 -0
  37. snowflake/connector/dbapi.py +53 -0
  38. snowflake/connector/description.py +19 -0
  39. snowflake/connector/direct_file_operation_utils.py +88 -0
  40. snowflake/connector/encryption_util.py +220 -0
  41. snowflake/connector/errorcode.py +91 -0
  42. snowflake/connector/errors.py +615 -0
  43. snowflake/connector/externals_utils/__init__.py +0 -0
  44. snowflake/connector/externals_utils/externals_setup.py +27 -0
  45. snowflake/connector/feature.py +4 -0
  46. snowflake/connector/file_compression_type.py +118 -0
  47. snowflake/connector/file_lock.py +72 -0
  48. snowflake/connector/file_transfer_agent.py +1215 -0
  49. snowflake/connector/file_util.py +153 -0
  50. snowflake/connector/gcs_storage_client.py +474 -0
  51. snowflake/connector/gzip_decoder.py +85 -0
  52. snowflake/connector/local_storage_client.py +90 -0
  53. snowflake/connector/log_configuration.py +60 -0
  54. snowflake/connector/logging_utils/__init__.py +0 -0
  55. snowflake/connector/logging_utils/filters.py +72 -0
  56. snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
  57. snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
  58. snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  59. snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
  60. snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  61. snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  62. snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  63. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
  64. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
  65. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
  66. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
  67. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
  68. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
  69. snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
  70. snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  71. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
  72. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  73. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
  74. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
  75. snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
  76. snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  77. snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
  78. snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  79. snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  80. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  81. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
  82. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
  83. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
  84. snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  85. snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
  86. snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  87. snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
  88. snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  89. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  90. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
  91. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
  92. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
  93. snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
  94. snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  95. snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
  96. snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  97. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
  98. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  99. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
  100. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
  101. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  102. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  103. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  104. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
  105. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
  106. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  107. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
  108. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
  109. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
  110. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  111. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
  112. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
  113. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  114. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  115. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  116. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
  117. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
  118. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
  119. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  120. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
  121. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
  122. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
  123. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  124. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  125. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
  126. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
  127. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  128. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  129. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  130. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  131. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  132. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
  133. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
  134. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
  135. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  136. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  137. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
  138. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
  139. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
  140. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
  141. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
  142. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
  143. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
  144. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
  145. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
  146. snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
  147. snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
  148. snowflake/connector/network.py +1297 -0
  149. snowflake/connector/ocsp_asn1crypto.py +447 -0
  150. snowflake/connector/ocsp_snowflake.py +1883 -0
  151. snowflake/connector/options.py +131 -0
  152. snowflake/connector/pandas_tools.py +732 -0
  153. snowflake/connector/proxy.py +43 -0
  154. snowflake/connector/py.typed +0 -0
  155. snowflake/connector/result_batch.py +786 -0
  156. snowflake/connector/result_set.py +319 -0
  157. snowflake/connector/s3_storage_client.py +605 -0
  158. snowflake/connector/secret_detector.py +181 -0
  159. snowflake/connector/sf_dirs.py +64 -0
  160. snowflake/connector/sfbinaryformat.py +35 -0
  161. snowflake/connector/sfdatetime.py +345 -0
  162. snowflake/connector/snow_logging.py +144 -0
  163. snowflake/connector/sqlstate.py +9 -0
  164. snowflake/connector/ssd_internal_keys.py +30 -0
  165. snowflake/connector/ssl_wrap_socket.py +134 -0
  166. snowflake/connector/storage_client.py +478 -0
  167. snowflake/connector/telemetry.py +249 -0
  168. snowflake/connector/telemetry_oob.py +543 -0
  169. snowflake/connector/test_util.py +30 -0
  170. snowflake/connector/time_util.py +159 -0
  171. snowflake/connector/token_cache.py +402 -0
  172. snowflake/connector/tool/__init__.py +0 -0
  173. snowflake/connector/tool/dump_certs.py +57 -0
  174. snowflake/connector/tool/dump_ocsp_response.py +139 -0
  175. snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
  176. snowflake/connector/tool/probe_connection.py +69 -0
  177. snowflake/connector/url_util.py +49 -0
  178. snowflake/connector/util_text.py +301 -0
  179. snowflake/connector/vendored/__init__.py +3 -0
  180. snowflake/connector/vendored/requests/LICENSE +175 -0
  181. snowflake/connector/vendored/requests/__init__.py +169 -0
  182. snowflake/connector/vendored/requests/__version__.py +14 -0
  183. snowflake/connector/vendored/requests/_internal_utils.py +50 -0
  184. snowflake/connector/vendored/requests/adapters.py +537 -0
  185. snowflake/connector/vendored/requests/api.py +157 -0
  186. snowflake/connector/vendored/requests/auth.py +315 -0
  187. snowflake/connector/vendored/requests/certs.py +17 -0
  188. snowflake/connector/vendored/requests/compat.py +79 -0
  189. snowflake/connector/vendored/requests/cookies.py +561 -0
  190. snowflake/connector/vendored/requests/exceptions.py +140 -0
  191. snowflake/connector/vendored/requests/help.py +134 -0
  192. snowflake/connector/vendored/requests/hooks.py +33 -0
  193. snowflake/connector/vendored/requests/models.py +1033 -0
  194. snowflake/connector/vendored/requests/sessions.py +833 -0
  195. snowflake/connector/vendored/requests/status_codes.py +128 -0
  196. snowflake/connector/vendored/requests/structures.py +99 -0
  197. snowflake/connector/vendored/requests/utils.py +1093 -0
  198. snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
  199. snowflake/connector/vendored/urllib3/__init__.py +85 -0
  200. snowflake/connector/vendored/urllib3/_collections.py +355 -0
  201. snowflake/connector/vendored/urllib3/_version.py +2 -0
  202. snowflake/connector/vendored/urllib3/connection.py +572 -0
  203. snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
  204. snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
  205. snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
  206. snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
  207. snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
  208. snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
  209. snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
  210. snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
  211. snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
  212. snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
  213. snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
  214. snowflake/connector/vendored/urllib3/exceptions.py +323 -0
  215. snowflake/connector/vendored/urllib3/fields.py +274 -0
  216. snowflake/connector/vendored/urllib3/filepost.py +98 -0
  217. snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
  218. snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
  219. snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
  220. snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
  221. snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
  222. snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
  223. snowflake/connector/vendored/urllib3/request.py +191 -0
  224. snowflake/connector/vendored/urllib3/response.py +885 -0
  225. snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
  226. snowflake/connector/vendored/urllib3/util/connection.py +156 -0
  227. snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
  228. snowflake/connector/vendored/urllib3/util/queue.py +22 -0
  229. snowflake/connector/vendored/urllib3/util/request.py +146 -0
  230. snowflake/connector/vendored/urllib3/util/response.py +107 -0
  231. snowflake/connector/vendored/urllib3/util/retry.py +620 -0
  232. snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
  233. snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
  234. snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
  235. snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
  236. snowflake/connector/vendored/urllib3/util/url.py +435 -0
  237. snowflake/connector/vendored/urllib3/util/wait.py +152 -0
  238. snowflake/connector/version.py +3 -0
  239. snowflake/connector/wif_util.py +407 -0
  240. snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
  241. snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
  242. snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
  243. snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
  244. snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
  245. snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
  246. snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,50 @@
1
+ """
2
+ requests._internal_utils
3
+ ~~~~~~~~~~~~~~
4
+
5
+ Provides utility functions that are consumed internally by Requests
6
+ which depend on extremely few external helpers (such as compat)
7
+ """
8
+ import re
9
+
10
+ from .compat import builtin_str
11
+
12
+ _VALID_HEADER_NAME_RE_BYTE = re.compile(rb"^[^:\s][^:\r\n]*$")
13
+ _VALID_HEADER_NAME_RE_STR = re.compile(r"^[^:\s][^:\r\n]*$")
14
+ _VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
15
+ _VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")
16
+
17
+ _HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
18
+ _HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
19
+ HEADER_VALIDATORS = {
20
+ bytes: _HEADER_VALIDATORS_BYTE,
21
+ str: _HEADER_VALIDATORS_STR,
22
+ }
23
+
24
+
25
+ def to_native_string(string, encoding="ascii"):
26
+ """Given a string object, regardless of type, returns a representation of
27
+ that string in the native string type, encoding and decoding where
28
+ necessary. This assumes ASCII unless told otherwise.
29
+ """
30
+ if isinstance(string, builtin_str):
31
+ out = string
32
+ else:
33
+ out = string.decode(encoding)
34
+
35
+ return out
36
+
37
+
38
+ def unicode_is_ascii(u_string):
39
+ """Determine if unicode string only contains ASCII characters.
40
+
41
+ :param str u_string: unicode string to check. Must be unicode
42
+ and not Python 2 `str`.
43
+ :rtype: bool
44
+ """
45
+ assert isinstance(u_string, str)
46
+ try:
47
+ u_string.encode("ascii")
48
+ return True
49
+ except UnicodeEncodeError:
50
+ return False
@@ -0,0 +1,537 @@
1
+ """
2
+ requests.adapters
3
+ ~~~~~~~~~~~~~~~~~
4
+
5
+ This module contains the transport adapters that Requests uses to define
6
+ and maintain connections.
7
+ """
8
+
9
+ import os.path
10
+ import socket # noqa: F401
11
+
12
+ from ..urllib3.exceptions import ClosedPoolError, ConnectTimeoutError
13
+ from ..urllib3.exceptions import HTTPError as _HTTPError
14
+ from ..urllib3.exceptions import InvalidHeader as _InvalidHeader
15
+ from ..urllib3.exceptions import (
16
+ LocationValueError,
17
+ MaxRetryError,
18
+ NewConnectionError,
19
+ ProtocolError,
20
+ )
21
+ from ..urllib3.exceptions import ProxyError as _ProxyError
22
+ from ..urllib3.exceptions import ReadTimeoutError, ResponseError
23
+ from ..urllib3.exceptions import SSLError as _SSLError
24
+ from ..urllib3.poolmanager import PoolManager, proxy_from_url
25
+ from ..urllib3.util import Timeout as TimeoutSauce
26
+ from ..urllib3.util import parse_url
27
+ from ..urllib3.util.retry import Retry
28
+ from .auth import _basic_auth_str
29
+ from .compat import basestring, urlparse
30
+ from .cookies import extract_cookies_to_jar
31
+ from .exceptions import (
32
+ ConnectionError,
33
+ ConnectTimeout,
34
+ InvalidHeader,
35
+ InvalidProxyURL,
36
+ InvalidSchema,
37
+ InvalidURL,
38
+ ProxyError,
39
+ ReadTimeout,
40
+ RetryError,
41
+ SSLError,
42
+ )
43
+ from .models import Response
44
+ from .structures import CaseInsensitiveDict
45
+ from .utils import (
46
+ DEFAULT_CA_BUNDLE_PATH,
47
+ extract_zipped_paths,
48
+ get_auth_from_url,
49
+ get_encoding_from_headers,
50
+ prepend_scheme_if_needed,
51
+ select_proxy,
52
+ urldefragauth,
53
+ )
54
+
55
+ try:
56
+ from ..urllib3.contrib.socks import SOCKSProxyManager
57
+ except ImportError:
58
+
59
+ def SOCKSProxyManager(*args, **kwargs):
60
+ raise InvalidSchema("Missing dependencies for SOCKS support.")
61
+
62
+
63
+ DEFAULT_POOLBLOCK = False
64
+ DEFAULT_POOLSIZE = 10
65
+ DEFAULT_RETRIES = 0
66
+ DEFAULT_POOL_TIMEOUT = None
67
+
68
+
69
+ class BaseAdapter:
70
+ """The Base Transport Adapter"""
71
+
72
+ def __init__(self):
73
+ super().__init__()
74
+
75
+ def send(
76
+ self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
77
+ ):
78
+ """Sends PreparedRequest object. Returns Response object.
79
+
80
+ :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
81
+ :param stream: (optional) Whether to stream the request content.
82
+ :param timeout: (optional) How long to wait for the server to send
83
+ data before giving up, as a float, or a :ref:`(connect timeout,
84
+ read timeout) <timeouts>` tuple.
85
+ :type timeout: float or tuple
86
+ :param verify: (optional) Either a boolean, in which case it controls whether we verify
87
+ the server's TLS certificate, or a string, in which case it must be a path
88
+ to a CA bundle to use
89
+ :param cert: (optional) Any user-provided SSL certificate to be trusted.
90
+ :param proxies: (optional) The proxies dictionary to apply to the request.
91
+ """
92
+ raise NotImplementedError
93
+
94
+ def close(self):
95
+ """Cleans up adapter specific items."""
96
+ raise NotImplementedError
97
+
98
+
99
+ class HTTPAdapter(BaseAdapter):
100
+ """The built-in HTTP Adapter for urllib3.
101
+
102
+ Provides a general-case interface for Requests sessions to contact HTTP and
103
+ HTTPS urls by implementing the Transport Adapter interface. This class will
104
+ usually be created by the :class:`Session <Session>` class under the
105
+ covers.
106
+
107
+ :param pool_connections: The number of urllib3 connection pools to cache.
108
+ :param pool_maxsize: The maximum number of connections to save in the pool.
109
+ :param max_retries: The maximum number of retries each connection
110
+ should attempt. Note, this applies only to failed DNS lookups, socket
111
+ connections and connection timeouts, never to requests where data has
112
+ made it to the server. By default, Requests does not retry failed
113
+ connections. If you need granular control over the conditions under
114
+ which we retry a request, import urllib3's ``Retry`` class and pass
115
+ that instead.
116
+ :param pool_block: Whether the connection pool should block for connections.
117
+
118
+ Usage::
119
+
120
+ >>> import requests
121
+ >>> s = requests.Session()
122
+ >>> a = requests.adapters.HTTPAdapter(max_retries=3)
123
+ >>> s.mount('http://', a)
124
+ """
125
+
126
+ __attrs__ = [
127
+ "max_retries",
128
+ "config",
129
+ "_pool_connections",
130
+ "_pool_maxsize",
131
+ "_pool_block",
132
+ ]
133
+
134
+ def __init__(
135
+ self,
136
+ pool_connections=DEFAULT_POOLSIZE,
137
+ pool_maxsize=DEFAULT_POOLSIZE,
138
+ max_retries=DEFAULT_RETRIES,
139
+ pool_block=DEFAULT_POOLBLOCK,
140
+ ):
141
+ if max_retries == DEFAULT_RETRIES:
142
+ self.max_retries = Retry(0, read=False)
143
+ else:
144
+ self.max_retries = Retry.from_int(max_retries)
145
+ self.config = {}
146
+ self.proxy_manager = {}
147
+
148
+ super().__init__()
149
+
150
+ self._pool_connections = pool_connections
151
+ self._pool_maxsize = pool_maxsize
152
+ self._pool_block = pool_block
153
+
154
+ self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
155
+
156
+ def __getstate__(self):
157
+ return {attr: getattr(self, attr, None) for attr in self.__attrs__}
158
+
159
+ def __setstate__(self, state):
160
+ # Can't handle by adding 'proxy_manager' to self.__attrs__ because
161
+ # self.poolmanager uses a lambda function, which isn't pickleable.
162
+ self.proxy_manager = {}
163
+ self.config = {}
164
+
165
+ for attr, value in state.items():
166
+ setattr(self, attr, value)
167
+
168
+ self.init_poolmanager(
169
+ self._pool_connections, self._pool_maxsize, block=self._pool_block
170
+ )
171
+
172
+ def init_poolmanager(
173
+ self, connections, maxsize, block=DEFAULT_POOLBLOCK, **pool_kwargs
174
+ ):
175
+ """Initializes a urllib3 PoolManager.
176
+
177
+ This method should not be called from user code, and is only
178
+ exposed for use when subclassing the
179
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
180
+
181
+ :param connections: The number of urllib3 connection pools to cache.
182
+ :param maxsize: The maximum number of connections to save in the pool.
183
+ :param block: Block when no free connections are available.
184
+ :param pool_kwargs: Extra keyword arguments used to initialize the Pool Manager.
185
+ """
186
+ # save these values for pickling
187
+ self._pool_connections = connections
188
+ self._pool_maxsize = maxsize
189
+ self._pool_block = block
190
+
191
+ self.poolmanager = PoolManager(
192
+ num_pools=connections,
193
+ maxsize=maxsize,
194
+ block=block,
195
+ **pool_kwargs,
196
+ )
197
+
198
+ def proxy_manager_for(self, proxy, **proxy_kwargs):
199
+ """Return urllib3 ProxyManager for the given proxy.
200
+
201
+ This method should not be called from user code, and is only
202
+ exposed for use when subclassing the
203
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
204
+
205
+ :param proxy: The proxy to return a urllib3 ProxyManager for.
206
+ :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
207
+ :returns: ProxyManager
208
+ :rtype: urllib3.ProxyManager
209
+ """
210
+ if proxy in self.proxy_manager:
211
+ manager = self.proxy_manager[proxy]
212
+ elif proxy.lower().startswith("socks"):
213
+ username, password = get_auth_from_url(proxy)
214
+ manager = self.proxy_manager[proxy] = SOCKSProxyManager(
215
+ proxy,
216
+ username=username,
217
+ password=password,
218
+ num_pools=self._pool_connections,
219
+ maxsize=self._pool_maxsize,
220
+ block=self._pool_block,
221
+ **proxy_kwargs,
222
+ )
223
+ else:
224
+ proxy_headers = self.proxy_headers(proxy)
225
+ manager = self.proxy_manager[proxy] = proxy_from_url(
226
+ proxy,
227
+ proxy_headers=proxy_headers,
228
+ num_pools=self._pool_connections,
229
+ maxsize=self._pool_maxsize,
230
+ block=self._pool_block,
231
+ **proxy_kwargs,
232
+ )
233
+
234
+ return manager
235
+
236
+ def cert_verify(self, conn, url, verify, cert):
237
+ """Verify a SSL certificate. This method should not be called from user
238
+ code, and is only exposed for use when subclassing the
239
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
240
+
241
+ :param conn: The urllib3 connection object associated with the cert.
242
+ :param url: The requested URL.
243
+ :param verify: Either a boolean, in which case it controls whether we verify
244
+ the server's TLS certificate, or a string, in which case it must be a path
245
+ to a CA bundle to use
246
+ :param cert: The SSL certificate to verify.
247
+ """
248
+ if url.lower().startswith("https") and verify:
249
+
250
+ cert_loc = None
251
+
252
+ # Allow self-specified cert location.
253
+ if verify is not True:
254
+ cert_loc = verify
255
+
256
+ if not cert_loc:
257
+ cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
258
+
259
+ if not cert_loc or not os.path.exists(cert_loc):
260
+ raise OSError(
261
+ f"Could not find a suitable TLS CA certificate bundle, "
262
+ f"invalid path: {cert_loc}"
263
+ )
264
+
265
+ conn.cert_reqs = "CERT_REQUIRED"
266
+
267
+ if not os.path.isdir(cert_loc):
268
+ conn.ca_certs = cert_loc
269
+ else:
270
+ conn.ca_cert_dir = cert_loc
271
+ else:
272
+ conn.cert_reqs = "CERT_NONE"
273
+ conn.ca_certs = None
274
+ conn.ca_cert_dir = None
275
+
276
+ if cert:
277
+ if not isinstance(cert, basestring):
278
+ conn.cert_file = cert[0]
279
+ conn.key_file = cert[1]
280
+ else:
281
+ conn.cert_file = cert
282
+ conn.key_file = None
283
+ if conn.cert_file and not os.path.exists(conn.cert_file):
284
+ raise OSError(
285
+ f"Could not find the TLS certificate file, "
286
+ f"invalid path: {conn.cert_file}"
287
+ )
288
+ if conn.key_file and not os.path.exists(conn.key_file):
289
+ raise OSError(
290
+ f"Could not find the TLS key file, invalid path: {conn.key_file}"
291
+ )
292
+
293
+ def build_response(self, req, resp):
294
+ """Builds a :class:`Response <requests.Response>` object from a urllib3
295
+ response. This should not be called from user code, and is only exposed
296
+ for use when subclassing the
297
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`
298
+
299
+ :param req: The :class:`PreparedRequest <PreparedRequest>` used to generate the response.
300
+ :param resp: The urllib3 response object.
301
+ :rtype: requests.Response
302
+ """
303
+ response = Response()
304
+
305
+ # Fallback to None if there's no status_code, for whatever reason.
306
+ response.status_code = getattr(resp, "status", None)
307
+
308
+ # Make headers case-insensitive.
309
+ response.headers = CaseInsensitiveDict(getattr(resp, "headers", {}))
310
+
311
+ # Set encoding.
312
+ response.encoding = get_encoding_from_headers(response.headers)
313
+ response.raw = resp
314
+ response.reason = response.raw.reason
315
+
316
+ if isinstance(req.url, bytes):
317
+ response.url = req.url.decode("utf-8")
318
+ else:
319
+ response.url = req.url
320
+
321
+ # Add new cookies from the server.
322
+ extract_cookies_to_jar(response.cookies, req, resp)
323
+
324
+ # Give the Response some context.
325
+ response.request = req
326
+ response.connection = self
327
+
328
+ return response
329
+
330
+ def get_connection(self, url, proxies=None):
331
+ """Returns a urllib3 connection for the given URL. This should not be
332
+ called from user code, and is only exposed for use when subclassing the
333
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
334
+
335
+ :param url: The URL to connect to.
336
+ :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
337
+ :rtype: urllib3.ConnectionPool
338
+ """
339
+ proxy = select_proxy(url, proxies)
340
+
341
+ if proxy:
342
+ proxy = prepend_scheme_if_needed(proxy, "http")
343
+ proxy_url = parse_url(proxy)
344
+ if not proxy_url.host:
345
+ raise InvalidProxyURL(
346
+ "Please check proxy URL. It is malformed "
347
+ "and could be missing the host."
348
+ )
349
+ proxy_manager = self.proxy_manager_for(proxy)
350
+ conn = proxy_manager.connection_from_url(url)
351
+ else:
352
+ # Only scheme should be lower case
353
+ parsed = urlparse(url)
354
+ url = parsed.geturl()
355
+ conn = self.poolmanager.connection_from_url(url)
356
+
357
+ return conn
358
+
359
+ def close(self):
360
+ """Disposes of any internal state.
361
+
362
+ Currently, this closes the PoolManager and any active ProxyManager,
363
+ which closes any pooled connections.
364
+ """
365
+ self.poolmanager.clear()
366
+ for proxy in self.proxy_manager.values():
367
+ proxy.clear()
368
+
369
+ def request_url(self, request, proxies):
370
+ """Obtain the url to use when making the final request.
371
+
372
+ If the message is being sent through a HTTP proxy, the full URL has to
373
+ be used. Otherwise, we should only use the path portion of the URL.
374
+
375
+ This should not be called from user code, and is only exposed for use
376
+ when subclassing the
377
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
378
+
379
+ :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
380
+ :param proxies: A dictionary of schemes or schemes and hosts to proxy URLs.
381
+ :rtype: str
382
+ """
383
+ proxy = select_proxy(request.url, proxies)
384
+ scheme = urlparse(request.url).scheme
385
+
386
+ is_proxied_http_request = proxy and scheme != "https"
387
+ using_socks_proxy = False
388
+ if proxy:
389
+ proxy_scheme = urlparse(proxy).scheme.lower()
390
+ using_socks_proxy = proxy_scheme.startswith("socks")
391
+
392
+ url = request.path_url
393
+ if is_proxied_http_request and not using_socks_proxy:
394
+ url = urldefragauth(request.url)
395
+
396
+ return url
397
+
398
+ def add_headers(self, request, **kwargs):
399
+ """Add any headers needed by the connection. As of v2.0 this does
400
+ nothing by default, but is left for overriding by users that subclass
401
+ the :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
402
+
403
+ This should not be called from user code, and is only exposed for use
404
+ when subclassing the
405
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
406
+
407
+ :param request: The :class:`PreparedRequest <PreparedRequest>` to add headers to.
408
+ :param kwargs: The keyword arguments from the call to send().
409
+ """
410
+ pass
411
+
412
+ def proxy_headers(self, proxy):
413
+ """Returns a dictionary of the headers to add to any request sent
414
+ through a proxy. This works with urllib3 magic to ensure that they are
415
+ correctly sent to the proxy, rather than in a tunnelled request if
416
+ CONNECT is being used.
417
+
418
+ This should not be called from user code, and is only exposed for use
419
+ when subclassing the
420
+ :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
421
+
422
+ :param proxy: The url of the proxy being used for this request.
423
+ :rtype: dict
424
+ """
425
+ headers = {}
426
+ username, password = get_auth_from_url(proxy)
427
+
428
+ if username:
429
+ headers["Proxy-Authorization"] = _basic_auth_str(username, password)
430
+
431
+ return headers
432
+
433
+ def send(
434
+ self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None
435
+ ):
436
+ """Sends PreparedRequest object. Returns Response object.
437
+
438
+ :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
439
+ :param stream: (optional) Whether to stream the request content.
440
+ :param timeout: (optional) How long to wait for the server to send
441
+ data before giving up, as a float, or a :ref:`(connect timeout,
442
+ read timeout) <timeouts>` tuple.
443
+ :type timeout: float or tuple or urllib3 Timeout object
444
+ :param verify: (optional) Either a boolean, in which case it controls whether
445
+ we verify the server's TLS certificate, or a string, in which case it
446
+ must be a path to a CA bundle to use
447
+ :param cert: (optional) Any user-provided SSL certificate to be trusted.
448
+ :param proxies: (optional) The proxies dictionary to apply to the request.
449
+ :rtype: requests.Response
450
+ """
451
+
452
+ try:
453
+ conn = self.get_connection(request.url, proxies)
454
+ except LocationValueError as e:
455
+ raise InvalidURL(e, request=request)
456
+
457
+ self.cert_verify(conn, request.url, verify, cert)
458
+ url = self.request_url(request, proxies)
459
+ self.add_headers(
460
+ request,
461
+ stream=stream,
462
+ timeout=timeout,
463
+ verify=verify,
464
+ cert=cert,
465
+ proxies=proxies,
466
+ )
467
+
468
+ chunked = not (request.body is None or "Content-Length" in request.headers)
469
+
470
+ if isinstance(timeout, tuple):
471
+ try:
472
+ connect, read = timeout
473
+ timeout = TimeoutSauce(connect=connect, read=read)
474
+ except ValueError:
475
+ raise ValueError(
476
+ f"Invalid timeout {timeout}. Pass a (connect, read) timeout tuple, "
477
+ f"or a single float to set both timeouts to the same value."
478
+ )
479
+ elif isinstance(timeout, TimeoutSauce):
480
+ pass
481
+ else:
482
+ timeout = TimeoutSauce(connect=timeout, read=timeout)
483
+
484
+ try:
485
+ resp = conn.urlopen(
486
+ method=request.method,
487
+ url=url,
488
+ body=request.body,
489
+ headers=request.headers,
490
+ redirect=False,
491
+ assert_same_host=False,
492
+ preload_content=False,
493
+ decode_content=False,
494
+ retries=self.max_retries,
495
+ timeout=timeout,
496
+ chunked=chunked,
497
+ )
498
+
499
+ except (ProtocolError, OSError) as err:
500
+ raise ConnectionError(err, request=request)
501
+
502
+ except MaxRetryError as e:
503
+ if isinstance(e.reason, ConnectTimeoutError):
504
+ # TODO: Remove this in 3.0.0: see #2811
505
+ if not isinstance(e.reason, NewConnectionError):
506
+ raise ConnectTimeout(e, request=request)
507
+
508
+ if isinstance(e.reason, ResponseError):
509
+ raise RetryError(e, request=request)
510
+
511
+ if isinstance(e.reason, _ProxyError):
512
+ raise ProxyError(e, request=request)
513
+
514
+ if isinstance(e.reason, _SSLError):
515
+ # This branch is for urllib3 v1.22 and later.
516
+ raise SSLError(e, request=request)
517
+
518
+ raise ConnectionError(e, request=request)
519
+
520
+ except ClosedPoolError as e:
521
+ raise ConnectionError(e, request=request)
522
+
523
+ except _ProxyError as e:
524
+ raise ProxyError(e)
525
+
526
+ except (_SSLError, _HTTPError) as e:
527
+ if isinstance(e, _SSLError):
528
+ # This branch is for urllib3 versions earlier than v1.22
529
+ raise SSLError(e, request=request)
530
+ elif isinstance(e, ReadTimeoutError):
531
+ raise ReadTimeout(e, request=request)
532
+ elif isinstance(e, _InvalidHeader):
533
+ raise InvalidHeader(e, request=request)
534
+ else:
535
+ raise
536
+
537
+ return self.build_response(request, resp)