MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / routes_from_urlconf

Function routes_from_urlconf

plugins/ast/python/src/lib.rs:228–246  ·  view source on GitHub ↗

Extract a route from a Django URLConf entry: `path("p/", view)`, `re_path(r"^p$", view)`, or legacy `url(...)`. Django doesn't bind a method at the URL layer, so we emit "ALL".

(expression: &Expression, routes: &mut Vec<Route>)

Source from the content-addressed store, hash-verified

226/// Extract a route from a Django URLConf entry: `path("p/", view)`, `re_path(r"^p$", view)`,
227/// or legacy `url(...)`. Django doesn't bind a method at the URL layer, so we emit "ALL".
228fn routes_from_urlconf(expression: &Expression, routes: &mut Vec<Route>) {
229 let Expression::Call(CallExpression {
230 func, arguments, ..
231 }) = expression
232 else {
233 return;
234 };
235
236 if !matches!(call_leaf(func).as_deref(), Some("path" | "re_path" | "url")) {
237 return;
238 }
239
240 if let Some(raw) = arguments.args.first().and_then(expr_string) {
241 routes.push(Route {
242 method: "ALL".into(),
243 path: normalize_route(&raw),
244 });
245 }
246}
247
248/// Normalize a URLConf pattern to a leading-slash path, stripping regex anchors.
249fn normalize_route(raw: &str) -> String {

Callers 1

collect_routesFunction · 0.85

Calls 1

normalize_routeFunction · 0.85

Tested by

no test coverage detected