Get the dynamic arguments for the given route. Args: route: The route to get the arguments for. Returns: The route arguments.
(route: str)
| 55 | |
| 56 | |
| 57 | def get_route_args(route: str) -> dict[str, str]: |
| 58 | """Get the dynamic arguments for the given route. |
| 59 | |
| 60 | Args: |
| 61 | route: The route to get the arguments for. |
| 62 | |
| 63 | Returns: |
| 64 | The route arguments. |
| 65 | """ |
| 66 | args = {} |
| 67 | |
| 68 | def _add_route_arg(arg_name: str, type_: str): |
| 69 | if arg_name in args: |
| 70 | msg = ( |
| 71 | f"Arg name `{arg_name}` is used more than once in the route `{route}`." |
| 72 | ) |
| 73 | raise ValueError(msg) |
| 74 | args[arg_name] = type_ |
| 75 | |
| 76 | # Regex to check for route args. |
| 77 | argument_regex = constants.RouteRegex.ARG |
| 78 | optional_argument_regex = constants.RouteRegex.OPTIONAL_ARG |
| 79 | |
| 80 | # Iterate over the route parts and check for route args. |
| 81 | for part in route.split("/"): |
| 82 | if part == constants.RouteRegex.SPLAT_CATCHALL: |
| 83 | _add_route_arg("splat", constants.RouteArgType.LIST) |
| 84 | break |
| 85 | |
| 86 | optional_argument = optional_argument_regex.match(part) |
| 87 | if optional_argument: |
| 88 | _add_route_arg(optional_argument.group(1), constants.RouteArgType.SINGLE) |
| 89 | continue |
| 90 | |
| 91 | argument = argument_regex.match(part) |
| 92 | if argument: |
| 93 | _add_route_arg(argument.group(1), constants.RouteArgType.SINGLE) |
| 94 | continue |
| 95 | |
| 96 | return args |
| 97 | |
| 98 | |
| 99 | def replace_brackets_with_keywords(input_string: str) -> str: |