From 065900d9fe8e10733fd5912e00b67f43ce8b2243 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 20 Sep 2023 07:37:36 +0200 Subject: [PATCH] :pencil: replace requests import to niquests in docstrings Also move constants DEFAUL_POOL* to _constant.py --- src/niquests/__init__.py | 7 +++---- src/niquests/_constant.py | 4 ++++ src/niquests/adapters.py | 13 ++++--------- src/niquests/api.py | 4 ++-- src/niquests/models.py | 10 +++++----- src/niquests/sessions.py | 6 +++--- src/niquests/status_codes.py | 8 ++++---- 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/niquests/__init__.py b/src/niquests/__init__.py index 4ebf0d58eb..e3345b7150 100644 --- a/src/niquests/__init__.py +++ b/src/niquests/__init__.py @@ -57,10 +57,9 @@ def check_compatibility(urllib3_version, charset_normalizer_version) -> None: # Check urllib3 for compatibility. major, minor, patch = urllib3_version # noqa: F811 major, minor, patch = int(major), int(minor), int(patch) - # urllib3 >= 1.21.1 - assert major >= 1 - if major == 1: - assert minor >= 21 + # urllib3 >= 2.0.9xx + assert major >= 2 + assert patch >= 900 # Check charset_normalizer for compatibility. major, minor, patch = charset_normalizer_version.split(".")[:3] diff --git a/src/niquests/_constant.py b/src/niquests/_constant.py index dee6761aec..c558412d71 100644 --- a/src/niquests/_constant.py +++ b/src/niquests/_constant.py @@ -4,3 +4,7 @@ READ_DEFAULT_TIMEOUT: TimeoutType = 30 #: Default timeout (total) assigned for DELETE, PUT, PATCH, and POST. WRITE_DEFAULT_TIMEOUT: TimeoutType = 120 + +DEFAULT_POOLBLOCK: bool = False +DEFAULT_POOLSIZE: int = 10 +DEFAULT_RETRIES: int = 0 diff --git a/src/niquests/adapters.py b/src/niquests/adapters.py index 328f7b6d84..e622a6e924 100644 --- a/src/niquests/adapters.py +++ b/src/niquests/adapters.py @@ -31,6 +31,7 @@ from urllib3.util import parse_url from urllib3.util.retry import Retry +from ._constant import DEFAULT_POOLBLOCK, DEFAULT_POOLSIZE, DEFAULT_RETRIES from ._typing import CacheLayerAltSvcType, ProxyType, TLSClientCertType, TLSVerifyType from .auth import _basic_auth_str from .cookies import extract_cookies_to_jar @@ -66,12 +67,6 @@ def SOCKSProxyManager(*args: typing.Any, **kwargs: typing.Any) -> None: # type: raise InvalidSchema("Missing dependencies for SOCKS support.") -DEFAULT_POOLBLOCK = False -DEFAULT_POOLSIZE = 10 -DEFAULT_RETRIES = 0 -DEFAULT_POOL_TIMEOUT = None - - class BaseAdapter: """The Base Transport Adapter""" @@ -129,9 +124,9 @@ class HTTPAdapter(BaseAdapter): Usage:: - >>> import requests - >>> s = requests.Session() - >>> a = requests.adapters.HTTPAdapter(max_retries=3) + >>> import niquests + >>> s = niquests.Session() + >>> a = niquests.adapters.HTTPAdapter(max_retries=3) >>> s.mount('http://', a) """ diff --git a/src/niquests/api.py b/src/niquests/api.py index 74153685ec..c2f428fa42 100644 --- a/src/niquests/api.py +++ b/src/niquests/api.py @@ -86,8 +86,8 @@ def request( Usage:: - >>> import requests - >>> req = requests.request('GET', 'https://httpbin.org/get') + >>> import niquests + >>> req = niquests.request('GET', 'https://httpbin.org/get') >>> req """ diff --git a/src/niquests/models.py b/src/niquests/models.py index f98debb511..a564c86b7c 100644 --- a/src/niquests/models.py +++ b/src/niquests/models.py @@ -124,8 +124,8 @@ class Request: Usage:: - >>> import requests - >>> req = requests.Request('GET', 'https://httpbin.org/get') + >>> import niquests + >>> req = niquests.Request('GET', 'https://httpbin.org/get') >>> req.prepare() """ @@ -219,13 +219,13 @@ class PreparedRequest: Usage:: - >>> import requests - >>> req = requests.Request('GET', 'https://httpbin.org/get') + >>> import niquests + >>> req = niquests.Request('GET', 'https://httpbin.org/get') >>> r = req.prepare() >>> r - >>> s = requests.Session() + >>> s = niquests.Session() >>> s.send(r) """ diff --git a/src/niquests/sessions.py b/src/niquests/sessions.py index 0607b0d5b1..015354bc18 100644 --- a/src/niquests/sessions.py +++ b/src/niquests/sessions.py @@ -136,14 +136,14 @@ class Session: Basic Usage:: - >>> import requests - >>> s = requests.Session() + >>> import niquests + >>> s = niquests.Session() >>> s.get('https://httpbin.org/get') Or as a context manager:: - >>> with requests.Session() as s: + >>> with niquests.Session() as s: ... s.get('https://httpbin.org/get') """ diff --git a/src/niquests/status_codes.py b/src/niquests/status_codes.py index 4bd072be97..d16ed9f5f6 100644 --- a/src/niquests/status_codes.py +++ b/src/niquests/status_codes.py @@ -5,12 +5,12 @@ Example:: - >>> import requests - >>> requests.codes['temporary_redirect'] + >>> import niquests + >>> niquests.codes['temporary_redirect'] 307 - >>> requests.codes.teapot + >>> niquests.codes.teapot 418 - >>> requests.codes['\o/'] + >>> niquests.codes['\o/'] 200 Some codes have multiple names, and both upper- and lower-case versions of