Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nggit committed Nov 17, 2023
1 parent 7f8875c commit ed83611
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tremolo/lib/http_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def socket(self):
@property
def client(self):
if not self._client:
self._client = self.socket.getpeername()[:2]
try:
self._client = self.socket.getpeername()[:2]
except TypeError:
pass

Check warning on line 92 in tremolo/lib/http_request.py

View check run for this annotation

Codecov / codecov/patch

tremolo/lib/http_request.py#L91-L92

Added lines #L91 - L92 were not covered by tests

return self._client

Expand Down
13 changes: 7 additions & 6 deletions tremolo/tremolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
(400, handlers.error_400, {}),
(404, handlers.error_404, dict(status=(404, b'Not Found'),
stream=False)),
# must be at the very end
(500, handlers.error_500, {})
],
1: [
Expand All @@ -56,8 +57,8 @@ def __init__(self):
'worker_start': [],
'worker_stop': []
}
self.ports = {}

self._ports = {}
self._loop = None
self._logger = None

Expand All @@ -67,11 +68,11 @@ def listen(self, port, host=None, **options):
host = port
port = None

if (host, port) in self._ports:
if (host, port) in self.ports:
return False

self._ports[(host, port)] = options
return (host, port) in self._ports
self.ports[(host, port)] = options
return (host, port) in self.ports

def route(self, path):
if isinstance(path, int):
Expand Down Expand Up @@ -605,7 +606,7 @@ def run(self, host=None, port=0, reuse_port=True, worker_num=1, **kwargs):
print()

if host is None:
if not self._ports:
if not self.ports:
raise ValueError(
'with host=None, listen() must be called first'
)
Expand All @@ -627,7 +628,7 @@ def run(self, host=None, port=0, reuse_port=True, worker_num=1, **kwargs):

print('Options:')

for (_host, _port), options in self._ports.items():
for (_host, _port), options in self.ports.items():
if _host is None:
_host = host

Expand Down

0 comments on commit ed83611

Please sign in to comment.