mirror of
https://github.com/elicpeter/nyx.git
synced 2026-06-12 19:55:14 +02:00
[pitboss] sweep after phase 12: 3 deferred items resolved
This commit is contained in:
parent
df9fd2bb17
commit
9ed837be9b
5 changed files with 158 additions and 153 deletions
|
|
@ -17,7 +17,8 @@ use crate::symbol::Lang;
|
|||
use tree_sitter::Node;
|
||||
|
||||
use super::python_routes::{
|
||||
bind_path_params, find_python_function, function_formal_names, source_imports_flask,
|
||||
bind_path_params, find_python_function, first_string_arg, function_formal_names, methods_kwarg,
|
||||
source_imports_flask,
|
||||
};
|
||||
|
||||
pub struct PythonFlaskAdapter;
|
||||
|
|
@ -90,48 +91,6 @@ fn decorator_route_shape(decorator: Node<'_>, bytes: &[u8]) -> Option<(HttpMetho
|
|||
Some((method, path))
|
||||
}
|
||||
|
||||
fn first_string_arg(args: Node<'_>, bytes: &[u8]) -> Option<String> {
|
||||
let mut cur = args.walk();
|
||||
for c in args.named_children(&mut cur) {
|
||||
if c.kind() == "string" {
|
||||
return Some(strip_string_quotes(c.utf8_text(bytes).ok()?).to_owned());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn strip_string_quotes(raw: &str) -> &str {
|
||||
let t = raw.trim();
|
||||
let t = t.strip_prefix("b").unwrap_or(t);
|
||||
let t = t.strip_prefix("r").unwrap_or(t);
|
||||
let t = t.strip_prefix("u").unwrap_or(t);
|
||||
t.trim_matches(['\'', '"'])
|
||||
}
|
||||
|
||||
fn methods_kwarg(args: Node<'_>, bytes: &[u8]) -> Option<HttpMethod> {
|
||||
let mut cur = args.walk();
|
||||
for arg in args.children(&mut cur) {
|
||||
if arg.kind() != "keyword_argument" {
|
||||
continue;
|
||||
}
|
||||
let name = arg.child_by_field_name("name")?.utf8_text(bytes).ok()?;
|
||||
if name != "methods" {
|
||||
continue;
|
||||
}
|
||||
let value = arg.child_by_field_name("value")?;
|
||||
let mut vc = value.walk();
|
||||
for child in value.named_children(&mut vc) {
|
||||
if child.kind() == "string" {
|
||||
let raw = strip_string_quotes(child.utf8_text(bytes).ok()?);
|
||||
if let Some(m) = HttpMethod::from_ident(raw) {
|
||||
return Some(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
impl FrameworkAdapter for PythonFlaskAdapter {
|
||||
fn name(&self) -> &'static str {
|
||||
ADAPTER_NAME
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue