query#
The user input in the line editor is called Query.
This module provides an objective oriented interface to parse user input string
into machine friendly Query object.
- class zelfred.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 zelfred.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!", 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