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

Function collect_routes

plugins/ast/python/src/lib.rs:198–224  ·  view source on GitHub ↗
(body: &[Statement], routes: &mut Vec<Route>)

Source from the content-addressed store, hash-verified

196const ROUTE_VERBS: &[&str] = &["get", "post", "put", "patch", "delete", "options", "head"];
197
198fn 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".

Callers 1

parseRoutesFunction · 0.85

Calls 2

routes_from_decoratorFunction · 0.85
routes_from_urlconfFunction · 0.85

Tested by

no test coverage detected