Skip to content

Commit

Permalink
Use an indirect logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ebraminio committed Nov 17, 2023
1 parent fc47363 commit 6f4b4af
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions aiosseclient.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''Asynchronous Server Side Events (SSE) Client'''
'''Main module'''
import re
import logging
from typing import (
Expand All @@ -12,7 +12,7 @@
# pylint: disable=too-many-arguments, dangerous-default-value, redefined-builtin, unsubscriptable-object

_SSE_LINE_PATTERN: Final[re.Pattern[str]] = re.compile('(?P<name>[^:]*):?( ?(?P<value>.*))?')

_LOGGER = logging.getLogger(__name__)

# Good parts of the below class is adopted from:
# https://github.com/btubbs/sseclient/blob/db38dc6/sseclient.py
Expand Down Expand Up @@ -66,7 +66,7 @@ def parse(cls, raw):
m = _SSE_LINE_PATTERN.match(line)
if m is None:
# Malformed line. Discard but warn.
logging.warning('Invalid SSE line: %s', line)
_LOGGER.warning('Invalid SSE line: %s', line)
continue

name = m.group('name')
Expand Down Expand Up @@ -119,10 +119,10 @@ async def aiosseclient(
sock_connect=None, sock_read=None)
async with aiohttp.ClientSession(timeout=timeout) as session:
try:
logging.info('Session created: %s', session)
_LOGGER.info('Session created: %s', session)
response = await session.get(url, headers=headers)
if response.status not in valid_http_codes:
logging.error('Invalid HTTP response.status: %s', response.status)
_LOGGER.error('Invalid HTTP response.status: %s', response.status)
await session.close()
lines = []
async for line in response.content:
Expand All @@ -141,5 +141,5 @@ async def aiosseclient(
else:
lines.append(line)
except TimeoutError as sseerr:
logging.error('TimeoutError: %s', sseerr)
_LOGGER.error('TimeoutError: %s', sseerr)
await session.close()

0 comments on commit 6f4b4af

Please sign in to comment.