Skip to content

Commit a6ac837

Browse files
committed
clean up
1 parent 58b1c12 commit a6ac837

File tree

7 files changed

+21
-20
lines changed

7 files changed

+21
-20
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ And other use cases…
3737
## Features
3838
Tremolo is only suitable for those who value [minimalism](https://en.wikipedia.org/wiki/Minimalism_%28computing%29) and stability over features.
3939

40-
With only **3k** lines of code, with no dependencies other than the [Python Standard Library](https://docs.python.org/3/library/index.html), it gives you:
40+
With only **3k** lines of code, with **no dependencies** other than the [Python Standard Library](https://docs.python.org/3/library/index.html), it gives you:
4141

4242
* HTTP/1.x with [WebSocket support](https://nggit.github.io/tremolo-docs/websocket.html)
4343
* Keep-Alive connections with [configurable limit](https://nggit.github.io/tremolo-docs/configuration.html#keepalive_connections)
4444
* Stream chunked uploads
4545
* [Stream multipart uploads](https://nggit.github.io/tremolo-docs/body.html#multipart)
4646
* Download/upload speed throttling
4747
* [Resumable downloads](https://nggit.github.io/tremolo-docs/resumable-downloads.html)
48-
* Framework features; routing, middleware, etc
48+
* Framework features; routing, middleware, etc.
4949
* ASGI server
5050
* PyPy compatible
5151

@@ -139,7 +139,7 @@ You will find that Tremolo is reasonably fast.
139139
However, it should be noted that bottlenecks often occur on the application side.
140140
Which means that in real-world usage, throughput reflects more on the application than the server.
141141

142-
## Misc
142+
## Misc.
143143
Tremolo utilizes `SO_REUSEPORT` (Linux 3.9+) to load balance worker processes.
144144

145145
```python

tremolo/http_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, lock=None, **kwargs):
2525

2626
async def _connection_made(self):
2727
for func, _ in self._middlewares['connect']:
28-
if (await func(**self._server)):
28+
if await func(**self._server):
2929
break
3030

3131
async def _connection_lost(self, exc):
@@ -35,7 +35,7 @@ async def _connection_lost(self, exc):
3535
while i > 0:
3636
i -= 1
3737

38-
if (await self._middlewares['close'][i][0](**self._server)):
38+
if await self._middlewares['close'][i][0](**self._server):
3939
break
4040
finally:
4141
super().connection_lost(exc)

tremolo/lib/h1parser/parse_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def getlist(self, name):
1313

1414
return result
1515

16-
return values.replace(b', ', b',').split(b',')
16+
return values.replace(b', ', b',').split(b',', 100)
1717

1818

1919
class ParseHeader:

tremolo/lib/http_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ async def handle_exception(self, exc):
214214
if isinstance(data, str):
215215
encoding = 'utf-8'
216216

217-
for v in exc.content_type.split(';'):
217+
for v in exc.content_type.split(';', 100):
218218
v = v.lstrip()
219219

220220
if v.startswith('charset='):

tremolo/lib/http_request.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ async def stream(self, raw=False):
180180
if not paused:
181181
try:
182182
buf.extend(await agen.__anext__())
183-
except StopAsyncIteration:
183+
except StopAsyncIteration as exc:
184184
if b'0\r\n' not in buf:
185185
del buf[:]
186186
raise BadRequest(
187187
'bad chunked encoding: incomplete read'
188-
)
188+
) from exc
189189

190190
if unread_bytes > 0:
191191
data = buf[:unread_bytes]
@@ -215,9 +215,9 @@ async def stream(self, raw=False):
215215

216216
try:
217217
chunk_size = int(buf[:i].split(b';', 1)[0], 16)
218-
except ValueError:
218+
except ValueError as exc:
219219
del buf[:]
220-
raise BadRequest('bad chunked encoding')
220+
raise BadRequest('bad chunked encoding') from exc
221221

222222
data = buf[i + 2:i + 2 + chunk_size]
223223
unread_bytes = chunk_size - len(data)
@@ -321,8 +321,8 @@ async def files(self, limit=1024):
321321

322322
try:
323323
boundary = ct['boundary'][-1].encode('latin-1')
324-
except KeyError:
325-
raise BadRequest('missing boundary')
324+
except KeyError as exc:
325+
raise BadRequest('missing boundary') from exc
326326

327327
header = None
328328
body = bytearray()
@@ -341,12 +341,12 @@ async def files(self, limit=1024):
341341
if not paused:
342342
try:
343343
data = await self._read_instance.__anext__()
344-
except StopAsyncIteration:
344+
except StopAsyncIteration as exc:
345345
if header_size == -1 or body_size == -1:
346346
del body[:]
347347
raise BadRequest(
348348
'malformed multipart/form-data: incomplete read'
349-
)
349+
) from exc
350350

351351
if header is None:
352352
self._read_buf.extend(data)

tremolo/lib/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ async def recv(self):
4040
data = await task
4141

4242
self.protocol.queue[0].task_done()
43-
except asyncio.CancelledError:
44-
raise TimeoutError('recv timeout')
43+
except asyncio.CancelledError as exc:
44+
raise TimeoutError('recv timeout') from exc
4545
finally:
4646
timer.cancel()
4747

tremolo/lib/websocket.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ async def receive(self):
110110

111111
try:
112112
payload = await self.recv()
113-
except TimeoutError:
114-
raise WebSocketServerClosed('receive timeout', code=1000)
113+
except TimeoutError as exc:
114+
raise WebSocketServerClosed('receive timeout',
115+
code=1000) from exc
115116
finally:
116117
timer.cancel()
117118

@@ -166,7 +167,7 @@ def _ping(self):
166167
# ping only if this connection is still listed,
167168
# otherwise let the recv timeout drop it
168169
if self.protocol in self.protocol.options['_connections']:
169-
return self.protocol.loop.create_task(self.ping())
170+
self.protocol.loop.create_task(self.ping())
170171

171172
async def ping(self, data=b''):
172173
await self.send(data, opcode=9)

0 commit comments

Comments
 (0)