MCPcopy
hub / github.com/reflex-dev/reflex / get_route_args

Function get_route_args

reflex/route.py:57–96  ·  view source on GitHub ↗

Get the dynamic arguments for the given route. Args: route: The route to get the arguments for. Returns: The route arguments.

(route: str)

Source from the content-addressed store, hash-verified

55
56
57def 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
99def replace_brackets_with_keywords(input_string: str) -> str:

Callers 4

test_route_argsFunction · 0.90
test_invalid_route_argsFunction · 0.90
add_pageMethod · 0.90
_walk_app_featuresFunction · 0.90

Calls 2

_add_route_argFunction · 0.85
splitMethod · 0.80

Tested by 2

test_route_argsFunction · 0.72
test_invalid_route_argsFunction · 0.72