Skip to content

Commit c693a77

Browse files
author
Two Dev
committedFeb 15, 2025·
feat: python3.8 supported
1 parent b77dafa commit c693a77

File tree

9 files changed

+44
-53
lines changed

9 files changed

+44
-53
lines changed
 

‎requirements-dev.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ setuptools~=75.3.0
1010
twine~=6.0.1
1111

1212
# Tests & Linting
13-
pre-commit==3.7.0
13+
pre-commit
14+
pytest-cov
15+
Werkzeug
1416
black==24.3.0
1517
coverage[toml]==7.6.1
16-
pre-commit==3.7.0
1718
isort==5.13.2
1819
flake8==7.1.1
1920
mypy==1.11.2
2021
pytest==8.3.3
2122
pytest-asyncio==0.24.0
22-
pytest-cov==6.0.0
2323
pytest_httpserver==1.1.0
24-
Werkzeug==3.1.3
2524
tox==4.23.2

‎setup.cfg

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ long_description = file: README.md
33
long_description_content_type = text/markdown
44
license = MIT
55
license_file = LICENSE
6-
python_requires = >=3.9
6+
python_requires = >=3.8
77
install_requires =
88
chardet ~= 5.2.0
99
requests ~= 2.32.3
1010
tqdm ~= 4.67.1
11+
idna ~= 3.10
1112
classifiers =
1213
Development Status :: 5 - Production/Stable
1314
Intended Audience :: Developers
@@ -17,6 +18,7 @@ classifiers =
1718
Operating System :: OS Independent
1819
Programming Language :: Python
1920
Programming Language :: Python :: 3
21+
Programming Language :: Python :: 3.8
2022
Programming Language :: Python :: 3.9
2123
Programming Language :: Python :: 3.10
2224
Programming Language :: Python :: 3.11

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
BASE_DIR = os.path.dirname(__file__)
1111
CURRENT_PYTHON = sys.version_info[:2]
12-
REQUIRED_PYTHON = (3, 9)
12+
REQUIRED_PYTHON = (3, 8)
1313

