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.

parse(s: str) Query[source]#

Convert string query to structured Query object.

Parameters:

s – a 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!", then parts is ["hello", "world!"].

  • trimmed_parts – similar to parts, but each part is white-space stripped For example, if the user input is " hello world ", then parts is ["", "hello", "world", ""], and trimmed_parts is ["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=<afwf.query.QueryParser object>)[source]#

Parse query from string using the given parser.

property n_parts: int#

The number of items in the parts.

property n_trimmed_parts: int#

The number of items in the trimmed_parts.