1- # -*- coding: utf-8 -*-
2-
31# __
42# /__) _ _ _ _ _/ _
53# / ( (- (/ (/ (- _) / _)
4038:license: Apache 2.0, see LICENSE for more details.
4139"""
4240
43- import urllib3
4441import warnings
42+
43+ import urllib3
44+
4545from .exceptions import RequestsDependencyWarning
4646
4747try :
5454except ImportError :
5555 chardet_version = None
5656
57+
5758def check_compatibility (urllib3_version , chardet_version , charset_normalizer_version ):
58- urllib3_version = urllib3_version .split ('.' )
59- assert urllib3_version != [' dev' ] # Verify urllib3 isn't installed from git.
59+ urllib3_version = urllib3_version .split ("." )
60+ assert urllib3_version != [" dev" ] # Verify urllib3 isn't installed from git.
6061
6162 # Sometimes, urllib3 only reports its version as 16.1.
6263 if len (urllib3_version ) == 2 :
63- urllib3_version .append ('0' )
64+ urllib3_version .append ("0" )
6465
6566 # Check urllib3 for compatibility.
6667 major , minor , patch = urllib3_version # noqa: F811
@@ -72,36 +73,46 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
7273
7374 # Check charset_normalizer for compatibility.
7475 if chardet_version :
75- major , minor , patch = chardet_version .split ('.' )[:3 ]
76+ major , minor , patch = chardet_version .split ("." )[:3 ]
7677 major , minor , patch = int (major ), int (minor ), int (patch )
7778 # chardet_version >= 3.0.2, < 5.0.0
7879 assert (3 , 0 , 2 ) <= (major , minor , patch ) < (5 , 0 , 0 )
7980 elif charset_normalizer_version :
80- major , minor , patch = charset_normalizer_version .split ('.' )[:3 ]
81+ major , minor , patch = charset_normalizer_version .split ("." )[:3 ]
8182 major , minor , patch = int (major ), int (minor ), int (patch )
8283 # charset_normalizer >= 2.0.0 < 3.0.0
8384 assert (2 , 0 , 0 ) <= (major , minor , patch ) < (3 , 0 , 0 )
8485 else :
8586 raise Exception ("You need either charset_normalizer or chardet installed" )
8687
88+
8789def _check_cryptography (cryptography_version ):
8890 # cryptography < 1.3.4
8991 try :
90- cryptography_version = list (map (int , cryptography_version .split ('.' )))
92+ cryptography_version = list (map (int , cryptography_version .split ("." )))
9193 except ValueError :
9294 return
9395
9496 if cryptography_version < [1 , 3 , 4 ]:
95- warning = 'Old version of cryptography ({}) may cause slowdown.' .format (cryptography_version )
97+ warning = "Old version of cryptography ({}) may cause slowdown." .format (
98+ cryptography_version
99+ )
96100 warnings .warn (warning , RequestsDependencyWarning )
97101
102+
98103# Check imported dependencies for compatibility.
99104try :
100- check_compatibility (urllib3 .__version__ , chardet_version , charset_normalizer_version )
105+ check_compatibility (
106+ urllib3 .__version__ , chardet_version , charset_normalizer_version
107+ )
101108except (AssertionError , ValueError ):
102- warnings .warn ("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
103- "version!" .format (urllib3 .__version__ , chardet_version , charset_normalizer_version ),
104- RequestsDependencyWarning )
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+ )
105116
106117# Attempt to enable urllib3's fallback for SNI support
107118# if the standard library doesn't support SNI or the
@@ -114,39 +125,56 @@ def _check_cryptography(cryptography_version):
114125
115126 if not getattr (ssl , "HAS_SNI" , False ):
116127 from urllib3 .contrib import pyopenssl
128+
117129 pyopenssl .inject_into_urllib3 ()
118130
119131 # Check cryptography version
120132 from cryptography import __version__ as cryptography_version
133+
121134 _check_cryptography (cryptography_version )
122135except ImportError :
123136 pass
124137
125138# urllib3's DependencyWarnings should be silenced.
126139from urllib3 .exceptions import DependencyWarning
127- warnings .simplefilter ('ignore' , DependencyWarning )
128140
129- from .__version__ import __title__ , __description__ , __url__ , __version__
130- from .__version__ import __build__ , __author__ , __author_email__ , __license__
131- from .__version__ import __copyright__ , __cake__
132-
133- from . import utils
134- from . import packages
135- from .models import Request , Response , PreparedRequest
136- from .api import request , get , head , post , patch , put , delete , options
137- from .sessions import session , Session
138- from .status_codes import codes
139- from .exceptions import (
140- RequestException , Timeout , URLRequired ,
141- TooManyRedirects , HTTPError , ConnectionError ,
142- FileModeWarning , ConnectTimeout , ReadTimeout , JSONDecodeError
143- )
141+ warnings .simplefilter ("ignore" , DependencyWarning )
144142
145143# Set default logging handler to avoid "No handler found" warnings.
146144import logging
147145from logging import NullHandler
148146
147+ from . import packages , utils
148+ from .__version__ import (
149+ __author__ ,
150+ __author_email__ ,
151+ __build__ ,
152+ __cake__ ,
153+ __copyright__ ,
154+ __description__ ,
155+ __license__ ,
156+ __title__ ,
157+ __url__ ,
158+ __version__ ,
159+ )
160+ from .api import delete , get , head , options , patch , post , put , request
161+ from .exceptions import (
162+ ConnectionError ,
163+ ConnectTimeout ,
164+ FileModeWarning ,
165+ HTTPError ,
166+ JSONDecodeError ,
167+ ReadTimeout ,
168+ RequestException ,
169+ Timeout ,
170+ TooManyRedirects ,
171+ URLRequired ,
172+ )
173+ from .models import PreparedRequest , Request , Response
174+ from .sessions import Session , session
175+ from .status_codes import codes
176+
149177logging .getLogger (__name__ ).addHandler (NullHandler ())
150178
151179# FileModeWarnings go off per the default.
152- warnings .simplefilter (' default' , FileModeWarning , append = True )
180+ warnings .simplefilter (" default" , FileModeWarning , append = True )
0 commit comments