khard.query

Queries to match against contacts

Module Contents

class khard.query.Query

A query to match against strings, lists of strings and CarddavObjects

abstract match(self, thing: Union[str, carddav_object.CarddavObject])

Match the self query against the given thing

abstract get_term(self)

Extract the search terms from a query.

__and__(self, other: Query)

Combine two queries with AND

__or__(self, other: Query)

Combine two queries with OR

__eq__(self, other: object)

A generic equality for all query types without parameters

__hash__(self)

A generic hashing implementation for all queries without parameters

class khard.query.NullQuery

Bases: khard.query.Query

The null-query, it matches nothing.

match(self, thing: Union[str, carddav_object.CarddavObject])
get_term(self)
__str__(self)
class khard.query.AnyQuery

Bases: khard.query.Query

The match-anything-query, it always matches.

match(self, thing: Union[str, carddav_object.CarddavObject])
get_term(self)
__hash__(self)
__str__(self)
class khard.query.TermQuery(term: str)

Bases: khard.query.Query

A query to match an object against a fixed string.

match(self, thing: Union[str, carddav_object.CarddavObject])
get_term(self)
__eq__(self, other: object)
__hash__(self)
__str__(self)
class khard.query.FieldQuery(field: str, value: str)

Bases: khard.query.TermQuery

A query to match against a certain field in a carddav object.

match(self, thing: Union[str, carddav_object.CarddavObject])
_match_union(self, value: Union[str, datetime, List, Dict[str, Any]])
__eq__(self, other: object)
__hash__(self)
__str__(self)
class khard.query.AndQuery(first: Query, second: Query, *queries: Query)

Bases: khard.query.Query

A query to combine multible queries with “and”.

match(self, thing: Union[str, carddav_object.CarddavObject])
get_term(self)
__eq__(self, other: object)
__hash__(self)
static reduce(queries: List[Query], start: Optional[Query] = None)
__str__(self)
class khard.query.OrQuery(first: Query, second: Query, *queries: Query)

Bases: khard.query.Query

A query to combine multible queries with “or”.

match(self, thing: Union[str, carddav_object.CarddavObject])
get_term(self)
__eq__(self, other: object)
__hash__(self)
static reduce(queries: List[Query], start: Optional[Query] = None)
__str__(self)
class khard.query.NameQuery(term: str)

Bases: khard.query.TermQuery

special query to match any kind of name field of a vcard

match(self, thing: Union[str, carddav_object.CarddavObject])
__eq__(self, other: object)
__hash__(self)
__str__(self)
khard.query.parse(string: str) → Union[TermQuery, FieldQuery]

Parse a string into a query object

The input string interpreted as a FieldQuery if it starts with a valid property name of the CarddavObject class, followed by a colon and an arbitrary search term. Otherwise it is interpreted as a TermQuery.

Parameters

string – a string to parse into a query

Returns

a FieldQuery if the string contains a valid field specifier, a TermQuery otherwise