Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/requests/__init__.py: 62%
68 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# __
2# /__) _ _ _ _ _/ _
3# / ( (- (/ (/ (- _) / _)
4# /
6"""
7Requests HTTP Library
8~~~~~~~~~~~~~~~~~~~~~
10Requests is an HTTP library, written in Python, for human beings.
11Basic GET usage:
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
20... or POST:
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 }
34The other HTTP methods are supported - see `requests.api`. Full documentation
35is at <https://requests.readthedocs.io>.
37:copyright: (c) 2017 by Kenneth Reitz.
38:license: Apache 2.0, see LICENSE for more details.
39"""
41import warnings
43import urllib3
45from .exceptions import RequestsDependencyWarning
47try:
48 from charset_normalizer import __version__ as charset_normalizer_version
49except ImportError:
50 charset_normalizer_version = None
52try:
53 from chardet import __version__ as chardet_version
54except ImportError:
55 chardet_version = None
58def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
59 urllib3_version = urllib3_version.split(".")
60 assert urllib3_version != ["dev"] # Verify urllib3 isn't installed from git.
62 # Sometimes, urllib3 only reports its version as 16.1.
63 if len(urllib3_version) == 2: 63 ↛ 64line 63 didn't jump to line 64, because the condition on line 63 was never true
64 urllib3_version.append("0")
66 # Check urllib3 for compatibility.
67 major, minor, patch = urllib3_version # noqa: F811
68 major, minor, patch = int(major), int(minor), int(patch)
69 # urllib3 >= 1.21.1, <= 1.26
70 assert major == 1
71 assert minor >= 21
72 assert minor <= 26
74 # Check charset_normalizer for compatibility.
75 if chardet_version: 75 ↛ 76line 75 didn't jump to line 76, because the condition on line 75 was never true
76 major, minor, patch = chardet_version.split(".")[:3]
77 major, minor, patch = int(major), int(minor), int(patch)
78 # chardet_version >= 3.0.2, < 6.0.0
79 assert (3, 0, 2) <= (major, minor, patch) < (6, 0, 0)
80 elif charset_normalizer_version: 80 ↛ 86line 80 didn't jump to line 86, because the condition on line 80 was never false
81 major, minor, patch = charset_normalizer_version.split(".")[:3]
82 major, minor, patch = int(major), int(minor), int(patch)
83 # charset_normalizer >= 2.0.0 < 3.0.0
84 assert (2, 0, 0) <= (major, minor, patch) < (3, 0, 0)
85 else:
86 raise Exception("You need either charset_normalizer or chardet installed")
89def _check_cryptography(cryptography_version):
90 # cryptography < 1.3.4
91 try:
92 cryptography_version = list(map(int, cryptography_version.split(".")))
93 except ValueError:
94 return
96 if cryptography_version < [1, 3, 4]:
97 warning = "Old version of cryptography ({}) may cause slowdown.".format(
98 cryptography_version
99 )
100 warnings.warn(warning, RequestsDependencyWarning)
103# Check imported dependencies for compatibility.
104try:
105 check_compatibility(
106 urllib3.__version__, chardet_version, charset_normalizer_version
107 )
108except (AssertionError, ValueError):
109 warnings.warn(
110 "urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
111 "version!".format(
112 urllib3.__version__, chardet_version, charset_normalizer_version
113 ),
114 RequestsDependencyWarning,
115 )
117# Attempt to enable urllib3's fallback for SNI support
118# if the standard library doesn't support SNI or the
119# 'ssl' library isn't available.
120try:
121 try:
122 import ssl
123 except ImportError:
124 ssl = None
126 if not getattr(ssl, "HAS_SNI", False): 126 ↛ 127line 126 didn't jump to line 127, because the condition on line 126 was never true
127 from urllib3.contrib import pyopenssl
129 pyopenssl.inject_into_urllib3()
131 # Check cryptography version
132 from cryptography import __version__ as cryptography_version
134 _check_cryptography(cryptography_version)
135except ImportError:
136 pass
138# urllib3's DependencyWarnings should be silenced.
139from urllib3.exceptions import DependencyWarning
141warnings.simplefilter("ignore", DependencyWarning)
143# Set default logging handler to avoid "No handler found" warnings.
144import logging
145from logging import NullHandler
147from . import packages, utils
148from .__version__ import (
149 __author__,
150 __author_email__,
151 __build__,
152 __cake__,
153 __copyright__,
154 __description__,
155 __license__,
156 __title__,
157 __url__,
158 __version__,
159)
160from .api import delete, get, head, options, patch, post, put, request
161from .exceptions import (
162 ConnectionError,
163 ConnectTimeout,
164 FileModeWarning,
165 HTTPError,
166 JSONDecodeError,
167 ReadTimeout,
168 RequestException,
169 Timeout,
170 TooManyRedirects,
171 URLRequired,
172)
173from .models import PreparedRequest, Request, Response
174from .sessions import Session, session
175from .status_codes import codes
177logging.getLogger(__name__).addHandler(NullHandler())
179# FileModeWarnings go off per the default.
180warnings.simplefilter("default", FileModeWarning, append=True)