class
Analyzer::Python::Litestar
Defined in:
analyzer/analyzers/python/litestar.crConstant Summary
-
CLASS_HEAD_RE =
/^\s*class\s+(#{PYTHON_VAR_NAME_REGEX})\s*\(/ -
CONTROLLER_CLASS_RE =
/^\s*class\s+(#{PYTHON_VAR_NAME_REGEX})\s*\(([^)]*)\)/ -
DECORATOR_PATH_KW_REGEX =
/path\s*=\s*[rf]?['"]([^'"]*)['"]/ -
DECORATOR_PATH_REGEX =
/^\s*[rf]?['"]([^'"]*)['"]/ -
Path literal inside a decorator. Litestar accepts both a positional path and an explicit
path=keyword argument. -
DECORATOR_REGEX =
/@(get|post|put|patch|delete|head|options|route|websocket(?:_listener|_stream)?)\s*\(([^)]*)/ -
Decorator matching: @get("/path"), @post("/path"), etc. The tail after the path literal is captured so extra kwargs (like methods=) can be inspected for multi-method @route decorators.
websocket(?:_listener|_stream)?also matches Litestar's@websocket_listener("/ws")and@websocket_stream("/ws")decorators (the listener/stream class-based WS handlers), which take a positional path just like@websocket— without the variants every listener/stream endpoint was silently dropped. -
DOTTED_HANDLER_RE =
/(#{PYTHON_VAR_NAME_REGEX})\.(#{PYTHON_VAR_NAME_REGEX})/ -
Hoisted out of the per-line/per-param loops: an interpolated regex literal recompiles (PCRE2 JIT) on every evaluation, and these interpolate only constants or fixed sets. The
.to_sexpansion is byte-identical to the previous inline form, so matching behaviour is unchanged. -
HTTP_METHOD_KW_REGEX =
/http_method\s*=\s*(?:\[([^\]]*)\]|['"]([^'"]+)['"])/ -
PATH_PARAM_REGEX =
/\{([a-zA-Z_][a-zA-Z0-9_]*)(?::[a-zA-Z_][a-zA-Z0-9_]*)?\}/ -
Path param: {name} or {name:type}. Litestar uses the :type suffix as a converter (int, str, uuid, path, float); strip it when exposing the param.
-
PRIMITIVE_TYPE_PATTERNS =
["str", "int", "float", "bool", "bytes", "UUID", "date", "datetime"].map do |t| /\b#{t}\b/ end -
classify_paramruns once per typed handler parameter and rebuilt one PCRE2 pattern per primitive type on every call. -
REQUEST_ATTR_PATTERNS =
(["query_params", "path_params", "headers", "cookies"] of ::String).to_h do |attr| {attr, {/request\.#{attr}\[\s*[rf]?['"]([^'"]+)['"]\s*\]/, /request\.#{attr}\.get\(\s*[rf]?['"]([^'"]+)['"]/}} end -
collect_request_attr_paramsruns twice per handler-body line per attribute; the attribute set is fixed, so precompile the patterns. -
ROUTER_REGEX =
/(#{PYTHON_VAR_NAME_REGEX})\s*=\s*Router\s*\(([^)]*)\)/m -
Router(path="/prefix", route_handlers=[...])
-
TYPED_PATH_PARAM_REGEX =
/\{([a-zA-Z_][a-zA-Z0-9_]*):[a-zA-Z_][a-zA-Z0-9_]*\}/