class
Analyzer::Python::Starlette
Defined in:
analyzer/analyzers/python/starlette.crConstant Summary
-
ADD_ROUTE_RE =
/(#{DOT_NATION})\.add_(websocket_)?route\s*\((.*)\)/m -
Hoisted out of the analyze loops: an interpolated regex literal recompiles (PCRE2 JIT) on every evaluation, and these interpolate only constants. The
.to_sexpansion is byte-identical to the previous inline form, so matching behaviour is unchanged. -
CLASS_METHOD_DEF_RE =
/^\s*(?:async\s+)?def\s+(get|post|put|patch|delete|head|options)\s*\(([^)]*)\)/ -
MOUNT_REGEX =
/Mount\s*\(\s*[rf]?['"]([^'"]*)['"]/ -
Mount('/prefix', routes=[...]) — only the prefix literal is needed; the routes list is scanned via the ongoing line loop while the mount is on the paren stack.
-
PATH_PARAM_REGEX =
/\{([a-zA-Z_][a-zA-Z0-9_]*)(?::[a-zA-Z_][a-zA-Z0-9_]*)?\}/ -
Path param in a route pattern: {name} or {name:type}. Starlette uses the :type suffix as a converter hint (int, str, float, uuid, path); it is stripped before the param is exposed as a path param.
-
ROUTE_REGEX =
/\b(WebSocketRoute|Route)\s*\(\s*[rf]?['"]([^'"]*)['"]([^)]*)/ -
Route('/path', handler, methods=[...]) — captures path, and the tail after the path literal so we can inspect methods= and the handler reference. The tail stops at the closing paren on the same line to keep the match cheap; multi-line Route() calls are still covered for the common (path, handler, methods) shape.
-
TYPED_PATH_PARAM_REGEX =
/\{([a-zA-Z_][a-zA-Z0-9_]*):[a-zA-Z_][a-zA-Z0-9_]*\}/