From 1c4afdb4ab3c8b6b9fd0a5740015ce92aa7046a4 Mon Sep 17 00:00:00 2001 From: TAHRI Ahmed R Date: Sun, 8 Oct 2023 08:59:29 +0200 Subject: [PATCH] :wrench: Remove charset-normalizer check in top-lvl import and change the RequestsDependencyWarning text (#32) Also remove unused filter on FileModeWarning as it was removed in 3.0 --- src/niquests/__init__.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/niquests/__init__.py b/src/niquests/__init__.py index 1a6b1f1444..313a2d4d53 100644 --- a/src/niquests/__init__.py +++ b/src/niquests/__init__.py @@ -42,41 +42,30 @@ import warnings -import charset_normalizer import urllib3 from .exceptions import RequestsDependencyWarning -def check_compatibility(urllib3_version, charset_normalizer_version) -> None: - urllib3_version = urllib3_version.split(".") - assert urllib3_version != ["dev"] # Verify urllib3 isn't installed from git. - - # Sometimes, urllib3 only reports its version as 16.1. - if len(urllib3_version) == 2: - urllib3_version.append("0") +def check_compatibility(urllib3_version: str) -> None: + urllib3_version_split = [int(n) for n in urllib3_version.split(".")] # Check urllib3 for compatibility. - major, minor, patch = urllib3_version # noqa: F811 - major, minor, patch = int(major), int(minor), int(patch) + major, minor, patch = urllib3_version_split # noqa: F811 # urllib3 >= 2.0.9xx assert major >= 2 assert patch >= 900 - # Check charset_normalizer for compatibility. - major, minor, patch = charset_normalizer_version.split(".")[:3] - major, minor, patch = int(major), int(minor), int(patch) - # charset_normalizer >= 2.0.0 < 4.0.0 - assert (2, 0, 0) <= (major, minor, patch) < (4, 0, 0) - # Check imported dependencies for compatibility. try: - check_compatibility(urllib3.__version__, charset_normalizer.__version__) + check_compatibility(urllib3.__version__) except (AssertionError, ValueError): warnings.warn( - "urllib3 ({}) or charset_normalizer ({}) doesn't match a supported " - "version!".format(urllib3.__version__, charset_normalizer.__version__), + f"""Niquests require urllib3.future installed in your environment. + Installed urllib3 yield version {urllib3.__version__}. Make sure the patch revision is greater or equal to 900. + You may fix this issue by executing `python -m pip uninstall urllib3 urllib3.future`, + then `python -m pip install urllib3.future -U`.""", RequestsDependencyWarning, ) @@ -121,10 +110,6 @@ def check_compatibility(urllib3_version, charset_normalizer_version) -> None: logging.getLogger(__name__).addHandler(NullHandler()) -# FileModeWarnings go off per the default. -warnings.simplefilter("default", FileModeWarning, append=True) - - __all__ = ( "RequestsDependencyWarning", "utils",