Browse Source

HUE-9422 [core] Apply HUE-9045 on requests-2.23.0

Ying Chen 5 years ago
parent
commit
faf09df471

+ 3 - 13
desktop/core/ext-py/requests-2.23.0/requests/__init__.py

@@ -41,12 +41,11 @@ is at <https://requests.readthedocs.io>.
 """
 
 import urllib3
-import chardet
 import warnings
 from .exceptions import RequestsDependencyWarning
 
 
-def check_compatibility(urllib3_version, chardet_version):
+def check_compatibility(urllib3_version):
     urllib3_version = urllib3_version.split('.')
     assert urllib3_version != ['dev']  # Verify urllib3 isn't installed from git.
 
@@ -62,15 +61,6 @@ def check_compatibility(urllib3_version, chardet_version):
     assert minor >= 21
     assert minor <= 25
 
-    # Check chardet for compatibility.
-    major, minor, patch = chardet_version.split('.')[:3]
-    major, minor, patch = int(major), int(minor), int(patch)
-    # chardet >= 3.0.2, < 3.1.0
-    assert major == 3
-    assert minor < 1
-    assert patch >= 2
-
-
 def _check_cryptography(cryptography_version):
     # cryptography < 1.3.4
     try:
@@ -84,10 +74,10 @@ def _check_cryptography(cryptography_version):
 
 # Check imported dependencies for compatibility.
 try:
-    check_compatibility(urllib3.__version__, chardet.__version__)
+    check_compatibility(urllib3.__version__)
 except (AssertionError, ValueError):
     warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
-                  "version!".format(urllib3.__version__, chardet.__version__),
+                  "version!".format(urllib3.__version__),
                   RequestsDependencyWarning)
 
 # Attempt to enable urllib3's SNI support, if possible

+ 0 - 2
desktop/core/ext-py/requests-2.23.0/requests/compat.py

@@ -8,8 +8,6 @@ This module handles import compatibility issues between Python 2 and
 Python 3.
 """
 
-import chardet
-
 import sys
 
 # -------

+ 0 - 3
desktop/core/ext-py/requests-2.23.0/requests/help.py

@@ -8,7 +8,6 @@ import ssl
 
 import idna
 import urllib3
-import chardet
 
 from . import __version__ as requests_version
 
@@ -71,7 +70,6 @@ def info():
 
     implementation_info = _implementation()
     urllib3_info = {'version': urllib3.__version__}
-    chardet_info = {'version': chardet.__version__}
 
     pyopenssl_info = {
         'version': None,
@@ -101,7 +99,6 @@ def info():
         'using_pyopenssl': pyopenssl is not None,
         'pyOpenSSL': pyopenssl_info,
         'urllib3': urllib3_info,
-        'chardet': chardet_info,
         'cryptography': cryptography_info,
         'idna': idna_info,
         'requests': {

+ 16 - 3
desktop/core/ext-py/requests-2.23.0/requests/models.py

@@ -38,7 +38,7 @@ from .utils import (
 from .compat import (
     Callable, Mapping,
     cookielib, urlunparse, urlsplit, urlencode, str, bytes,
-    is_py2, chardet, builtin_str, basestring)
+    is_py2, builtin_str, basestring)
 from .compat import json as complexjson
 from .status_codes import codes
 
@@ -56,6 +56,8 @@ DEFAULT_REDIRECT_LIMIT = 30
 CONTENT_CHUNK_SIZE = 10 * 1024
 ITER_CHUNK_SIZE = 512
 
+from desktop.lib.python_util import check_encoding
+
 
 class RequestEncodingMixin(object):
     @property
@@ -724,8 +726,19 @@ class Response(object):
 
     @property
     def apparent_encoding(self):
-        """The apparent encoding, provided by the chardet library."""
-        return chardet.detect(self.content)['encoding']
+        try:
+            import chardet
+            chardet_version = chardet.__version__
+            major, minor, patch = chardet_version.split('.')[:3]
+            major, minor, patch = int(major), int(minor), int(patch)
+            # chardet >= 3.0.2, < 3.1.0
+            assert major == 3
+            assert minor < 1
+            assert patch >= 2
+        except (ImportError, AssertionError) as e:
+            return check_encoding(self.content)
+        else:
+            return chardet.detect(self.content)['encoding']
 
     def iter_content(self, chunk_size=1, decode_unicode=False):
         """Iterates over the response data.  When stream=True is set on the

+ 1 - 1
desktop/core/ext-py/requests-2.23.0/requests/packages.py

@@ -3,7 +3,7 @@ import sys
 # This code exists for backwards compatibility reasons.
 # I don't like it either. Just look the other way. :)
 
-for package in ('urllib3', 'idna', 'chardet'):
+for package in ('urllib3', 'idna'):
     locals()[package] = __import__(package)
     # This traversal is apparently necessary such that the identities are
     # preserved (requests.packages.urllib3.* is urllib3.*)