Include class¶
This is the reference for the Include that contains all the parameters,
attributes and functions.
How to import¶
from ravyn import Include
ravyn.Include
¶
Include(
path=None,
app=None,
name=None,
routes=None,
namespace=None,
pattern=None,
parent=None,
dependencies=None,
interceptors=None,
permissions=None,
exception_handlers=None,
middleware=None,
before_request=None,
after_request=None,
include_in_schema=True,
deprecated=None,
security=None,
tags=None,
redirect_slashes=True,
)
Bases: Dispatcher, Include
Include object class that allows scalability and modularity
to happen with elegance.
Read more about the Include to understand what can be done.
Include manages routes as a list or as a namespace but not both or a
ImproperlyConfigured is raised.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Relative path of the Example Example with parameters
TYPE:
|
app
|
An application can be anything that is treated as an ASGI application.
For example, it can be a ChildRavyn, another The app is a parameter that makes the Include extremely powerful when it comes to integrate with ease with whatever Python stack you want and need. Example Example with a WSGI framework
TYPE:
|
name
|
The name for the Gateway. The name can be reversed by
TYPE:
|
routes
|
A global This is also an entry-point for the routes of the Include but it does not rely on only one level. Read more about how to use and leverage the Ravyn routing system. Example Note The Include is very powerful and this example is not enough to understand what more things you can do. Read in more detail about this.
TYPE:
|
namespace
|
A string with a qualified namespace from where the URLs should be loaded. The namespace is an alternative to The When using a Example Assuming there is a file with some routes located at myapp/auth/urls.py
Using the
TYPE:
|
pattern
|
A string By default, the when using the Example Assuming there is a file with some routes located at myapp/auth/urls.py
Using the
TYPE:
|
parent
|
Who owns the Gateway. If not specified, the application automatically it assign it. This is directly related with the application levels.
TYPE:
|
dependencies
|
A dictionary of string and Inject instances enable application level dependency injection.
TYPE:
|
interceptors
|
A list of interceptors to serve the application incoming requests (HTTP and Websockets).
TYPE:
|
permissions
|
A list of permissions to serve the application incoming requests (HTTP and Websockets).
TYPE:
|
exception_handlers
|
A dictionary of exception types (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of
TYPE:
|
middleware
|
A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.
TYPE:
|
before_request
|
A Read more about the events.
TYPE:
|
after_request
|
A Read more about the events.
TYPE:
|
include_in_schema
|
Boolean flag indicating if it should be added to the OpenAPI docs. This will add all the routes of the Include even those nested (Include containing more Includes.)
TYPE:
|
deprecated
|
Boolean flag for indicating the deprecation of the Include and all of its routes and to display it in the OpenAPI documentation..
TYPE:
|
security
|
Used by OpenAPI definition, the security must be compliant with the norms. Ravyn offers some out of the box solutions where this is implemented. The Ravyn security is available to automatically used. The security can be applied also on a level basis. For custom security objects, you must subclass
TYPE:
|
tags
|
A list of strings tags to be applied to the path operation. It will be added to the generated OpenAPI documentation. Note almost everything in Ravyn can be done in levels, which means these tags on a Ravyn instance, means it will be added to every route even if those routes also contain tags.
TYPE:
|
redirect_slashes
|
Boolean flag indicating if the redirect slashes are enabled for the routes or not.
TYPE:
|
Source code in ravyn/routing/router.py
3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 | |
stringify_parameters
property
¶
stringify_parameters
Gets the param:type in string like list.
Used for the directive ravyn show_urls.
This property returns a list of strings representing the parameter name and type in the format "param:type".
It is used specifically for the ravyn show_urls directive.
The method first parses the path of the dispatcher object using the parse_path method.
It then filters out any path components that are not dictionaries, leaving only the parameter components.
Next, it iterates over each parameter component and creates a string in the format "param:type". The parameter name is obtained from the 'name' key of the component dictionary, and the parameter type is obtained from the 'type' key of the component dictionary.
Finally, the method returns the list of stringified parameters.
Returns: - list[str]: A list of strings representing the parameter name and type in the format "param:type".
Example:
dispatcher = Dispatcher() parameters = dispatcher.stringify_parameters() print(parameters) ['param1:int', 'param2:str', 'param3:bool']
Note:
- The parameter type is obtained using the __name__ attribute of the type object.
- The parameter components are obtained by parsing the path of the dispatcher object.
- If there are no parameter components in the path, an empty list will be returned.
exception_handlers
instance-attribute
¶
exception_handlers = (
{}
if exception_handlers is None
else dict(exception_handlers)
)
wrapped_permissions
instance-attribute
¶
wrapped_permissions = [
(wrap_permission(permission))
for permission in (permissions or [])
]
before_request
instance-attribute
¶
before_request = (
before_request if before_request is not None else []
)
after_request
instance-attribute
¶
after_request = (
after_request if after_request is not None else []
)
handler_signature
property
¶
handler_signature
Returns the Signature of the handler function.
This property returns the Signature object representing the signature of the handler function. The Signature object provides information about the parameters, return type, and annotations of the handler function.
Returns: - Signature: The Signature object representing the signature of the handler function.
Example:
handler = Dispatcher() signature = handler.handler_signature print(signature)
Note:
- The Signature object is created using the from_callable method of the Signature class.
- The from_callable method takes a callable object (in this case, the handler function) as input and returns a Signature object.
- The Signature object can be used to inspect the parameters and return type of the handler function.
path_parameters
property
¶
path_parameters
Gets the path parameters in a set format.
This property returns a set of path parameters used in the URL pattern of the handler. Each path parameter represents a dynamic value that is extracted from the URL during routing.
Returns: - Set[str]: A set of path parameters.
Example:
handler = Dispatcher() parameters = handler.path_parameters print(parameters)
Note: - The path parameters are extracted from the URL pattern defined in the handler's route. - The path parameters are represented as strings. - If no path parameters are defined in the URL pattern, an empty set will be returned.
parent_levels
property
¶
parent_levels
Returns the handler from the app down to the route handler.
This property returns a list of all the parent levels of the current handler. Each parent level represents a higher level in the routing hierarchy.
Example: Consider the following routing hierarchy: app = Ravyn(routes=[ Include(path='/api/v1', routes=[ Gateway(path='/home', handler=home) ]) ])
In this example, the parent of the Gateway handler is the Include handler. The parent of the Include handler is the Ravyn router. The parent of the Ravyn router is the Ravyn app itself.
The parent_levels property uses a while loop to traverse the parent hierarchy.
It starts with the current handler and iteratively adds each parent level to a list.
Finally, it reverses the list to maintain the correct order of parent levels.
Returns: - list[Any]: A list of parent levels, starting from the current handler and going up to the app level.
Note:
- The parent levels are determined based on the parent attribute of each handler.
- If there are no parent levels (i.e., the current handler is the top-level handler), an empty list will be returned.
dependency_names
property
¶
dependency_names
Returns a unique set of all dependency names provided in the handlers parent levels.
This property retrieves the dependencies from each parent level of the handler and collects all the dependency names in a set. It ensures that the set only contains unique dependency names.
Returns: - Set[str]: A set of unique dependency names.
Example:
handler = Dispatcher() dependency_names = handler.dependency_names print(dependency_names)
Note: - If no dependencies are defined in any of the parent levels, an empty set will be returned. - The dependencies are collected from all parent levels, ensuring that there are no duplicate dependency names in the final set.
lilya_permissions
instance-attribute
¶
lilya_permissions = {
index: (permission in __lilya_permissions__)
for (index, permission) in (
enumerate(__lilya_permissions__)
)
}
permissions
instance-attribute
¶
permissions = {
index: (wrap_permission(permission))
for (index, permission) in (enumerate(permissions))
if is_ravyn_permission(permission)
}
handle_signature
¶
handle_signature()
Source code in lilya/routing.py
121 122 | |
search
¶
search(scope)
Searches within the route patterns and matches against the regex.
If found, then dispatches the request to the handler of the object.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The request scope.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Match, Scope]
|
Tuple[Match, Scope]: The match result and child scope. |
Source code in lilya/routing.py
2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 | |
path_for
¶
path_for(name, /, **path_params)
Generate a URLPath for a given route name and path parameters.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the route.
TYPE:
|
path_params
|
Path parameters for route substitution.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
URLPath
|
The generated URLPath.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NoMatchFound
|
If no matching route is found for the given name and parameters. |
Source code in lilya/routing.py
2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 | |
url_path_for
¶
url_path_for(name, /, **path_params)
Generate a URLPath for a given route name and path parameters.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name of the route.
TYPE:
|
path_params
|
Path parameters for route substitution.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
URLPath
|
The generated URLPath.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
NoMatchFound
|
If no matching route is found for the given name and parameters. |
Source code in lilya/routing.py
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 | |
dispatch
async
¶
dispatch(scope, receive, send)
Dispatches the request to the appropriate handler.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The request scope.
TYPE:
|
receive
|
The receive channel.
TYPE:
|
send
|
The send channel.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
None |
Source code in lilya/routing.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
handle_not_found_fallthrough
async
staticmethod
¶
handle_not_found_fallthrough(scope, receive, send)
Source code in lilya/routing.py
182 183 184 | |
handle_exception_handlers
async
¶
handle_exception_handlers(scope, receive, send, exc)
Manages exception handlers for HTTP and WebSocket scopes.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The ASGI scope.
TYPE:
|
receive
|
The receive function.
TYPE:
|
send
|
The send function.
TYPE:
|
exc
|
The exception to handle.
TYPE:
|
Source code in lilya/routing.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
handle_match
¶
handle_match(scope, match, route_path, root_path)
Handles the case when a match is found in the route patterns.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The request scope.
TYPE:
|
match
|
The match object from the regex.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Match, Scope]
|
Tuple[Match, Scope]: The match result and child scope. |
Source code in lilya/routing.py
2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 | |
parse_path
¶
parse_path(path)
Using the Lilya TRANSFORMERS and the application registered convertors, transforms the path into a PathParameterSchema used for the OpenAPI definition.
Source code in ravyn/routing/core/base.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
get_response_for_handler
¶
get_response_for_handler()
Checks and validates the type of return response and maps to the corresponding handler with the given parameters.
| RETURNS | DESCRIPTION |
|---|---|
Callable[[Any], Awaitable[Response]]
|
Callable[[Any], Awaitable[LilyaResponse]]: The response handler function. |
Source code in ravyn/routing/core/base.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
get_response_for_request
async
¶
get_response_for_request(
scope, request, route, parameter_model
)
Get response for the given request using the specified route and parameter model.
| PARAMETER | DESCRIPTION |
|---|---|
scope
|
The scope of the request.
TYPE:
|
request
|
The incoming request.
TYPE:
|
route
|
The route handler for the request.
TYPE:
|
parameter_model
|
The parameter model for handling request parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LilyaResponse
|
The response generated for the request.
TYPE:
|
Source code in ravyn/routing/core/base.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
create_signature_model
¶
create_signature_model(is_websocket=False)
Creates a signature model for the given route.
Websockets do not support methods.
Source code in ravyn/routing/core/base.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
create_handler_transformer_model
¶
create_handler_transformer_model()
Method to create a TransformerModel for a given handler.
Source code in ravyn/routing/core/base.py
139 140 141 142 143 144 145 146 147 148 | |
get_lookup_path
¶
get_lookup_path(ignore_first=True)
Constructs and returns the lookup path for the current object by traversing its parent hierarchy.
The method collects the 'name' attribute of the current object and its ancestors, if they exist, and returns them as a list in reverse order (from the root ancestor to the current object).
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
list[str]: A list of names representing the lookup path from the root |
list[str]
|
ancestor to the current object. |
Source code in ravyn/routing/core/base.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 | |
get_dependencies
¶
get_dependencies()
Returns all dependencies of the handler function's starting from the parent levels.
This method retrieves all the dependencies of the handler function by iterating over each parent level. It collects the dependencies defined in each level and stores them in a dictionary.
Returns: - Dependencies: A dictionary containing all the dependencies of the handler function.
Raises:
- RuntimeError: If get_dependencies is called before a signature model has been generated.
Example:
handler = Dispatcher() dependencies = handler.get_dependencies() print(dependencies)
Note: - If no dependencies are defined in any of the parent levels, an empty dictionary will be returned. - Each dependency is represented by a key-value pair in the dictionary, where the key is the dependency name and the value is the dependency object. - The dependencies are collected from all parent levels, ensuring that there are no duplicate dependencies in the final dictionary.
Source code in ravyn/routing/core/base.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |
is_unique_dependency
staticmethod
¶
is_unique_dependency(dependencies, key, injector)
Validates that a given inject has not been already defined under a different key in any of the levels.
This method takes in a dictionary of dependencies, a key, and an injector. It checks if the injector is already defined in the dependencies dictionary under a different key.
Parameters: - dependencies (Dependencies): A dictionary of dependencies. - key (str): The key to check for uniqueness. - injector (Inject): The injector to check.
Raises: - ImproperlyConfigured: If the injector is already defined under a different key in the dependencies dictionary.
Example:
dependencies = {"db": injector1, "logger": injector2} key = "db" injector = injector3 is_unique_dependency(dependencies, key, injector)
This method iterates over each key-value pair in the dependencies dictionary. If the value matches the given injector, it raises an ImproperlyConfigured exception with a detailed error message.
Note: - The dependencies dictionary is expected to have string keys and values of type Inject. - The key parameter should be a string representing the key to check for uniqueness. - The injector parameter should be an instance of the Inject class.
Source code in ravyn/routing/core/base.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 | |
get_cookies
¶
get_cookies(local_cookies, other_cookies=None)
Returns a unique list of cookies.
This method takes two sets of cookies, local_cookies and other_cookies,
and returns a list of dictionaries representing the normalized cookies.
Parameters: - local_cookies (ResponseCookies): The set of local cookies. - other_cookies (ResponseCookies): The set of other cookies.
Returns: - list[dict[str, Any]]: A list of dictionaries representing the normalized cookies.
The method first creates a filtered list of cookies by combining the local_cookies
and other_cookies sets. It ensures that only unique cookies are included in the list.
Then, it normalizes each cookie by converting it into a dictionary representation, excluding the 'description' attribute. The normalized cookies are stored in a list.
Finally, the method returns the list of normalized cookies.
Note: - The 'description' attribute is excluded from the normalized cookies.
Example usage:
local_cookies = [...]
other_cookies = [...]
normalized_cookies = get_cookies(local_cookies, other_cookies)
print(normalized_cookies)
This will output the list of normalized cookies.
Source code in ravyn/routing/core/base.py
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 | |
get_headers
¶
get_headers(headers)
Returns a dictionary of response headers.
Parameters: - headers (ResponseHeaders): The response headers object.
Returns: - dict[str, Any]: A dictionary containing the response headers.
Example:
headers = {"Content-Type": "application/json", "Cache-Control": "no-cache"} response_headers = get_headers(headers) print(response_headers)
This method takes a ResponseHeaders object and converts it into a dictionary
of response headers. Each key-value pair in the ResponseHeaders object is
added to the dictionary.
Note:
- The ResponseHeaders object is expected to have string keys and values.
- If the ResponseHeaders object is empty, an empty dictionary will be returned.
Source code in ravyn/routing/core/base.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
get_response_data
async
¶
get_response_data(data)
Retrieves the response data for synchronous and asynchronous operations.
This method takes in a data parameter, which can be either a regular value or an awaitable object.
If data is an awaitable object, it will be awaited to retrieve the actual response data.
If data is a regular value, it will be returned as is.
Parameters: - data (Any): The response data, which can be either a regular value or an awaitable object.
Returns: - Any: The actual response data.
Example usage:
response_data = await get_response_data(some_data)
Source code in ravyn/routing/core/base.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
allow_connection
async
¶
allow_connection(connection, permission)
Asynchronously allows a connection based on the provided permission.
| PARAMETER | DESCRIPTION |
|---|---|
permission
|
The permission object to check.
TYPE:
|
connection
|
The connection object representing the request.
TYPE:
|
Returns: None Raises: PermissionException: If the permission check fails.
Source code in ravyn/routing/core/base.py
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 | |
dispatch_allow_connection
async
¶
dispatch_allow_connection(
permissions,
connection,
scope,
receive,
send,
dispatch_call,
)
Dispatches a connection based on the provided permissions.
| PARAMETER | DESCRIPTION |
|---|---|
permissions
|
A dictionary mapping permission levels to either an asynchronous callable or a DefinePermission instance.
TYPE:
|
connection
|
The connection object to be dispatched.
TYPE:
|
scope
|
The scope of the connection.
TYPE:
|
receive
|
The receive channel for the connection.
TYPE:
|
send
|
The send channel for the connection.
TYPE:
|
Returns: None
Source code in ravyn/routing/core/base.py
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
get_security_schemes
¶
get_security_schemes()
Returns a list of all security schemes associated with the handler.
This method iterates over each parent level of the handler and collects the security schemes defined in each level. The collected security schemes are stored in a list and returned.
Returns: - list[SecurityScheme]: A list of security schemes associated with the handler.
Example:
handler = Dispatcher() security_schemes = handler.get_security_schemes() print(security_schemes) [SecurityScheme(name='BearerAuth', type='http', scheme='bearer', bearer_format='JWT'), SecurityScheme(name='ApiKeyAuth', type='apiKey', in_='header', name='X-API-Key')]
Note: - If no security schemes are defined in any of the parent levels, an empty list will be returned. - Each security scheme is represented by an instance of the SecurityScheme class. - The SecurityScheme class has attributes such as name, type, scheme, bearer_format, in_, and name, which provide information about the security scheme.
Source code in ravyn/routing/core/base.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
get_handler_tags
¶
get_handler_tags()
Returns all the tags associated with the handler by checking the parents as well.
This method retrieves all the tags associated with the handler by iterating over each parent level. It collects the tags defined in each level and stores them in a list.
Returns: - list[str]: A list of tags associated with the handler.
Example:
handler = Dispatcher() tags = handler.get_handler_tags() print(tags) ['api', 'user']
Note: - If no tags are defined in any of the parent levels, an empty list will be returned. - Each tag is represented as a string. - The tags are collected from all parent levels, ensuring that there are no duplicate tags in the final list.
Source code in ravyn/routing/core/base.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 | |
resolve_app_parent
¶
resolve_app_parent(app)
Resolves the owner of ChildRavyn or Ravyn iself.
Source code in ravyn/routing/router.py
3897 3898 3899 3900 3901 3902 3903 3904 3905 | |
resolve_route_path_handler
¶
resolve_route_path_handler(routes)
Make sure the paths are properly configured from the handler handler. The handler can be a Lilya function, an View or a HTTPHandler.
LilyaBasePath() has a limitation of not allowing nested LilyaBasePath().
Example:
route_patterns = [
LilyaBasePath(path='/my path', routes=[
LilyaBasePath(path='/another mount')
])
]
Include() extends the LilyaBasePath and adds extras on the top. Allowing nested Include() also allows importing in different ways. Via qualified namespace or via list() but not both.
Example:
1. Root of the application, example, `urls.py`.
route_patterns = [
Include(path='/api/v1/', namespace='myapp.v1.urls'),
Gateway(path='/example', handler=example_endpoint, name='example')
...
]
2. Inside `myapp.v1.urls`
from mysecondapp.urls import route_patterns
route_patterns = [
Include(path='/api/v2/', routes=route_patterns),
Gateway(path='/another-example', handler=another_endpoint, name='example')
...
]
3. Inside `mysecondapp.v1.urls`:
route_patterns = [
Gateway(path='/last-example', handler=another_endpoint, name='example')
...
]
Source code in ravyn/routing/router.py
3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 | |
handle_interceptors
async
¶
handle_interceptors(scope, receive, send)
Handles the interceptors for the Include. This method ensures that the interceptors are set correctly and that they are compatible with the Lilya interceptors system.
Source code in ravyn/routing/router.py
4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 | |
handle_permissions
async
¶
handle_permissions(scope, receive, send)
Handles the permissions for the Include. This method ensures that the permissions are set correctly and that they are compatible with the Lilya permissions system.
Source code in ravyn/routing/router.py
4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 | |
handle_dispatch
async
¶
handle_dispatch(scope, receive, send)
In the call we need to make sure we call the permissions and validations first to assure it won't even reach the lower app and run the validation against.
Source code in ravyn/routing/router.py
4076 4077 4078 4079 4080 4081 4082 4083 | |
- path
- app
- name
- routes
- namespace
- pattern
- parent
- dependencies
- exception_handlers
- interceptors
- permissions
- middleware
- include_in_schema
- deprecated
- security
- tags