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
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 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 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 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 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 | |
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
2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 | |
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
2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 | |
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
2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 | |
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
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 | |
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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
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
509 510 511 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 542 543 544 | |
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
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
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
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
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
138 139 140 141 142 143 144 145 146 147 | |
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
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 | |
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
760 761 762 763 764 765 766 767 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 | |
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
802 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 | |
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
837 838 839 840 841 842 843 844 845 846 847 848 849 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 875 876 877 878 879 880 881 882 | |
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
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 | |
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
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 | |
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
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
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
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 | |
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
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | |
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
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | |
resolve_app_parent
¶
resolve_app_parent(app)
Resolves the owner of ChildRavyn or Ravyn iself.
Source code in ravyn/routing/router.py
4075 4076 4077 4078 4079 4080 4081 4082 4083 | |
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
4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 | |
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
4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 | |
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
4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 | |
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
4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 | |
- path
- app
- name
- routes
- namespace
- pattern
- parent
- dependencies
- exception_handlers
- interceptors
- permissions
- middleware
- include_in_schema
- deprecated
- security
- tags