From 8c13c0675a3a99aa88361e6f86e6ec9931e0ddc4 Mon Sep 17 00:00:00 2001 From: nggit <12218311+nggit@users.noreply.github.com> Date: Thu, 19 Dec 2024 10:17:45 +0700 Subject: [PATCH] clean up --- tremolo/lib/connections.py | 3 +-- tremolo/tremolo.py | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tremolo/lib/connections.py b/tremolo/lib/connections.py index a61627d..be57639 100644 --- a/tremolo/lib/connections.py +++ b/tremolo/lib/connections.py @@ -2,7 +2,7 @@ class KeepAliveConnections(dict): - def __init__(self, *args, maxlen=512, **kwargs): + def __init__(self, maxlen=512): if not isinstance(maxlen, int) or maxlen < 1: raise ValueError( 'maxlen must be an integer greater than or equal to 1, ' @@ -10,7 +10,6 @@ def __init__(self, *args, maxlen=512, **kwargs): ) self._maxlen = maxlen - super().__init__(*args, **kwargs) def __repr__(self): return self.keys().__repr__() diff --git a/tremolo/tremolo.py b/tremolo/tremolo.py index 5b99f99..3f959c5 100644 --- a/tremolo/tremolo.py +++ b/tremolo/tremolo.py @@ -49,18 +49,6 @@ def __init__(self): self.loop = None self.logger = None - def listen(self, port, host=None, **options): - if not isinstance(port, int): - # assume it's a UNIX socket path - host = port - port = None - - if (host, port) in self.ports: - return False - - self.ports[(host, port)] = options - return (host, port) in self.ports - def route(self, path): if isinstance(path, int): return self.error(path) @@ -158,6 +146,18 @@ def add_middleware(self, func, name='request', priority=999, kwargs=None): self.middlewares[name].sort(key=lambda item: item[0], reverse=name in ('close', 'response')) + def listen(self, port, host=None, **options): + if not isinstance(port, int): + # assume it's a UNIX socket path + host = port + port = None + + if (host, port) in self.ports: + return False + + self.ports[(host, port)] = options + return (host, port) in self.ports + async def _serve(self, host, port, **options): backlog = options.get('backlog', 100)