Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sonic182 committed Aug 5, 2024
1 parent 0554680 commit e62f0d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
37 changes: 17 additions & 20 deletions elastic_transport/_node/_http_aiosonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .._compat import warn_stacklevel
from .._exceptions import ConnectionError, ConnectionTimeout, SecurityWarning, TlsError
from .._models import ApiResponseMeta, HttpHeaders, NodeConfig
from ..client_utils import DEFAULT, DefaultType, client_meta_version
from ..client_utils import DefaultType, client_meta_version
from ._base import (
BUILTIN_EXCEPTIONS,
DEFAULT_CA_CERTS,
Expand All @@ -37,12 +37,12 @@
from ._base_async import BaseAsyncNode

try:
from aiosonic import HTTPClient
from aiosonic import exceptions as aiosonic_exceptions
from aiosonic.connection import TCPConnector
from aiosonic.resolver import get_loop
from aiosonic.timeout import Timeouts
from aiosonic.version import VERSION
import aiosonic # type: ignore
from aiosonic.connection import TCPConnector # type: ignore
from aiosonic.exceptions import TimeoutException # type: ignore
from aiosonic.resolver import get_loop # type: ignore
from aiosonic.timeout import Timeouts # type: ignore
from aiosonic.version import VERSION # type: ignore

_AIOSONIC_AVAILABLE = True
_AIOSONIC_META_VERSION = client_meta_version(VERSION)
Expand Down Expand Up @@ -117,12 +117,13 @@ def __init__(self, config: NodeConfig):
ssl_context.load_cert_chain(config.client_cert)

self._loop: asyncio.AbstractEventLoop = None # type: ignore[assignment]
self.client = HTTPClient(
connector=TCPConnector(
pool_size=config.connections_per_node,
use_dns_cache=True,
),
)
if _AIOSONIC_AVAILABLE:
self.client = aiosonic.HTTPClient(
connector=TCPConnector(
pool_size=config.connections_per_node,
use_dns_cache=True,
),
)

self._ssl_context = ssl_context

Expand All @@ -132,17 +133,15 @@ async def perform_request( # type: ignore[override]
target: str,
body: Optional[bytes] = None,
headers: Optional[HttpHeaders] = None,
request_timeout: Union[DefaultType, Optional[float]] = DEFAULT,
request_timeout: Union[DefaultType, Optional[float]] = None,
) -> NodeApiResponse:
url = self.base_url + target

if not self._loop:
self._loop = get_loop()

timeouts = Timeouts(
request_timeout=(
request_timeout.value if request_timeout.value else self._BIG_TIMEOUT
)
request_timeout=(request_timeout if request_timeout else self._BIG_TIMEOUT)
)

request_headers = self._headers.copy()
Expand Down Expand Up @@ -177,9 +176,7 @@ async def perform_request( # type: ignore[override]
raise
except Exception as e:
err: Exception
if isinstance(
e, (asyncio.TimeoutError, aiosonic_exceptions.TimeoutException)
):
if isinstance(e, (asyncio.TimeoutError, TimeoutException)):
err = ConnectionTimeout(
"Connection timed out during request", errors=(e,)
)
Expand Down
1 change: 1 addition & 0 deletions requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
requests==2.26.0
urllib3==1.26.2
aiohttp==3.8.0
aiosonic==0.20.0
httpx==0.27.0

0 comments on commit e62f0d7

Please sign in to comment.