Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed May 9, 2023
2 parents db19b6e + cfc4164 commit 197fdd0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/orm/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Taggable(Model):

has_many({'tags': {'via': 'taggings'}})

@fieldmethod('taglist')
@rowmethod('taglist')
def get_taglist(self, row):
return row.tags().column('name')

Expand Down
8 changes: 4 additions & 4 deletions docs/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ So you've just learned three handy aspects of Emmett:
HTTP/2
------

*New in version 2.1*
*Changed in version 2.5*

Emmett supports serving requests following the HTTP/2 standard. In order to enable serving such requests the `h11` protocol implementation should be enabled in `develop` and `serve` commands using the `--http-protocol` option.

Moreover, in order for the browser to use HTTP/2 protocol, SSL should be enabled. SSL certificate and key should be passed to `develop` and `serve` commands using the relevant `--ssl-certfile` and `--ssl-keyfile` options.
Emmett supports serving requests following the HTTP/2 standard. In order for the browser to use HTTP/2 protocol, SSL should be enabled. SSL certificate and key should be passed to `develop` and `serve` commands using the relevant `--ssl-certfile` and `--ssl-keyfile` options.

> **Hint:** a self-signed SSL certificate can be generated for development purposes using the `openssl` command, like: `openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes`.
Expand All @@ -170,3 +168,5 @@ async def index():
await request.push_promise(url("static", "some_asset.js"))
return {}
```

> **Note:** Emmett's integrated HTTP server doesn't support push promises. In order to use this feature you will need to serve your application with a 3rd party server like Hypercorn.
2 changes: 1 addition & 1 deletion emmett/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.5.0"
__version__ = "2.5.1"
6 changes: 6 additions & 0 deletions emmett/routing/dispatchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class WSCloseDispatcher(Dispatcher):
async def dispatch(self, reqargs):
try:
await self.f(**reqargs)
except asyncio.CancelledError:
await asyncio.shield(self._parallel_flow(self.flow_close))
return
except Exception:
await self._parallel_flow(self.flow_close)
raise
Expand All @@ -102,6 +105,9 @@ async def dispatch(self, reqargs):
await self._parallel_flow(self.flow_open)
try:
await self.f(**reqargs)
except asyncio.CancelledError:
await asyncio.shield(self._parallel_flow(self.flow_close))
return
except Exception:
await self._parallel_flow(self.flow_close)
raise
Expand Down
23 changes: 16 additions & 7 deletions emmett/rsgi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@

from typing import Awaitable, Callable, Optional, Tuple

from granian.rsgi import Scope, HTTPProtocol, WebsocketProtocol, WebsocketMessageType
from granian.rsgi import (
HTTPProtocol,
ProtocolClosed,
Scope,
WebsocketMessageType,
WebsocketProtocol
)

from ..ctx import RequestContext, WSContext, current
from ..debug import smart_traceback, debug_handler
Expand Down Expand Up @@ -251,12 +257,15 @@ async def __call__(

async def handle_transport(self, transport: WSTransport):
await transport.accepted.wait()
while True:
msg = await transport.transport.receive()
if msg.kind == WebsocketMessageType.close:
transport.interrupted
break
await transport.input.put(msg)
try:
while True:
msg = await transport.transport.receive()
if msg.kind == WebsocketMessageType.close:
transport.interrupted = True
break
await transport.input.put(msg)
except ProtocolClosed:
transport.interrupted = True

def handle_request(
self,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "emmett"
version = "2.5.0"
version = "2.5.1"
description = "The web framework for inventors"
authors = ["Giovanni Barillari <[email protected]>"]
license = "BSD-3-Clause"
Expand Down Expand Up @@ -43,7 +43,7 @@ emmett = "emmett.cli:main"
[tool.poetry.dependencies]
python = "^3.8"
click = ">=6.0"
granian = "~0.3.0"
granian = "~0.4.0"
emmett-crypto = "~0.3"
pendulum = "~2.1.2"
pyDAL = "17.3"
Expand Down

0 comments on commit 197fdd0

Please sign in to comment.