Skip to content

Commit

Permalink
🔧 Remove charset-normalizer check in top-lvl import and change the Re…
Browse files Browse the repository at this point in the history
…questsDependencyWarning text (#32)

Also remove unused filter on FileModeWarning as it was removed in 3.0
  • Loading branch information
Ousret authored Oct 8, 2023
1 parent b064e47 commit 1c4afdb
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions src/niquests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 1c4afdb

Please sign in to comment.