Skip to content

Utilities & Compatibility ## Business Purpose

Provide helper functions for URL manipulation, proxy resolution, header parsing, encoding detection, and cross-version Python compatibility. ## Current Behaviors - compat.py resolves chardet/charset_normalizer, urllib3 version, and imports from collections.abc and urllib.parse for Python 2/3 compatibility (src/requests/compat.py:37-46,22-28,54-57,60-65,72-76,79-91). - utils.py provides functions for proxy bypass, netrc auth, header validation, URL requoting, CIDR validation, cookie dict conversion, encoding detection, and TEMP environment variable setting (src/requests/utils.py: many functions). - _internal_utils.py provides to_native_string() and unicode_is_ascii() (src/requests/_internal_utils.py:26-36,39-51). - structures.py implements CaseInsensitiveDict and LookupDict for case-insensitive header storage and numeric status code lookup (src/requests/structures.py:20-93,96-130). ## Technical Implementation These modules are imported and used across the library. CaseInsensitiveDict is used for headers; LookupDict for requests.codes. Compatibility aliases ensure the library works on Python 2 and 3. ## Definition of Done - CaseInsensitiveDict allows case-insensitive key access and preserves original key case. - requests.codes.ok returns 200. - to_native_string(b'hello') returns 'hello' (str). - unicode_is_ascii('abc') returns True. - get_encoding_from_headers correctly returns charset from Content-Type.