alexapy.aiohttp.web_urldispatcher
¶
Classes¶
UrlDispatcher
: Helper class that provides a standard way to create an ABC usingUrlMappingMatchInfo
: dict() -> new empty dictionaryAbstractResource
: Abstract base class for generic types.Resource
: Abstract base class for generic types.PlainResource
: Abstract base class for generic types.DynamicResource
: Abstract base class for generic types.AbstractRoute
: Helper class that provides a standard way to create an ABC usingResourceRoute
: A route with resourceStaticResource
: Abstract base class for generic types.View
: Abstract class based view.
- class alexapy.aiohttp.web_urldispatcher.UrlDispatcher¶
Inheritance
- add_delete(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method DELETE.
- add_get(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], *, name: Optional[str] = None, allow_head: bool = True, **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method GET.
If allow_head is true, another route is added allowing head requests to the same endpoint.
- add_head(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method HEAD.
- add_options(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method OPTIONS.
- add_patch(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method PATCH.
- add_post(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method POST.
- add_put(path: str, handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with method PUT.
- add_routes(routes: Iterable[alexapy.aiohttp.web_routedef.AbstractRouteDef]) List[alexapy.aiohttp.web_urldispatcher.AbstractRoute] ¶
Append routes to route table.
Parameter should be a sequence of RouteDef objects.
Returns a list of registered AbstractRoute instances.
- add_static(prefix: str, path: Union[str, os.PathLike[str]], *, name: Optional[str] = None, expect_handler: Optional[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[None]]] = None, chunk_size: int = 262144, show_index: bool = False, follow_symlinks: bool = False, append_version: bool = False) alexapy.aiohttp.web_urldispatcher.AbstractResource ¶
Add static files view.
prefix - url prefix path - folder with files
- add_view(path: str, handler: Type[alexapy.aiohttp.abc.AbstractView], **kwargs: Any) alexapy.aiohttp.web_urldispatcher.AbstractRoute ¶
Shortcut for add_route with ANY methods for a class-based view.
- freeze() None ¶
Freeze router.
- async resolve(request: alexapy.aiohttp.web_request.Request) alexapy.aiohttp.web_urldispatcher.UrlMappingMatchInfo ¶
Return MATCH_INFO for given request
- class alexapy.aiohttp.web_urldispatcher.UrlMappingMatchInfo(match_dict: Dict[str, str], route: alexapy.aiohttp.web_urldispatcher.AbstractRoute)¶
Inheritance
- add_app(app: Application) None ¶
Add application to the nested apps stack.
- property apps: Tuple[Application, ...]¶
Stack of nested applications.
Top level application is left-most element.
- property expect_handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[None]]¶
Expect handler for 100-continue processing
- freeze() None ¶
Freeze the match info.
The method is called after route resolution.
After the call .add_app() is forbidden.
- get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- property handler: Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]]¶
Execute matched request handler
- property http_exception: Optional[alexapy.aiohttp.web_exceptions.HTTPException]¶
HTTPException instance raised on router’s resolving, or None
- class alexapy.aiohttp.web_urldispatcher.AbstractResource(*, name: Optional[str] = None)¶
Inheritance
- abstract add_prefix(prefix: str) None ¶
Add a prefix to processed URLs.
Required for subapplications support.
- abstract property canonical: str¶
Exposes the resource’s canonical path.
For example ‘/foo/bar/{name}’
- abstract get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- abstract raw_match(path: str) bool ¶
Perform a raw match against path
- abstract async resolve(request: alexapy.aiohttp.web_request.Request) Tuple[Optional[alexapy.aiohttp.web_urldispatcher.UrlMappingMatchInfo], Set[str]] ¶
Resolve resource.
Return (UrlMappingMatchInfo, allowed_methods) pair.
- abstract url_for(**kwargs: str) yarl.URL ¶
Construct url for resource with additional params.
- class alexapy.aiohttp.web_urldispatcher.Resource(*, name: Optional[str] = None)¶
Inheritance
- async resolve(request: alexapy.aiohttp.web_request.Request) Tuple[Optional[alexapy.aiohttp.web_urldispatcher.UrlMappingMatchInfo], Set[str]] ¶
Resolve resource.
Return (UrlMappingMatchInfo, allowed_methods) pair.
- class alexapy.aiohttp.web_urldispatcher.PlainResource(path: str, *, name: Optional[str] = None)¶
Inheritance
- add_prefix(prefix: str) None ¶
Add a prefix to processed URLs.
Required for subapplications support.
- property canonical: str¶
Exposes the resource’s canonical path.
For example ‘/foo/bar/{name}’
- get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- raw_match(path: str) bool ¶
Perform a raw match against path
- url_for() yarl.URL ¶
Construct url for resource with additional params.
- class alexapy.aiohttp.web_urldispatcher.DynamicResource(path: str, *, name: Optional[str] = None)¶
Inheritance
- add_prefix(prefix: str) None ¶
Add a prefix to processed URLs.
Required for subapplications support.
- property canonical: str¶
Exposes the resource’s canonical path.
For example ‘/foo/bar/{name}’
- get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- raw_match(path: str) bool ¶
Perform a raw match against path
- url_for(**parts: str) yarl.URL ¶
Construct url for resource with additional params.
- class alexapy.aiohttp.web_urldispatcher.AbstractRoute(method: str, handler: Union[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], Type[alexapy.aiohttp.abc.AbstractView]], *, expect_handler: Optional[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[None]]] = None, resource: Optional[alexapy.aiohttp.web_urldispatcher.AbstractResource] = None)¶
Inheritance
- abstract get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- abstract property name: Optional[str]¶
Optional route’s name, always equals to resource’s name.
- abstract url_for(*args: str, **kwargs: str) yarl.URL ¶
Construct url for route with additional params.
- class alexapy.aiohttp.web_urldispatcher.ResourceRoute(method: str, handler: Union[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[alexapy.aiohttp.web_response.StreamResponse]], Type[alexapy.aiohttp.abc.AbstractView]], resource: alexapy.aiohttp.web_urldispatcher.AbstractResource, *, expect_handler: Optional[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[None]]] = None)¶
A route with resource
Inheritance
- get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- property name: Optional[str]¶
Optional route’s name, always equals to resource’s name.
- url_for(*args: str, **kwargs: str) yarl.URL ¶
Construct url for route with additional params.
- class alexapy.aiohttp.web_urldispatcher.StaticResource(prefix: str, directory: Union[str, os.PathLike[str]], *, name: Optional[str] = None, expect_handler: Optional[Callable[[alexapy.aiohttp.web_request.Request], Awaitable[None]]] = None, chunk_size: int = 262144, show_index: bool = False, follow_symlinks: bool = False, append_version: bool = False)¶
Inheritance
- get_info() alexapy.aiohttp.web_urldispatcher._InfoDict ¶
Return a dict with additional info useful for introspection
- async resolve(request: alexapy.aiohttp.web_request.Request) Tuple[Optional[alexapy.aiohttp.web_urldispatcher.UrlMappingMatchInfo], Set[str]] ¶
Resolve resource.
Return (UrlMappingMatchInfo, allowed_methods) pair.
- url_for(*, filename: Union[str, pathlib.Path], append_version: Optional[bool] = None) yarl.URL ¶
Construct url for resource with additional params.
- class alexapy.aiohttp.web_urldispatcher.View(request: None)¶
Inheritance