MCPcopy
hub / github.com/plotly/dash / _parse_path_variables

Function _parse_path_variables

dash/_pages.py:124–148  ·  view source on GitHub ↗

creates the dict of path variables passed to the layout e.g. path_template= "/asset/ " if pathname provided by the browser is "/assets/a100" returns **{"asset_id": "a100"}

(pathname, path_template)

Source from the content-addressed store, hash-verified

122
123
124def _parse_path_variables(pathname, path_template):
125 """
126 creates the dict of path variables passed to the layout
127 e.g. path_template= "/asset/<asset_id>"
128 if pathname provided by the browser is "/assets/a100"
129 returns **{"asset_id": "a100"}
130 """
131
132 # parse variable definitions e.g. <var_name> from template
133 # and create pattern to match
134 wildcard_pattern = re.sub("<.*?>", "*", path_template)
135 var_pattern = re.sub("<.*?>", "(.*)", path_template)
136
137 # check that static sections of the pathname match the template
138 if not fnmatch(pathname, wildcard_pattern):
139 return None
140
141 # parse variable names e.g. var_name from template
142 var_names = re.findall("<(.*?)>", path_template)
143
144 # parse variables from path
145 variables = re.findall(var_pattern, pathname)
146 variables = variables[0] if isinstance(variables[0], tuple) else variables
147
148 return dict(zip(var_names, variables))
149
150
151def _set_redirect(redirect_from, path):

Callers 1

_path_to_pageFunction · 0.85

Calls 1

subMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…