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)
| 122 | |
| 123 | |
| 124 | def _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 | |
| 151 | def _set_redirect(redirect_from, path): |
no test coverage detected
searching dependent graphs…