1414
if CURRENT_PYTHON < REQUIRED_PYTHON:
1515
sys.stderr.write(

‎tls_requests/models/encoders.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from io import BufferedReader, BytesIO, TextIOWrapper
44
from mimetypes import guess_type
5-
from typing import Any, AsyncIterator, Iterator, Mapping, TypeVar
5+
from typing import Any, AsyncIterator, Dict, Iterator, Mapping, Tuple, TypeVar
66
from urllib.parse import urlencode
77

88
from tls_requests.types import (BufferTypes, ByteOrStr, RequestData,
@@ -75,7 +75,7 @@ def render(self, chunk_size: int = 65_536) -> Iterator[bytes]:
7575
yield self.render_headers()
7676
yield from self.render_data(chunk_size)
7777

78-
def get_headers(self) -> dict[bytes, bytes]:
78+
def get_headers(self) -> Dict[bytes, bytes]:
7979
self._headers[b"Content-Disposition"] = self.render_parts()
8080
content_type = getattr(self, "content_type", None)
8181
if content_type:
@@ -101,7 +101,7 @@ def __init__(self, name: str, value: RequestFileValue):
101101
super(FileField, self).__init__(name, value)
102102
self.filename, self._buffer, self.content_type = self.unpack(value)
103103

104-
def unpack(self, value: RequestFileValue) -> tuple[str, BufferTypes, str]:
104+
def unpack(self, value: RequestFileValue) -> Tuple[str, BufferTypes, str]:
105105
filename, content_type = None, None
106106
if isinstance(value, tuple):
107107
if len(value) > 1:

‎tls_requests/models/headers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC
22
from collections.abc import Mapping, MutableMapping
33
from enum import Enum
4-
from typing import Any, ItemsView, KeysView, Literal, ValuesView
4+
from typing import Any, ItemsView, KeysView, List, Literal, Tuple, ValuesView
55

66
from tls_requests.types import ByteOrStr, HeaderTypes
77
from tls_requests.utils import to_str
@@ -63,7 +63,7 @@ def update(self, headers: HeaderTypes) -> "Headers": # noqa
6363
def copy(self) -> "Headers":
6464
return self.__class__(self._items.copy(), alias=self.alias) # noqa
6565

66-
def _prepare_items(self, headers: HeaderTypes) -> list[tuple[str, Any]]:
66+
def _prepare_items(self, headers: HeaderTypes) -> List[Tuple[str, Any]]:
6767
if headers is None:
6868
return []
6969
if isinstance(headers, self.__class__):
@@ -88,7 +88,7 @@ def _normalize_key(self, key: ByteOrStr) -> str:
8888

8989
return key.lower()
9090

91-
def _normalize_value(self, value) -> list[str]:
91+
def _normalize_value(self, value) -> List[str]:
9292
if isinstance(value, dict):
9393
raise TypeError
9494

@@ -102,7 +102,7 @@ def _normalize_value(self, value) -> list[str]:
102102

103103
return [to_str(value)]
104104

105-
def _normalize(self, key, value) -> tuple[str, list[str]]:
105+
def _normalize(self, key, value) -> Tuple[str, List[str]]:
106106
return self._normalize_key(key), self._normalize_value(value)
107107

108108
def __setitem__(self, key, value) -> None:

‎tls_requests/models/libraries.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dataclasses import dataclass, field, fields
88
from pathlib import Path
99
from platform import machine
10-
from typing import Optional
10+
from typing import List, Optional
1111

1212
import requests
1313
from tqdm import tqdm
@@ -86,7 +86,7 @@ class ReleaseAsset(BaseRelease):
8686
class Release(BaseRelease):
8787
name: Optional[str] = None
8888
tag_name: Optional[str] = None
89-
assets: list[ReleaseAsset] = field(default_factory=list)
89+
assets: List[ReleaseAsset] = field(default_factory=list)
9090

9191
@classmethod
9292
def from_kwargs(cls, **kwargs):
@@ -274,7 +274,7 @@ def find(cls) -> str:
274274
return fp
275275

276276
@classmethod
277-
def find_all(cls) -> list[str]:
277+
def find_all(cls) -> List[str]:
278278
return [
279279
src
280280
for src in glob.glob(os.path.join(BIN_DIR, r"*"))

‎tls_requests/models/tls.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import uuid
33
from dataclasses import asdict, dataclass, field
44
from dataclasses import fields as get_fields
5-
from typing import Any, Optional, TypeVar, Union
5+
from typing import Any, List, Mapping, Optional, Set, TypeVar, Union
66

77
from tls_requests.models.encoders import StreamEncoder
88
from tls_requests.models.libraries import TLSLibrary
@@ -178,7 +178,7 @@ class _BaseConfig:
178178
"""Base configuration for TLSSession"""
179179

180180
@classmethod
181-
def model_fields_set(cls) -> set[str]:
181+
def model_fields_set(cls) -> Set[str]:
182182
return {
183183
model_field.name
184184
for model_field in get_fields(cls)
@@ -341,19 +341,19 @@ class CustomTLSClientConfig(_BaseConfig):
341341
342342
"""
343343

344-
alpnProtocols: list[str] = None
345-
alpsProtocols: list[str] = None
344+
alpnProtocols: List[str] = None
345+
alpsProtocols: List[str] = None
346346
certCompressionAlgo: str = None
347347
connectionFlow: int = None
348-
h2Settings: list[str] = None
349-
h2SettingsOrder: list[str] = None
350-
headerPriority: list[str] = None
348+
h2Settings: List[str] = None
349+
h2SettingsOrder: List[str] = None
350+
headerPriority: List[str] = None
351351
ja3String: str = None
352-
keyShareCurves: list[str] = None
353-
priorityFrames: list[str] = None
354-
pseudoHeaderOrder: list[str] = None
355-
supportedSignatureAlgorithms: list[str] = None
356-
supportedVersions: list[str] = None
352+
keyShareCurves: List[str] = None
353+
priorityFrames: List[str] = None
354+
pseudoHeaderOrder: List[str] = None
355+
supportedSignatureAlgorithms: List[str] = None
356+
supportedVersions: List[str] = None
357357

358358

359359
@dataclass
@@ -424,19 +424,19 @@ class TLSConfig(_BaseConfig):
424424
"""
425425

426426
catchPanics: bool = False
427-
certificatePinningHosts: dict[str, str] = field(default_factory=dict)
427+
certificatePinningHosts: Mapping[str, str] = field(default_factory=dict)
428428
customTlsClient: Optional[CustomTLSClientConfig] = None
429429
followRedirects: bool = False
430430
forceHttp1: bool = False
431-
headerOrder: list[str] = field(default_factory=list)
432-
headers: dict[str, str] = field(default_factory=dict)
431+
headerOrder: List[str] = field(default_factory=list)
432+
headers: Mapping[str, str] = field(default_factory=dict)
433433
insecureSkipVerify: bool = False
434434
isByteRequest: bool = False
435435
isByteResponse: bool = True
436436
isRotatingProxy: bool = False
437437
proxyUrl: str = ""
438438
requestBody: Union[str, bytes, bytearray, None] = None
439-
requestCookies: list[TLSRequestCookiesConfig] = field(default_factory=list)
439+
requestCookies: List[TLSRequestCookiesConfig] = field(default_factory=list)
440440
requestMethod: MethodTypes = None
441441
requestUrl: Optional[str] = None
442442
sessionId: str = field(default_factory=lambda: str(uuid.uuid4()))
@@ -471,7 +471,7 @@ def to_dict(self) -> dict:
471471
def copy_with(
472472
self,
473473
session_id: str = None,
474-
headers: dict[str, str] = None,
474+
headers: Mapping[str, str] = None,
475475
cookies: TLSCookiesTypes = None,
476476
method: MethodTypes = None,
477477
url: URLTypes = None,
@@ -515,7 +515,7 @@ def copy_with(
515515
def from_kwargs(
516516
cls,
517517
session_id: str = None,
518-
headers: dict[str, str] = None,
518+
headers: Mapping[str, str] = None,
519519
cookies: TLSCookiesTypes = None,
520520
method: MethodTypes = None,
521521
url: URLTypes = None,

‎tls_requests/types.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44

55
from http.cookiejar import CookieJar
6-
from typing import (IO, TYPE_CHECKING, Any, BinaryIO, Callable, List, Literal,
7-
Mapping, Optional, Sequence, Tuple, Union)
6+
from typing import (IO, TYPE_CHECKING, Any, BinaryIO, Callable, Dict, List,
7+
Literal, Mapping, Optional, Sequence, Set, Tuple, Union)
88
from uuid import UUID
99

1010
if TYPE_CHECKING: # pragma: no cover
@@ -28,9 +28,9 @@
2828
Union[str, bytes],
2929
Union[
3030
URL_ALLOWED_PARAMS,
31-
list[URL_ALLOWED_PARAMS],
32-
tuple[URL_ALLOWED_PARAMS],
33-
set[URL_ALLOWED_PARAMS],
31+
List[URL_ALLOWED_PARAMS],
32+
Tuple[URL_ALLOWED_PARAMS],
33+
Set[URL_ALLOWED_PARAMS],
3434
],
3535
],
3636
]
@@ -43,7 +43,7 @@
4343
TLSSession = Union["TLSSession", None]
4444
TLSSessionId = Union[str, UUID]
4545
TLSPayload = Union[dict, str, bytes, bytearray]
46-
TLSCookiesTypes = Optional[List[dict[str, str]]]
46+
TLSCookiesTypes = Optional[List[Dict[str, str]]]
4747
TLSIdentifierTypes = Literal[
4848
"chrome_103",
4949
"chrome_104",
@@ -104,12 +104,7 @@
104104
"Headers",
105105
Mapping[str, str],
106106
Mapping[bytes, bytes],
107-
List[list[str, str]],
108-
List[list[bytes, bytes]],
109-
List[tuple[str, str]],
110-
List[tuple[bytes, bytes]],
111-
List[set[str, str]],
112-
List[set[bytes, bytes]],
107+
List[Union[List[Union[str, bytes]], Tuple[Union[str, bytes]], Set[Union[str, bytes]]]],
113108
]
114109
]
115110

@@ -119,12 +114,7 @@
119114
CookieJar,
120115
Mapping[str, str],
121116
Mapping[bytes, bytes],
122-
List[list[str, str]],
123-
List[list[bytes, bytes]],
124-
List[tuple[str, str]],
125-
List[tuple[bytes, bytes]],
126-
List[set[str, str]],
127-
List[set[bytes, bytes]],
117+
List[Union[List[Union[str, bytes]], Tuple[Union[str, bytes]], Set[Union[str, bytes]]]],
128118
]
129119
]
130120

‎tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py{39,310,311,312,313}-default
2+
envlist = py{38,39,310,311,312,313}-default
33

44
[testenv]
55
deps = -r requirements-dev.txt

0 commit comments

Comments
 (0)
Please sign in to comment.