MCPcopy
hub / github.com/pallets/werkzeug / _prefix_names

Function _prefix_names

src/werkzeug/routing/rules.py:299–311  ·  view source on GitHub ↗

ast parse and prefix names with `.` to avoid collision with user vars

(src: str, expected_type: type[_ASTT])

Source from the content-addressed store, hash-verified

297
298
299def _prefix_names(src: str, expected_type: type[_ASTT]) -> _ASTT:
300 """ast parse and prefix names with `.` to avoid collision with user vars"""
301 tree: ast.AST = ast.parse(src).body[0]
302 if isinstance(tree, ast.Expr):
303 tree = tree.value
304 if not isinstance(tree, expected_type):
305 raise TypeError(
306 f"AST node is of type {type(tree).__name__}, not {expected_type.__name__}"
307 )
308 for node in ast.walk(tree):
309 if isinstance(node, ast.Name):
310 node.id = f".{node.id}"
311 return tree
312
313
314_CALL_CONVERTER_CODE_FMT = "self._converters[{elem!r}].to_url()"

Callers 3

rules.pyFile · 0.85
_convertMethod · 0.85
_compile_builderMethod · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected