From da9b1eb34eefa877fefd6a44e188264d4f4a6dd7 Mon Sep 17 00:00:00 2001 From: Tomer Zait Date: Mon, 8 Jan 2024 11:31:27 +0200 Subject: [PATCH] fix support for socks proxy in python version <3.10 --- requests_raw/__version__.py | 4 ++-- requests_raw/socks.py | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/requests_raw/__version__.py b/requests_raw/__version__.py index 4324f3f..29b6cba 100644 --- a/requests_raw/__version__.py +++ b/requests_raw/__version__.py @@ -1,8 +1,8 @@ __title__ = 'requests-raw' __description__ = 'HTTP communication through raw sockets using requests for RFC compliance testing' __url__ = 'https://github.com/realgam3/requests-raw' -__version__ = '2.0.1' -__build__ = 0x020001 +__version__ = '2.0.2' +__build__ = 0x020002 __author__ = 'Tomer Zait (realgam3)' __author_email__ = 'realgam3@gmail.com' __license__ = 'Apache 2.0' diff --git a/requests_raw/socks.py b/requests_raw/socks.py index 5dc9a55..3332217 100644 --- a/requests_raw/socks.py +++ b/requests_raw/socks.py @@ -1,3 +1,5 @@ +from __future__ import annotations + try: import socks # type: ignore[import] except ImportError: @@ -22,13 +24,19 @@ from .connectionpool import RawHTTPConnectionPool, RawHTTPSConnectionPool -class _TYPE_SOCKS_OPTIONS(typing.TypedDict): - socks_version: int - proxy_host: str | None - proxy_port: str | None - username: str | None - password: str | None - rdns: bool +try: + from typing import TypedDict + + class _TYPE_SOCKS_OPTIONS(TypedDict): + socks_version: int + proxy_host: str | None + proxy_port: str | None + username: str | None + password: str | None + rdns: bool + +except ImportError: # Python 3.7 + _TYPE_SOCKS_OPTIONS = typing.Dict[str, typing.Any] # type: ignore[misc, assignment] class RawSOCKSConnection(SOCKSConnection, RawHTTPConnection):