From 076ffde8342ed3ed17c89caf01bfdd09634b04a2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:56:34 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- proxy/core/connection/connection.py | 8 ++++---- proxy/core/work/fd/fd.py | 4 ++-- proxy/core/work/threadless.py | 6 +++--- proxy/http/client.py | 2 +- proxy/http/server/reverse.py | 12 ++++++------ tests/core/test_leakage.py | 2 +- tests/http/parser/test_http_parser.py | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/proxy/core/connection/connection.py b/proxy/core/connection/connection.py index 5c30d547c9..f14b8753e7 100644 --- a/proxy/core/connection/connection.py +++ b/proxy/core/connection/connection.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) -EMPTY_MV = memoryview(b"") +EMPTY_MV = memoryview(b'') class TcpConnectionUninitializedException(Exception): pass @@ -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) @@ -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 @@ -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 diff --git a/proxy/core/work/fd/fd.py b/proxy/core/work/fd/fd.py index 854426f48a..e17a33ae7a 100644 --- a/proxy/core/work/fd/fd.py +++ b/proxy/core/work/fd/fd.py @@ -41,7 +41,7 @@ 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: @@ -49,7 +49,7 @@ def work(self, *args: Any) -> None: 'Exception occurred during initialization', exc_info=e, ) - self._cleanup(fileno, "error") + self._cleanup(fileno, 'error') @property @abstractmethod diff --git a/proxy/core/work/threadless.py b/proxy/core/work/threadless.py index 9544692bdd..93d44be444 100644 --- a/proxy/core/work/threadless.py +++ b/proxy/core/work/threadless.py @@ -301,7 +301,7 @@ 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: @@ -309,7 +309,7 @@ def _cleanup(self, work_id: int, reason: str) -> None: 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, @@ -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( diff --git a/proxy/http/client.py b/proxy/http/client.py index c4ba7b8a59..2df366edfc 100644 --- a/proxy/http/client.py +++ b/proxy/http/client.py @@ -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""" diff --git a/proxy/http/server/reverse.py b/proxy/http/server/reverse.py index c007b06ee1..34bf569825 100644 --- a/proxy/http/server/reverse.py +++ b/proxy/http/server/reverse.py @@ -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 @@ -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: diff --git a/tests/core/test_leakage.py b/tests/core/test_leakage.py index cbec6e4f3c..897a09691f 100644 --- a/tests/core/test_leakage.py +++ b/tests/core/test_leakage.py @@ -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): diff --git a/tests/http/parser/test_http_parser.py b/tests/http/parser/test_http_parser.py index c3eecf9d0a..a5254c86d7 100644 --- a/tests/http/parser/test_http_parser.py +++ b/tests/http/parser/test_http_parser.py @@ -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)