httk.optimade.backend.handlers

Re-exports of the generic OPTIMADE filter handlers.

The handler tables and generic handlers are implemented in httk.data.optimade_query and exposed here under the httk.optimade.backend.handlers namespace.

The handlers raise FilterTranslationError (which carries a neutral failure category instead of HTTP semantics); translate_filter() wraps it into TranslatorError with the appropriate HTTP status. simple_property_handlers() takes a plain property-name -> fulltype mapping as its third argument. A 'HAS' handler is called as handler(property, ops, values, search_variable, has_type) and returns a plain SearchExpression; the caller applies NOT as ~, and the backend determines whether the resulting expression also needs post-filter evaluation.

Attributes

HandlerTable

Per-property translation callables, keyed by property name.

invert_op

Functions

constant_comparison_handler(...)

Fold val1 <op> val2 (both constants) to a constant expression.

constant_set_handler(→ httk.data.query.SearchExpression)

constant_stringmatching_handler(...)

Fold val1 <CONTAINS|STARTS|ENDS> val2 (both constants) to a constant expression.

false_handler(→ httk.data.query.SearchExpression)

A constant-false expression over search_variable.

known_unknown_handler(→ httk.data.query.SearchExpression)

number_handler(→ httk.data.query.SearchExpression)

set_handler(→ httk.data.query.SearchExpression)

Translate one HAS family node over the list-valued field entry.

simple_property_handlers(→ dict[str, ...)

Build a filter handler table for an entry type from a property-key map.

string_handler(→ httk.data.query.SearchExpression)

stringmatching_handler(→ httk.data.query.SearchExpression)

Translate CONTAINS/STARTS/ENDS onto the field's literal matchers.

timestamp_handler(→ httk.data.query.SearchExpression)

true_handler(→ httk.data.query.SearchExpression)

A constant-true expression over search_variable.

unknown_comparison_handler(...)

unknown_has_handler(→ httk.data.query.SearchExpression)

unknown_length_handler(→ httk.data.query.SearchExpression)

unknown_stringmatching_handler(...)

unknown_unknown_handler(→ httk.data.query.SearchExpression)

Module Contents

type httk.optimade.backend.handlers.HandlerTable = Mapping[str, Mapping[str, Callable[..., Any]]][source]

Per-property translation callables, keyed by property name.

The inner mapping’s keys name the filter-operation families: 'comparison' (=, !=, <, <=, >, >=), 'stringmatching' (CONTAINS/STARTS/ENDS), 'HAS' (the set operations), 'length' (LENGTH), and 'unknown' (IS KNOWN/IS UNKNOWN). A 'HAS' handler is called as handler(property, ops, values, search_variable, has_type) and returns a plain SearchExpression. The caller applies NOT as ~; handlers do not receive negation state or report post-filter placement. Dotted '<type>.id' entries provide relationship-id filtering (see relationship_id_handler()).

httk.optimade.backend.handlers.constant_comparison_handler(val1: Any, op: str, val2: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

Fold val1 <op> val2 (both constants) to a constant expression.

val1 is the value being compared and val2 the filter constant, the same left-to-right convention as constant_set_handler(); translate_filter_ast() has already inverted op for constant-on-the-left filters, so this ordering is the filter’s own.

httk.optimade.backend.handlers.constant_set_handler(val1: Any, ops: Any, val2: Any, has_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.constant_stringmatching_handler(val1: Any, val2: Any, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

Fold val1 <CONTAINS|STARTS|ENDS> val2 (both constants) to a constant expression.

val1 is the value being matched and val2 the filter text, the same left-to-right convention as constant_set_handler().

httk.optimade.backend.handlers.false_handler(search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

A constant-false expression over search_variable.

httk.optimade.backend.handlers.invert_op[source]
httk.optimade.backend.handlers.known_unknown_handler(entry: str, search_variable: httk.data.query.SearchVariable, unknown_type: str) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.number_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.set_handler(entry: str, ops: Any, values: Any, has_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

Translate one HAS family node over the list-valued field entry.

HAS ALL becomes a conjunction of one-value has_any calls (each constraining an independently joined child row); HAS ANY and HAS ONLY map straight onto has_any/has_only. Negation is not the handler’s business: a surrounding NOT inverts the returned expression, and the backend’s ~ knows how to negate a set predicate.

httk.optimade.backend.handlers.simple_property_handlers(entry_type: str, property_keys: collections.abc.Mapping[str, str], property_fulltypes: collections.abc.Mapping[str, str]) dict[str, collections.abc.Mapping[str, collections.abc.Callable[Ellipsis, Any]]][source]

Build a filter handler table for an entry type from a property-key map.

Always provides the standard id (matched against the __id field) and type (a constant equal to entry_type) handlers. For every property named in property_keys (which maps property names to backend field names), handlers are generated from the property’s fulltype in property_fulltypes (default "string"): string properties get comparison and stringmatching handlers; integer and float properties get a numeric comparison handler; list of ... properties get a HAS (set membership) handler. Every generated property also gets a known unknown handler.

httk.optimade.backend.handlers.string_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.stringmatching_handler(entry: str, value: str, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

Translate CONTAINS/STARTS/ENDS onto the field’s literal matchers.

The filter constant is passed through unescaped: the search-field protocol’s contains/startswith/endswith take literal text, so % and _ match themselves (as OPTIMADE requires). Any escaping a backend’s pattern language needs is that backend’s own business.

httk.optimade.backend.handlers.timestamp_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.true_handler(search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]

A constant-true expression over search_variable.

httk.optimade.backend.handlers.unknown_comparison_handler(entry: str, ops: Any, values: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.unknown_has_handler(entry: str, op: Any, value: Any, search_variable: httk.data.query.SearchVariable, has_type: str) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.unknown_length_handler(entry: str, op: str, value: Any, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.unknown_stringmatching_handler(entry: str, values: Any, stringmatching_type: str, search_variable: httk.data.query.SearchVariable) httk.data.query.SearchExpression[source]
httk.optimade.backend.handlers.unknown_unknown_handler(entry: str, search_variable: httk.data.query.SearchVariable, unknown_type: str) httk.data.query.SearchExpression[source]