query#
query utilities.
- class afwf.query.QueryParser(delimiter: Union[str, List[str]] = ' ')[source]#
Utility class that can parse string to
Query
. Naturally, it is just a tokenizer.- Parameters:
delimiter – the delimiter to split the query string.
- 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:
parts – the parts of query string split by delimiter. For example, if the user input is
"hello world!"
, thenparts
is["hello", "world!"]
.trimmed_parts – similar to parts, but each part is white-space stripped For example, if the user input is
" hello world "
, thenparts
is["", "hello", "world", ""]
, andtrimmed_parts
is["hello", "world"]
.
Usage:
>>> q = Query.from_str(" a b c ") >>> q.trimmed_parts ['a', 'b', 'c'] >>> q.n_trimmed_parts 3