query¶
query utilities.
- class afwf.query.QueryParser(delimiter: list[str] = <factory>)[source]¶
Utility class that can parse string to
Query. Naturally, it is just a tokenizer.- Parameters:
delimiter – list of delimiter strings to split the query string.
Use the
from_delimiter()factory to construct with a single string or a list of strings.- classmethod from_delimiter(delimiter: str | list[str] = ' ') QueryParser[source]¶
Create a
QueryParserfrom a single delimiter string or a list.
- class afwf.query.Query(raw: str, parts: list[str], trimmed_parts: list[str])[source]¶
Structured query object. This is very useful to parse the input of UI handler.
- Parameters:
raw – the raw query string after delimiter normalization.
parts – the parts of query string split by delimiter. For example, if the user input is
"hello world!", thenpartsis["hello", "world!"].trimmed_parts – similar to parts, but each part is white-space stripped. For example, if the user input is
" hello world ", thenpartsis["", "hello", "world", ""], andtrimmed_partsis["hello", "world"].
Usage:
>>> q = Query.from_str(" a b c ") >>> q.trimmed_parts ['a', 'b', 'c'] >>> q.n_trimmed_parts 3
- classmethod from_str(s: str, parser: QueryParser = QueryParser(delimiter=[' '])) Query[source]¶
Parse query from string using the given parser.