khard.query

Queries to match against contacts

Module Contents

Classes

Query

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

NullQuery

The null-query, it matches nothing.

AnyQuery

The match-anything-query, it always matches.

TermQuery

A query to match an object against a fixed string.

FieldQuery

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

AndQuery

A query to combine multible queries with “and”.

OrQuery

A query to combine multible queries with “or”.

NameQuery

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

Functions

parse(string: str) → Union[TermQuery, FieldQuery]

Parse a string into a query object

class khard.query.Query

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

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

Match the self query against the given thing

abstract get_term(self)Optional[str]

Extract the search terms from a query.

__and__(self, other: Query)Query

Combine two queries with AND

__or__(self, other: Query)Query

Combine two queries with OR

__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

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])bool

Match the self query against the given thing

get_term(self)None

Extract the search terms from a query.

__str__(self)str

Return 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])bool

Match the self query against the given thing

get_term(self)str

Extract the search terms from a query.

__hash__(self)int

A generic hashing implementation for all queries without parameters

__str__(self)str

Return 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])bool

Match the self query against the given thing

get_term(self)str

Extract the search terms from a query.

__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

A generic hashing implementation for all queries without parameters

__str__(self)str

Return 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])bool

Match the self query against the given thing

_match_union(self, value: Union[str, datetime, List, Dict[str, Any]])bool
__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

A generic hashing implementation for all queries without parameters

__str__(self)str

Return 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])bool

Match the self query against the given thing

get_term(self)Optional[str]

Extract the search terms from a query.

__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

A generic hashing implementation for all queries without parameters

static reduce(queries: List[Query], start: Optional[Query] = None)Query
__str__(self)str

Return 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])bool

Match the self query against the given thing

get_term(self)Optional[str]

Extract the search terms from a query.

__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

A generic hashing implementation for all queries without parameters

static reduce(queries: List[Query], start: Optional[Query] = None)Query
__str__(self)str

Return 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])bool

Match the self query against the given thing

__eq__(self, other: object)bool

A generic equality for all query types without parameters

__hash__(self)int

A generic hashing implementation for all queries without parameters

__str__(self)str

Return 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