comparison env/lib/python3.9/site-packages/requests/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
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 import urllib3
44 import chardet
45 import warnings
46 from .exceptions import RequestsDependencyWarning
47
48
49 def check_compatibility(urllib3_version, chardet_version):
50 urllib3_version = urllib3_version.split('.')
51 assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.
52
53 # Sometimes, urllib3 only reports its version as 16.1.
54 if len(urllib3_version) == 2:
55 urllib3_version.append('0')
56
57 # Check urllib3 for compatibility.
58 major, minor, patch = urllib3_version # noqa: F811
59 major, minor, patch = int(major), int(minor), int(patch)
60 # urllib3 >= 1.21.1, <= 1.26
61 assert major == 1
62 assert minor >= 21
63 assert minor <= 26
64
65 # Check chardet for compatibility.
66 major, minor, patch = chardet_version.split('.')[:3]
67 major, minor, patch = int(major), int(minor), int(patch)
68 # chardet >= 3.0.2, < 5.0.0
69 assert (3, 0, 2) <= (major, minor, patch) < (5, 0, 0)
70
71
72 def _check_cryptography(cryptography_version):
73 # cryptography < 1.3.4
74 try:
75 cryptography_version = list(map(int, cryptography_version.split('.')))
76 except ValueError:
77 return
78
79 if cryptography_version < [1, 3, 4]:
80 warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
81 warnings.warn(warning, RequestsDependencyWarning)
82
83 # Check imported dependencies for compatibility.
84 try:
85 check_compatibility(urllib3.__version__, chardet.__version__)
86 except (AssertionError, ValueError):
87 warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
88 "version!".format(urllib3.__version__, chardet.__version__),
89 RequestsDependencyWarning)
90
91 # Attempt to enable urllib3's fallback for SNI support
92 # if the standard library doesn't support SNI or the
93 # 'ssl' library isn't available.
94 try:
95 try:
96 import ssl
97 except ImportError:
98 ssl = None
99
100 if not getattr(ssl, "HAS_SNI", False):
101 from urllib3.contrib import pyopenssl
102 pyopenssl.inject_into_urllib3()
103
104 # Check cryptography version
105 from cryptography import __version__ as cryptography_version
106 _check_cryptography(cryptography_version)
107 except ImportError:
108 pass
109
110 # urllib3's DependencyWarnings should be silenced.
111 from urllib3.exceptions import DependencyWarning
112 warnings.simplefilter('ignore', DependencyWarning)
113
114 from .__version__ import __title__, __description__, __url__, __version__
115 from .__version__ import __build__, __author__, __author_email__, __license__
116 from .__version__ import __copyright__, __cake__
117
118 from . import utils
119 from . import packages
120 from .models import Request, Response, PreparedRequest
121 from .api import request, get, head, post, patch, put, delete, options
122 from .sessions import session, Session
123 from .status_codes import codes
124 from .exceptions import (
125 RequestException, Timeout, URLRequired,
126 TooManyRedirects, HTTPError, ConnectionError,
127 FileModeWarning, ConnectTimeout, ReadTimeout
128 )
129
130 # Set default logging handler to avoid "No handler found" warnings.
131 import logging
132 from logging import NullHandler
133
134 logging.getLogger(__name__).addHandler(NullHandler())
135
136 # FileModeWarnings go off per the default.
137 warnings.simplefilter('default', FileModeWarning, append=True)