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 Apr 11, 2022
2 parents 6b5fa27 + d27dc99 commit 473525b
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 203 deletions.
2 changes: 1 addition & 1 deletion docs/orm/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ This shortcut will return the rows referenced to the record, and accepts the sam

> **Note:** calling the shortcut or the `select` method without parameters will perform caching of the referred rows on the set. If you need to avoid this for consequent calls, use the `reload` parameter set to `True`.
The `has_many` sets also have three more methods that can help you performing operations with relations, in particular the `create`, `add` and `remove` methods. These methods have a slightly different behavior when the `has_many` helper is configured with the `via` options. Let' see them in details.
The `has_many` sets also have three more methods that can help you performing operations with relations, in particular the `create`, `new`, `add` and `remove` methods. These methods have a slightly different behavior when the `has_many` helper is configured with the `via` options. Let' see them in details.

#### Creating new related records

Expand Down
2 changes: 1 addition & 1 deletion emmett/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.4.5"
__version__ = "2.4.6"
25 changes: 4 additions & 21 deletions emmett/asgi/protocols/http/h11.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from uvicorn.protocols.http.h11_impl import (
HIGH_WATER_LIMIT,
STATUS_PHRASES,
H11Protocol as _H11Protocol,
RequestResponseCycle,
service_unavailable,
Expand Down Expand Up @@ -46,8 +45,7 @@ def handle_upgrade(self, event: h11.Request):
output.append(b"\r\n")
protocol = self.ws_protocol_class(
config=self.config,
server_state=self.server_state,
on_connection_lost=self.on_connection_lost
server_state=self.server_state
)
protocol.connection_made(self.transport)
protocol.data_received(b"".join(output))
Expand All @@ -65,29 +63,14 @@ def handle_upgrade(self, event: h11.Request):
protocol = self.h2_protocol_class(
config=self.config,
server_state=self.server_state,
on_connection_lost=self.on_connection_lost,
_loop=self.loop
)
protocol.handle_upgrade_from_h11(self.transport, event, self.headers)
self.transport.set_protocol(protocol)
else:
msg = "Unsupported upgrade request."
self.logger.warning(msg)
reason = STATUS_PHRASES[400]
headers = [
(b"content-type", b"text/plain; charset=utf-8"),
(b"connection", b"close"),
]
event = h11.Response(status_code=400, headers=headers, reason=reason)
output = self.conn.send(event)
self.transport.write(output)
event = h11.Data(data=b"Unsupported upgrade request.")
output = self.conn.send(event)
self.transport.write(output)
event = h11.EndOfMessage()
output = self.conn.send(event)
self.transport.write(output)
self.transport.close()
self.send_400_response(msg)

def handle_h2_assumed(self):
self.connections.discard(self)
Expand All @@ -109,7 +92,7 @@ def handle_events(self):
except h11.RemoteProtocolError as exc:
msg = "Invalid HTTP request received."
self.logger.warning(msg, exc_info=exc)
self.transport.close()
self.send_400_response(msg)
return
event_type = type(event)

Expand Down Expand Up @@ -148,7 +131,7 @@ def handle_events(self):
"type": "http",
"asgi": {
"version": self.config.asgi_version,
"spec_version": "2.1",
"spec_version": "2.3",
},
"http_version": event.http_version.decode("ascii"),
"server": self.server,
Expand Down
9 changes: 2 additions & 7 deletions emmett/asgi/protocols/http/h2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from collections import defaultdict
from functools import partial
from typing import Any, Callable, List, Optional, Tuple
from typing import Any, List, Tuple
from urllib.parse import unquote

import h11
Expand Down Expand Up @@ -57,13 +57,11 @@ def __init__(
self,
config: Config,
server_state: ServerState,
on_connection_lost: Optional[Callable[[], None]] = None,
_loop=None
):
super().__init__(
config=config,
server_state=server_state,
on_connection_lost=on_connection_lost,
_loop=_loop
)
self.conn = h2.connection.H2Connection(
Expand Down Expand Up @@ -94,9 +92,6 @@ def connection_lost(self, exc):
if exc is None:
self.transport.close()

if self.on_connection_lost:
self.on_connection_lost()

def handle_upgrade_from_h11(
self,
transport: asyncio.Protocol,
Expand Down Expand Up @@ -280,7 +275,7 @@ def on_request_received(protocol: H2Protocol, event: h2.events.RequestReceived):
"type": "http",
"asgi": {
"version": protocol.config.asgi_version,
"spec_version": "2.1"
"spec_version": "2.3"
},
"http_version": "2",
"server": protocol.addr_local,
Expand Down
5 changes: 0 additions & 5 deletions emmett/asgi/protocols/http/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import asyncio
import logging

from typing import Callable, Optional

from uvicorn.main import ServerState
from uvicorn.protocols.utils import (
get_local_addr,
Expand Down Expand Up @@ -79,7 +77,6 @@ class HTTPProtocol(asyncio.Protocol):
"limit_concurrency",
"logger",
"loop",
"on_connection_lost",
"root_path",
"scheme",
"server_state",
Expand All @@ -94,12 +91,10 @@ def __init__(
self,
config: Config,
server_state: ServerState,
on_connection_lost: Optional[Callable[[], None]] = None,
_loop=None
):
self.config = config
self.app = config.loaded_app
self.on_connection_lost = on_connection_lost
self.loop = _loop or asyncio.get_event_loop()
self.logger = logging.getLogger("uvicorn.error")
self.access_logger = logging.getLogger("uvicorn.access")
Expand Down
22 changes: 3 additions & 19 deletions emmett/asgi/protocols/http/httptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"""

from uvicorn.protocols.http.httptools_impl import (
HttpToolsProtocol as _HttpToolsProtocol,
STATUS_LINE
HttpToolsProtocol as _HttpToolsProtocol
)

from . import protocols
Expand All @@ -30,21 +29,7 @@ def handle_upgrade(self):
if upgrade_value != b"websocket" or self.ws_protocol_class is None:
msg = "Unsupported upgrade request."
self.logger.warning(msg)

content = [STATUS_LINE[400]]
for name, value in self.default_headers:
content.extend([name, b": ", value, b"\r\n"])
content.extend(
[
b"content-type: text/plain; charset=utf-8\r\n",
b"content-length: " + str(len(msg)).encode("ascii") + b"\r\n",
b"connection: close\r\n",
b"\r\n",
msg.encode("ascii"),
]
)
self.transport.write(b"".join(content))
self.transport.close()
self.send_400_response(msg)
return

self.connections.discard(self)
Expand All @@ -55,8 +40,7 @@ def handle_upgrade(self):
output.append(b"\r\n")
protocol = self.ws_protocol_class(
config=self.config,
server_state=self.server_state,
on_connection_lost=self.on_connection_lost,
server_state=self.server_state
)
protocol.connection_made(self.transport)
protocol.data_received(b"".join(output))
Expand Down
2 changes: 1 addition & 1 deletion emmett/orm/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _parse(adapter, row, fdata, tables, concrete_tables, fields, colnames, blob_
column_name = new_column_name.groups(0)
new_row[column_name[0]] = value
for key, val in rows_cls.items():
new_row[key] = val(rows_accum[key])
new_row[key] = val._from_engine(rows_accum[key])
#: add extras if needed (eg. operations results)
if extras:
new_row['_extra'] = extras
Expand Down
Loading

0 comments on commit 473525b

Please sign in to comment.