Skip to content

Commit ba642d0

Browse files
committed
Refactor and a typo fix
Implemented structural improvements and consistency fixes: - Restructured session module: - Moved `sessions.py` → `session/async_session.py` for better organization - Fixed critical naming issue: - Renamed `TLSClientExeption` → `TLSClientException` (corrected typo) - Updated all references to use the properly spelled exception class - Improved type organization: - Renamed `settings.py` → `types.py` for semantic accuracy - Added explicit type exports for client identifiers
1 parent 7110293 commit ba642d0

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

async_tls_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# tls-client: https://github.com/bogdanfinn/tls-client
1313
# requests: https://github.com/psf/requests
1414

15-
from .sessions import AsyncSession
15+
from async_tls_client.session.async_session import AsyncSession

async_tls_client/cookies.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from .structures import CaseInsensitiveDict
2-
3-
from http.cookiejar import CookieJar, Cookie
4-
from typing import MutableMapping, Union, Any
5-
from urllib.parse import urlparse, urlunparse
6-
from http.client import HTTPMessage
71
import copy
2+
from http.client import HTTPMessage
3+
from http.cookiejar import Cookie, CookieJar
4+
from typing import Any, MutableMapping, Union
5+
from urllib.parse import urlparse, urlunparse
6+
7+
from .structures import CaseInsensitiveDict
88

99
try:
1010
import threading
@@ -240,7 +240,7 @@ def get_dict(self, domain=None, path=None):
240240
dictionary = {}
241241
for cookie in iter(self):
242242
if (domain is None or cookie.domain == domain) and (
243-
path is None or cookie.path == path
243+
path is None or cookie.path == path
244244
):
245245
dictionary[cookie.name] = cookie.value
246246
return dictionary
@@ -275,9 +275,9 @@ def __delitem__(self, name):
275275

276276
def set_cookie(self, cookie, *args, **kwargs):
277277
if (
278-
hasattr(cookie.value, "startswith")
279-
and cookie.value.startswith('"')
280-
and cookie.value.endswith('"')
278+
hasattr(cookie.value, "startswith")
279+
and cookie.value.startswith('"')
280+
and cookie.value.endswith('"')
281281
):
282282
cookie.value = cookie.value.replace('\\"', "")
283283
return super().set_cookie(cookie, *args, **kwargs)
@@ -432,12 +432,13 @@ def merge_cookies(cookiejar: RequestsCookieJar, cookies: Union[dict, RequestsCoo
432432

433433
return cookiejar
434434

435+
435436
def extract_cookies_to_jar(
436437
request_url: str,
437438
request_headers: CaseInsensitiveDict,
438439
cookie_jar: RequestsCookieJar,
439440
response_headers: dict
440-
) -> RequestsCookieJar:
441+
) -> RequestsCookieJar:
441442
response_cookie_jar = cookiejar_from_dict({})
442443

443444
req = MockRequest(request_url, request_headers)

async_tls_client/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
class TLSClientExeption(IOError):
2+
class TLSClientException(IOError):
33
"""General error with the TLS client"""

async_tls_client/response.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from .cookies import cookiejar_from_dict, RequestsCookieJar
2-
from .structures import CaseInsensitiveDict
3-
4-
from typing import Union
5-
import json
61
import base64
2+
import json
3+
from typing import Union
4+
5+
from .cookies import RequestsCookieJar, cookiejar_from_dict
6+
from .structures import CaseInsensitiveDict
77

88

99
class Response:
@@ -25,7 +25,7 @@ def __init__(self):
2525

2626
# A CookieJar of Cookies the server sent back.
2727
self.cookies = cookiejar_from_dict({})
28-
28+
2929
self._content = False
3030

3131
def __enter__(self):
@@ -37,11 +37,11 @@ def __repr__(self):
3737
def json(self, **kwargs):
3838
"""parse response body to json (dict/list)"""
3939
return json.loads(self.text, **kwargs)
40-
40+
4141
@property
4242
def content(self):
4343
"""Content of the response, in bytes."""
44-
44+
4545
if self._content is False:
4646
if self._content_consumed:
4747
raise RuntimeError("The content for this response was already consumed")

async_tls_client/session/__init__.py

Whitespace-only changes.

async_tls_client/sessions.py renamed to async_tls_client/session/async_session.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from json import dumps, loads
77
from typing import Any, Dict, List, Optional, Union
88

9-
from .cffi import destroySession, freeMemory, request
10-
from .cookies import cookiejar_from_dict, extract_cookies_to_jar, merge_cookies
11-
from .exceptions import TLSClientExeption
12-
from .response import Response, build_response
13-
from .settings import ClientIdentifiers
14-
from .structures import CaseInsensitiveDict
9+
from async_tls_client.cffi import destroySession, freeMemory, request
10+
from async_tls_client.cookies import cookiejar_from_dict, extract_cookies_to_jar, merge_cookies
11+
from async_tls_client.exceptions import TLSClientException
12+
from async_tls_client.response import Response, build_response
13+
from async_tls_client.types import ClientIdentifiers
14+
from async_tls_client.structures import CaseInsensitiveDict
1515

1616

1717
class AsyncSession:
@@ -475,7 +475,7 @@ def make_request():
475475
await asyncio.to_thread(freeMemory, response_object['id'].encode('utf-8'))
476476

477477
if response_object["status"] == 0:
478-
raise TLSClientExeption(response_object["body"])
478+
raise TLSClientException(response_object["body"])
479479

480480
response_cookie_jar = extract_cookies_to_jar(
481481
request_url=url,

async_tls_client/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from typing import MutableMapping, Mapping
21
from collections import OrderedDict
2+
from typing import Mapping, MutableMapping
33

44

55
class CaseInsensitiveDict(MutableMapping):
File renamed without changes.

0 commit comments

Comments
 (0)