Path: blob/master/venv/Lib/site-packages/requests/__init__.py
811 views
# -*- coding: utf-8 -*-12# __3# /__) _ _ _ _ _/ _4# / ( (- (/ (/ (- _) / _)5# /67"""8Requests HTTP Library9~~~~~~~~~~~~~~~~~~~~~1011Requests is an HTTP library, written in Python, for human beings.12Basic GET usage:1314>>> import requests15>>> r = requests.get('https://www.python.org')16>>> r.status_code1720018>>> b'Python is a programming language' in r.content19True2021... or POST:2223>>> payload = dict(key1='value1', key2='value2')24>>> r = requests.post('https://httpbin.org/post', data=payload)25>>> print(r.text)26{27...28"form": {29"key1": "value1",30"key2": "value2"31},32...33}3435The other HTTP methods are supported - see `requests.api`. Full documentation36is at <https://requests.readthedocs.io>.3738:copyright: (c) 2017 by Kenneth Reitz.39:license: Apache 2.0, see LICENSE for more details.40"""4142import urllib343import chardet44import warnings45from .exceptions import RequestsDependencyWarning464748def check_compatibility(urllib3_version, chardet_version):49urllib3_version = urllib3_version.split('.')50assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.5152# Sometimes, urllib3 only reports its version as 16.1.53if len(urllib3_version) == 2:54urllib3_version.append('0')5556# Check urllib3 for compatibility.57major, minor, patch = urllib3_version # noqa: F81158major, minor, patch = int(major), int(minor), int(patch)59# urllib3 >= 1.21.1, <= 1.2560assert major == 161assert minor >= 2162assert minor <= 256364# Check chardet for compatibility.65major, minor, patch = chardet_version.split('.')[:3]66major, minor, patch = int(major), int(minor), int(patch)67# chardet >= 3.0.2, < 3.1.068assert major == 369assert minor < 170assert patch >= 2717273def _check_cryptography(cryptography_version):74# cryptography < 1.3.475try:76cryptography_version = list(map(int, cryptography_version.split('.')))77except ValueError:78return7980if cryptography_version < [1, 3, 4]:81warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)82warnings.warn(warning, RequestsDependencyWarning)8384# Check imported dependencies for compatibility.85try:86check_compatibility(urllib3.__version__, chardet.__version__)87except (AssertionError, ValueError):88warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "89"version!".format(urllib3.__version__, chardet.__version__),90RequestsDependencyWarning)9192# Attempt to enable urllib3's fallback for SNI support93# if the standard library doesn't support SNI or the94# 'ssl' library isn't available.95try:96try:97import ssl98except ImportError:99ssl = None100101if not getattr(ssl, "HAS_SNI", False):102from urllib3.contrib import pyopenssl103pyopenssl.inject_into_urllib3()104105# Check cryptography version106from cryptography import __version__ as cryptography_version107_check_cryptography(cryptography_version)108except ImportError:109pass110111# urllib3's DependencyWarnings should be silenced.112from urllib3.exceptions import DependencyWarning113warnings.simplefilter('ignore', DependencyWarning)114115from .__version__ import __title__, __description__, __url__, __version__116from .__version__ import __build__, __author__, __author_email__, __license__117from .__version__ import __copyright__, __cake__118119from . import utils120from . import packages121from .models import Request, Response, PreparedRequest122from .api import request, get, head, post, patch, put, delete, options123from .sessions import session, Session124from .status_codes import codes125from .exceptions import (126RequestException, Timeout, URLRequired,127TooManyRedirects, HTTPError, ConnectionError,128FileModeWarning, ConnectTimeout, ReadTimeout129)130131# Set default logging handler to avoid "No handler found" warnings.132import logging133from logging import NullHandler134135logging.getLogger(__name__).addHandler(NullHandler())136137# FileModeWarnings go off per the default.138warnings.simplefilter('default', FileModeWarning, append=True)139140141