Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 14, 2024
1 parent a9beaf1 commit 076ffde
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions proxy/core/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

logger = logging.getLogger(__name__)

EMPTY_MV = memoryview(b"")
EMPTY_MV = memoryview(b'')

class TcpConnectionUninitializedException(Exception):
pass
Expand Down Expand Up @@ -79,7 +79,7 @@ def recv(
self._recv_leakage.putback(buffer_size - size)
if size == 0:
return None
logger.debug("received %d bytes from %s" % (size, self.tag))
logger.debug('received %d bytes from %s' % (size, self.tag))
logger.info(data)
return memoryview(data)

Expand Down Expand Up @@ -121,7 +121,7 @@ def flush(self, max_send_size: Optional[int] = None) -> int:
self._flush_leakage.putback(allowed_bytes - sent)
except BlockingIOError:
logger.warning(
"BlockingIOError when trying send to {0}".format(self.tag)
'BlockingIOError when trying send to {0}'.format(self.tag),
)
del mv
return 0
Expand All @@ -133,7 +133,7 @@ def flush(self, max_send_size: Optional[int] = None) -> int:
else:
self.buffer[0] = mv[sent:]
# if sent > 0:
logger.debug("flushed %d bytes to %s" % (sent, self.tag))
logger.debug('flushed %d bytes to %s' % (sent, self.tag))
logger.info(mv[:sent].tobytes())
del mv
return sent
Expand Down
4 changes: 2 additions & 2 deletions proxy/core/work/fd/fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def work(self, *args: Any) -> None:
publisher_id=self.__class__.__qualname__,
)
try:
logger.debug("Initializing work#{0}".format(fileno))
logger.debug('Initializing work#{0}'.format(fileno))
self.works[fileno].initialize()
self._total += 1
except Exception as e:
logger.exception( # pragma: no cover
'Exception occurred during initialization',
exc_info=e,
)
self._cleanup(fileno, "error")
self._cleanup(fileno, 'error')

@property
@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions proxy/core/work/threadless.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ def _cleanup_inactive(self) -> None:
if self.works[work_id].is_inactive():
inactive_works.append(work_id)
for work_id in inactive_works:
self._cleanup(work_id, "inactive")
self._cleanup(work_id, 'inactive')

# TODO: HttpProtocolHandler.shutdown can call flush which may block
def _cleanup(self, work_id: int, reason: str) -> None:
if work_id in self.registered_events_by_work_ids:
assert self.selector
for fileno in self.registered_events_by_work_ids[work_id]:
logger.debug(
"fd#{0} unregistered by work#{1}, reason: {2}".format(
'fd#{0} unregistered by work#{1}, reason: {2}'.format(
fileno,
work_id,
reason,
Expand Down Expand Up @@ -376,7 +376,7 @@ async def _run_once(self) -> bool:
teardown = True
finally:
if teardown:
self._cleanup(work_id, "teardown")
self._cleanup(work_id, 'teardown')
# self.cleanup(int(task.get_name()))
# logger.debug(
# "Done executing works, {0} pending, {1} registered".format(
Expand Down
2 changes: 1 addition & 1 deletion proxy/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def client(
conn_close: bool = True,
scheme: bytes = HTTPS_PROTO,
timeout: float = DEFAULT_TIMEOUT,
content_type: bytes = b"application/x-www-form-urlencoded",
content_type: bytes = b'application/x-www-form-urlencoded',
verify: bool = False,
) -> Optional[HttpParser]:
"""HTTP Client"""
Expand Down
12 changes: 6 additions & 6 deletions proxy/http/server/reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def handle_request(self, request: HttpParser) -> None:
)
needs_upstream = True
logger.debug(
"Starting connection to upstream {0}".format(self.choice)
'Starting connection to upstream {0}'.format(self.choice),
)
break
# Dynamic routes
Expand All @@ -99,21 +99,21 @@ def handle_request(self, request: HttpParser) -> None:
needs_upstream = True
self._upstream_proxy_pass = str(self.choice)
logger.debug(
"Starting connection to upstream {0}".format(choice)
'Starting connection to upstream {0}'.format(choice),
)
elif isinstance(choice, memoryview):
self.client.queue(choice)
self._upstream_proxy_pass = '{0} bytes'.format(len(choice))
logger.debug("Sending raw response to client")
logger.debug('Sending raw response to client')
else:
self.upstream = choice
self._upstream_proxy_pass = '{0}:{1}'.format(
*self.upstream.addr,
)
logger.debug(
"Using existing connection to upstream {0}".format(
self.upstream.addr
)
'Using existing connection to upstream {0}'.format(
self.upstream.addr,
),
)
break
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_leakage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_initial_consume_no_tokens(self):
rate = 100 # bytes per second
bucket = Leakage(rate)
self.assertEqual(
bucket.consume(150), 100
bucket.consume(150), 100,
) # No tokens yet, so expect 0 bytes to be sent

def test_consume_with_refill(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/http/parser/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def test_byte_by_byte(self) -> None:
]
response.parse(memoryview(request[0]))
self.assertEqual(response.state, httpParserStates.RCVING_BODY)
self.assertEqual(response.code, b"200")
self.assertEqual(response.code, b'200')
for byte in (bytes([b]) for b in request[1]):
response.parse(memoryview(byte))
self.assertEqual(response.state, httpParserStates.COMPLETE)

0 comments on commit 076ffde

Please sign in to comment.