Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hhhrrrttt222111
GitHub Repository: hhhrrrttt222111/Dorkify
Path: blob/master/venv/Lib/site-packages/requests/__init__.py
811 views
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.25
61
assert major == 1
62
assert minor >= 21
63
assert minor <= 25
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, < 3.1.0
69
assert major == 3
70
assert minor < 1
71
assert patch >= 2
72
73
74
def _check_cryptography(cryptography_version):
75
# cryptography < 1.3.4
76
try:
77
cryptography_version = list(map(int, cryptography_version.split('.')))
78
except ValueError:
79
return
80
81
if cryptography_version < [1, 3, 4]:
82
warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
83
warnings.warn(warning, RequestsDependencyWarning)
84
85
# Check imported dependencies for compatibility.
86
try:
87
check_compatibility(urllib3.__version__, chardet.__version__)
88
except (AssertionError, ValueError):
89
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
90
"version!".format(urllib3.__version__, chardet.__version__),
91
RequestsDependencyWarning)
92
93
# Attempt to enable urllib3's fallback for SNI support
94
# if the standard library doesn't support SNI or the
95
# 'ssl' library isn't available.
96
try:
97
try:
98
import ssl
99
except ImportError:
100
ssl = None
101
102
if not getattr(ssl, "HAS_SNI", False):
103
from urllib3.contrib import pyopenssl
104
pyopenssl.inject_into_urllib3()
105
106
# Check cryptography version
107
from cryptography import __version__ as cryptography_version
108
_check_cryptography(cryptography_version)
109
except ImportError:
110
pass
111
112
# urllib3's DependencyWarnings should be silenced.
113
from urllib3.exceptions import DependencyWarning
114
warnings.simplefilter('ignore', DependencyWarning)
115
116
from .__version__ import __title__, __description__, __url__, __version__
117
from .__version__ import __build__, __author__, __author_email__, __license__
118
from .__version__ import __copyright__, __cake__
119
120
from . import utils
121
from . import packages
122
from .models import Request, Response, PreparedRequest
123
from .api import request, get, head, post, patch, put, delete, options
124
from .sessions import session, Session
125
from .status_codes import codes
126
from .exceptions import (
127
RequestException, Timeout, URLRequired,
128
TooManyRedirects, HTTPError, ConnectionError,
129
FileModeWarning, ConnectTimeout, ReadTimeout
130
)
131
132
# Set default logging handler to avoid "No handler found" warnings.
133
import logging
134
from logging import NullHandler
135
136
logging.getLogger(__name__).addHandler(NullHandler())
137
138
# FileModeWarnings go off per the default.
139
warnings.simplefilter('default', FileModeWarning, append=True)
140
141