diff --git a/HISTORY.md b/HISTORY.md index 8b02990495..cbf2f5e0a6 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,15 @@ Release History =============== +3.5.2 (2024-03-05) +------------------ + +**Fixed** +- ImportError in an attempt to retrieve `ConnectionInfo`. + +**Changed** +- General performance improvements. + 3.5.1 (2024-03-04) ------------------ diff --git a/src/niquests/__version__.py b/src/niquests/__version__.py index 9d5100c6c7..d0a4e38883 100644 --- a/src/niquests/__version__.py +++ b/src/niquests/__version__.py @@ -9,9 +9,9 @@ __url__: str = "https://niquests.readthedocs.io" __version__: str -__version__ = "3.5.1" +__version__ = "3.5.2" -__build__: int = 0x030501 +__build__: int = 0x030502 __author__: str = "Kenneth Reitz" __author_email__: str = "me@kennethreitz.org" __license__: str = "Apache-2.0" diff --git a/src/niquests/models.py b/src/niquests/models.py index ec25e261be..a1dd470860 100644 --- a/src/niquests/models.py +++ b/src/niquests/models.py @@ -995,7 +995,7 @@ def lazy(self) -> bool: Determine if response isn't received and is actually a placeholder. Only significant if request was sent through a multiplexed connection. """ - return hasattr(self, "raw") and self.raw is None and hasattr(self, "_promise") + return self.raw is None and hasattr(self, "_promise") def _gather(self) -> None: """internals used for lazy responses. Do not try to access this unless you know what you are doing.""" @@ -1012,6 +1012,7 @@ def __getattribute__(self, item): ) else: self._gather() + return super().__getattribute__(item) def __enter__(self): diff --git a/src/niquests/structures.py b/src/niquests/structures.py index d8147bbb9b..8d5114ceb5 100644 --- a/src/niquests/structures.py +++ b/src/niquests/structures.py @@ -9,7 +9,6 @@ import threading import typing -from collections import OrderedDict from collections.abc import Mapping, MutableMapping from .exceptions import InvalidHeader @@ -18,6 +17,8 @@ def _ensure_str_or_bytes( key: typing.Any, value: typing.Any ) -> tuple[bytes | str, bytes | str]: + if isinstance(key, (bytes, str)) and isinstance(value, (bytes, str)): + return key, value if isinstance( value, ( @@ -25,8 +26,6 @@ def _ensure_str_or_bytes( int, ), ): - if isinstance(key, bytes): - key = key.decode() value = str(value) if isinstance(key, (bytes, str)) is False or ( value is not None and isinstance(value, (bytes, str)) is False @@ -63,14 +62,13 @@ class CaseInsensitiveDict(MutableMapping): """ def __init__(self, data=None, **kwargs) -> None: - self._store: MutableMapping[ - bytes | str, tuple[bytes | str, bytes | str] - ] = OrderedDict() + self._store: MutableMapping[bytes | str, tuple[bytes | str, bytes | str]] = {} if data is None: data = {} upstream_dict: bool = hasattr(data, "getlist") if upstream_dict: - data = dict(data) + self.update(data, **kwargs) + return normalized_items = [] for k, v in data.items() if hasattr(data, "items") else data: normalized_items.append( diff --git a/src/niquests/utils.py b/src/niquests/utils.py index b8d0df7a5a..c2ab56c726 100644 --- a/src/niquests/utils.py +++ b/src/niquests/utils.py @@ -33,8 +33,6 @@ ) from netrc import NetrcParseError, netrc -from urllib3 import ConnectionInfo - from ._compat import HAS_LEGACY_URLLIB3 if HAS_LEGACY_URLLIB3 is False: @@ -50,6 +48,7 @@ AsyncResolverDescription, AsyncManyResolver, ) + from urllib3 import ConnectionInfo else: from urllib3_future.util import make_headers, parse_url # type: ignore[assignment] from urllib3_future.contrib.resolver import ( # type: ignore[assignment] @@ -63,6 +62,7 @@ AsyncResolverDescription, AsyncManyResolver, ) + from urllib3_future import ConnectionInfo # type: ignore[assignment] from .__version__ import __version__ from .cookies import cookiejar_from_dict