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>)
| 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". |
| 228 | fn 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. |
| 249 | fn normalize_route(raw: &str) -> String { |
no test coverage detected