convert version compatibility checks to warning
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nate Prewitt · committed by Nate Prewitt · parent 4f1b17c · Browse files · 2 files·+35 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+35 added−22 removed
- other:+35 added−22 removed
Provenance
- Commit
d8e2367- Tree
1f0638f- Author
Nate Prewitt <Nate.Prewitt@gmail.com>- Committer
Nate Prewitt <Nate.Prewitt@gmail.com>- Parent
4f1b17c
2 files changed+35 added−22 removed
modified:requests/__init__.py+30 added-22 removed
38 unmodified lines39 :copyright: (c) 2017 by Kenneth Reitz.40 :license: Apache 2.0, see LICENSE for more details.41 """42 43-# Check urllib3 for compatibility.43 import urllib345-urllib3_version = urllib3.__version__.split('.')46-# Sometimes, urllib3 only reports its version as 16.1.47-if len(urllib3_version) == 2:48- urllib3_version.append('0')49-major, minor, patch = urllib3_version50-major, minor, patch = int(major), int(minor), int(patch)51-# urllib3 >= 1.21.1, < 1.2252-try:44+import chardet45+import warnings46+from .exceptions import RequestsDependencyWarning47+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: F81159+ major, minor, patch = int(major), int(minor), int(patch)60+ # urllib3 >= 1.21.1, < 1.2261 assert major == 162 assert minor >= 2163 assert minor <= 2256-except AssertionError:57- raise RuntimeError('Requests dependency \'urllib3\' must be version >= 1.21.1, < 1.22!')64 59-60-# Check chardet for compatibility.61-import chardet62-major, minor, patch = chardet.__version__.split('.')[:3]63-major, minor, patch = int(major), int(minor), int(patch)64-# chardet >= 3.0.2, < 3.1.065+ # 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.065-try:69 assert major == 370 assert minor < 171 assert patch >= 269-except AssertionError:70- raise RuntimeError('Requests dependency \'chardet\' must be version >= 3.0.2, < 3.1.0!')72 73+74+# Check imported dependencies for compatibility.75+try:76+ check_compatibility(urllib3.__version__, chardet.__version__)77+except (AssertionError, ValueError):78+ warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "79+ "version!".format(urllib3.__version__, chardet.__version__),80+ RequestsDependencyWarning)81+82 # Attempt to enable urllib3's SNI support, if possible83 try:84 from urllib3.contrib import pyopenssl85 pyopenssl.inject_into_urllib3()86 except ImportError:87 pass88 79-import warnings80-89 # urllib3's DependencyWarnings should be silenced.90 from urllib3.exceptions import DependencyWarning91 warnings.simplefilter('ignore', DependencyWarning)92 29 unmodified linesmodified:requests/exceptions.py+5 added
113 unmodified lines114 115 class FileModeWarning(RequestsWarning, DeprecationWarning):116 """A file was opened in text mode, but Requests determined its binary length."""117 pass118+119+120+class RequestsDependencyWarning(RequestsWarning):121+ """An imported dependency doesn't match the expected version range."""122+ pass