Skip to content

Commit

Permalink
fixup! Switch LGPL'd chardet for MIT licensed charset_normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb committed Apr 22, 2021
1 parent 65fe1ce commit ea671c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 3 additions & 2 deletions HISTORY.md
Expand Up @@ -8,8 +8,9 @@ dev

**Dependencies**

- Switch chardet for the MIT-licensed charset_normalizer to remove license
ambiguity for projects bundling requests.
- Switch chardet for the MIT-licensed charset_normalizer for Python3 to remove license
ambiguity for projects bundling requests. Python2 still depends upon the
LGPL'd module.

2.25.1 (2020-12-16)
-------------------
Expand Down
32 changes: 23 additions & 9 deletions requests/__init__.py
Expand Up @@ -41,12 +41,20 @@
"""

import urllib3
import charset_normalizer
import warnings
from .exceptions import RequestsDependencyWarning

try:
from charset_normalizer import __version__ as charset_normalizer_version
except ImportError:
charset_normalizer_version = None

try:
from chardet import __version__ as chardet_version
except ImportError:
chardet_version = None

def check_compatibility(urllib3_version, charset_normalizer_version):
def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version):
urllib3_version = urllib3_version.split('.')
assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.

Expand All @@ -63,10 +71,16 @@ def check_compatibility(urllib3_version, charset_normalizer_version):
assert minor <= 26

# Check charset_normalizer for compatibility.
major, minor, patch = charset_normalizer_version.split('.')[:3]
major, minor, patch = int(major), int(minor), int(patch)
# charset_normalizer >= 3.0.2, < 5.0.0
assert (1, 3, 5) <= (major, minor, patch) < (2, 0, 0)
if chardet_version:
major, minor, patch = chardet_version.split('.')[:3]
major, minor, patch = int(major), int(minor), int(patch)
# chardet_version >= 3.0.2, < 5.0.0
assert (3, 0, 2) <= (major, minor, patch) < (5, 0, 0)
else:
major, minor, patch = charset_normalizer_version.split('.')[:3]
major, minor, patch = int(major), int(minor), int(patch)
# charset_normalizer >= 1.3.5, < 2.0.0
assert (1, 3, 5) <= (major, minor, patch) < (2, 0, 0)


def _check_cryptography(cryptography_version):
Expand All @@ -82,10 +96,10 @@ def _check_cryptography(cryptography_version):

# Check imported dependencies for compatibility.
try:
check_compatibility(urllib3.__version__, charset_normalizer.__version__)
check_compatibility(urllib3.__version__, chardet_version, charset_normalizer_version)
except (AssertionError, ValueError):
warnings.warn("urllib3 ({}) or charset_normalizer ({}) doesn't match a supported "
"version!".format(urllib3.__version__, charset_normalizer.__version__),
warnings.warn("urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported "
"version!".format(urllib3.__version__, chardet_version, charset_normalizer_version),
RequestsDependencyWarning)

# Attempt to enable urllib3's fallback for SNI support
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -41,7 +41,8 @@ def run_tests(self):
packages = ['requests']

requires = [
'charset_normalizer>=1.3.5,<2',
'charset_normalizer>=1.3.5,<2; python_version >= "3"',
'chardet>=3.0.2,<5; python_version < "3"',
'idna>=2.5,<3',
'urllib3>=1.21.1,<1.27',
'certifi>=2017.4.17'
Expand Down

0 comments on commit ea671c4

Please sign in to comment.