-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: map Python middlewares to Tower layers (#1871)
* Python: map Python middlewares to Tower layers * Make middleware layer infallible * Use message and status code from `PyMiddlewareException` * Introduce `FuncMetadata` to represent some information about a Python function * Improve middleware errors * Add missing copyright headers * Allow accessing and changing request body * Allow changing response * Add some documentation about moving data back-and-forth between Rust and Python * Add `mypy` to Pokemon service and update typings and comments for middlewares * Add or update comments on the important types * Add Rust equivalent of `collections.abc.MutableMapping` * Add `PyHeaderMap` to make `HeaderMap` accessible from Python * Apply suggestions from code review Co-authored-by: Luca Palmieri <[email protected]> * Improve logging * Add `RichPyErr` to have a better output for `PyErr`s * Better error messages for `PyMiddlewareError` variants * Factor out repeating patterns in tests * Preserve `__builtins__` in `globals` to fix tests in Python 3.7.10 (our CI version) * Export `RichPyErr` to fix `cargo doc` error * Apply suggestions from code review Co-authored-by: Matteo Bigoi <[email protected]> * Add missing SPDX headers * Document that `keys`, `values` and `items` on `PyMutableMapping` causes clones Co-authored-by: Luca Palmieri <[email protected]> Co-authored-by: Matteo Bigoi <[email protected]>
- Loading branch information
1 parent
b82b6a6
commit 4f76e35
Showing
27 changed files
with
1,798 additions
and
766 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
rust-runtime/aws-smithy-http-server-python/examples/libpokemon_service_server_sdk.pyi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# NOTE: This is manually created to surpass some mypy errors and it is incomplete, | ||
# in future we will autogenerate correct stubs. | ||
|
||
from typing import Any, TypeVar, Callable | ||
|
||
F = TypeVar("F", bound=Callable[..., Any]) | ||
|
||
class App: | ||
context: Any | ||
run: Any | ||
|
||
def middleware(self, func: F) -> F: ... | ||
def do_nothing(self, func: F) -> F: ... | ||
def get_pokemon_species(self, func: F) -> F: ... | ||
def get_server_statistics(self, func: F) -> F: ... | ||
def check_health(self, func: F) -> F: ... | ||
def stream_pokemon_radio(self, func: F) -> F: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
[mypy] | ||
strict = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.