(body: &[Statement], routes: &mut Vec<Route>)
| 196 | const ROUTE_VERBS: &[&str] = &["get", "post", "put", "patch", "delete", "options", "head"]; |
| 197 | |
| 198 | fn collect_routes(body: &[Statement], routes: &mut Vec<Route>) { |
| 199 | for statement in body { |
| 200 | match statement { |
| 201 | Statement::ClassDef(class) => collect_routes(&class.body, routes), |
| 202 | Statement::FunctionDef(function) => { |
| 203 | for decorator in &function.decorator_list { |
| 204 | routes_from_decorator(&decorator.expression, routes); |
| 205 | } |
| 206 | } |
| 207 | // Django URLConf: `urlpatterns = [path("p/", view), re_path(...), ...]`. |
| 208 | Statement::Assign(Assignment { targets, value, .. }) => { |
| 209 | let is_urlpatterns = targets.iter().any(|t| { |
| 210 | matches!(t, Expression::Name(NameExpression { id, .. }) if id.as_str() == "urlpatterns") |
| 211 | }); |
| 212 | |
| 213 | if is_urlpatterns { |
| 214 | if let Expression::List(list) = &**value { |
| 215 | for element in &list.elts { |
| 216 | routes_from_urlconf(element, routes); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | _ => {} |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 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". |
no test coverage detected