-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrated to Asphalt 5 #68
base: master
Are you sure you want to change the base?
Conversation
Also dropped the install condition for aiohttp (it has worked on Python 3.12 for a while now)
async with Context() as ctx: | ||
ctx.add_resource(request, types=[Request]) | ||
async with Context(): | ||
add_resource(request, types=[Request]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(request, types=[Request]) | |
add_resource(request, types=Request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types
accepts a single type, which is the case here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is what it says in the docstring:
:param types: type(s) to register the resource as (omit to use the type of
value
)
And the annotation is:
types: type | Sequence[type] = (),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm so it seems that it can accept a single type, or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, althought the naming of the parameter suggests that it should be passed an iterable of types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, it doesn't matter a lot.
scope_type = HTTPScope if scope["type"] == "http" else WebSocketScope | ||
ctx.add_resource(scope, types=[scope_type]) | ||
add_resource(scope, types=[scope_type]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(scope, types=[scope_type]) | |
add_resource(scope, types=scope_type) |
if isinstance(request, ASGIRequest): | ||
ctx.add_resource(request.scope, types=[HTTPScope]) | ||
add_resource(request.scope, types=[HTTPScope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(request.scope, types=[HTTPScope]) | |
add_resource(request.scope, types=HTTPScope) |
if scope["type"] == "http": | ||
ctx.add_resource(scope, types=[HTTPScope]) | ||
ctx.add_resource(Request(scope)) | ||
add_resource(scope, types=[HTTPScope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(scope, types=[HTTPScope]) | |
add_resource(scope, types=HTTPScope) |
elif scope["type"] == "websocket": | ||
ctx.add_resource(scope, types=[WebSocketScope]) | ||
ctx.add_resource(Request(scope)) | ||
add_resource(scope, types=[WebSocketScope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(scope, types=[WebSocketScope]) | |
add_resource(scope, types=WebSocketScope) |
if scope["type"] == "http": | ||
ctx.add_resource(scope, types=[HTTPScope]) | ||
add_resource(scope, types=[HTTPScope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(scope, types=[HTTPScope]) | |
add_resource(scope, types=HTTPScope) |
elif scope["type"] == "websocket": | ||
ctx.add_resource(scope, types=[WebSocketScope]) | ||
add_resource(scope, types=[WebSocketScope]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(scope, types=[WebSocketScope]) | |
add_resource(scope, types=WebSocketScope) |
|
||
await super().__call__(scope, receive, send) | ||
|
||
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response: | ||
current_context().add_resource(request, types=[Request]) | ||
add_resource(request, types=[Request]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_resource(request, types=[Request]) | |
add_resource(request, types=Request) |
No description provided.