mirror of
https://github.com/soxoj/maigret.git
synced 2026-09-13 13:27:41 +02:00
chore: clean up imports and replace list()[0] with next(iter()) (#2816)
Two safe, mechanical changes:
- activation.py: replace `list(domain.values())[0]` with
`next(iter(domain.values()))` in import_aiohttp_cookies to avoid
materializing the entire iterable just to grab the first dict.
- checking.py: reorganize imports to PEP 8 order (stdlib, third-party,
local). `from unittest.mock import Mock` and the stdlib `quote`
import move into the stdlib section; `python_socks` and
`socid_extractor` move into third-party; `from .error_detection import
detect_error_page` and the `from .` local imports move into the local
section.
No behavioral change. Same diff shape as 2484509 -> HEAD for these two
files minus the else-removal work.
This commit is contained in:
@@ -160,7 +160,7 @@ def import_aiohttp_cookies(cookiestxt_filename):
|
||||
|
||||
cookies_list = []
|
||||
for domain in cookies_obj._cookies.values(): # type: ignore[attr-defined]
|
||||
for key, cookie in list(domain.values())[0].items():
|
||||
for key, cookie in next(iter(domain.values())).items():
|
||||
c: Morsel = Morsel()
|
||||
c.set(key, cookie.value, cookie.value)
|
||||
c["domain"] = cookie.domain
|
||||
|
||||
+13
-14
@@ -8,8 +8,8 @@ import re
|
||||
import ssl
|
||||
import sys
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
from unittest.mock import Mock
|
||||
from urllib.parse import quote
|
||||
from maigret.error_detection import detect_error_page
|
||||
|
||||
# Third party imports
|
||||
import aiodns
|
||||
@@ -21,6 +21,18 @@ from aiohttp.client_exceptions import (
|
||||
ClientConnectorError,
|
||||
ServerDisconnectedError,
|
||||
)
|
||||
from python_socks import _errors as proxy_errors
|
||||
from socid_extractor import extract # type: ignore[import-not-found]
|
||||
|
||||
# Local imports
|
||||
from . import errors
|
||||
from .activation import ParsingActivator, import_aiohttp_cookies
|
||||
from .error_detection import detect_error_page
|
||||
from .errors import CheckError
|
||||
from .executors import AsyncioQueueGeneratorExecutor
|
||||
from .result import MaigretCheckResult, MaigretCheckStatus, KeywordMatchStatus, SiteResult
|
||||
from .sites import MaigretDatabase, MaigretSite
|
||||
from .utils import ascii_data_display, get_random_user_agent, is_plausible_username
|
||||
|
||||
|
||||
_DNS_ERROR_MARKERS = (
|
||||
@@ -44,19 +56,6 @@ def _is_dns_error(exc: Exception) -> bool:
|
||||
return True
|
||||
text = str(exc).lower()
|
||||
return any(m in text for m in _DNS_ERROR_MARKERS)
|
||||
from python_socks import _errors as proxy_errors
|
||||
from socid_extractor import extract # type: ignore[import-not-found]
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
# Local imports
|
||||
from . import errors
|
||||
from .activation import ParsingActivator, import_aiohttp_cookies
|
||||
from .errors import CheckError
|
||||
from .executors import AsyncioQueueGeneratorExecutor
|
||||
from .result import MaigretCheckResult, MaigretCheckStatus, KeywordMatchStatus, SiteResult
|
||||
from .sites import MaigretDatabase, MaigretSite
|
||||
from .utils import ascii_data_display, get_random_user_agent, is_plausible_username
|
||||
|
||||
|
||||
SUPPORTED_IDS = (
|
||||
|
||||
Reference in New Issue
Block a user