API Documentation
- class filters.base.BaseFilter
Base functionality for all Filters, macros, etc.
- CODE_EXCEPTION = 'exception'
- property harness: FilterHarness | None
Returns the harness in which this filter is running (if applicable).
- property parent: BaseFilter[Any] | None
Returns the parent Filter.
- classmethod resolve(the_filter: BaseFilter | Callable[[], BaseFilter] | None, parent: BaseFilter[Any] | None = None, key: str | None = None) BaseFilter
Converts a filter-compatible value into a consistent type.
- exception filters.base.BaseFilterError(filter_: BaseFilter[Any], value: Any, code: str, context: Mapping[str, Any] | None = None)
Base class for errors that occur when filtering values.
- Parameters:
filter – The filter that raised the error.
value – The value provided to the filter.
code – Corresponding error code. Should match one of the keys in
filter_.templates
.context – Additional values that could be useful for troubleshooting cases where the filter is incorrectly rejecting values.
- class filters.base.FilterChain(start_filter: BaseFilter | None = None)
Allows chaining multiple filters together so that they are treated as a single filter.
- exception filters.base.FilterError(filter_: BaseFilter[Any], value: Any, code: str, context: Mapping[str, Any] | None = None, template_vars: Mapping[str, str] | None = None)
Indicates that a given value could not be filtered because it failed validation or was otherwise invalid, rather than because of a problem with the filter code itself.
Think of a
FilterError
like an HTTP 400 response.- Parameters:
filter – The filter that raised the error.
value – The value provided to the filter.
code – Corresponding error code. Should match one of the keys in
filter_.templates
.context – Additional values that could be useful for troubleshooting cases where the filter is incorrectly rejecting values.
template_vars – If
reason
contains interpolation placeholders, this parameter contains the corresponding values to insert.
- class filters.base.FilterHarness
Runs filters within a harness, so that it can catch and handle errors.
- handle_exception(e: UncaughtException) Any
Handles an uncaught exception that occurred when the filter ran.
- Returns:
Replacement value that the filter should return (usually
None
).
- abstract handle_filter_error(e: BaseFilterError) Any
Handles a filter error (i.e. invalid incoming value).
- Returns:
Replacement value that the filter should return (usually
None
).
- class filters.base.NoOp
Filter that does nothing, used when you need a placeholder Filter in a FilterChain.
- class filters.base.Type(allowed_types: type | tuple[type, ...], allow_subclass: bool = True)
Checks the type of the incoming value.
- Parameters:
allowed_types – The type (or types) that incoming values are allowed to have.
allow_subclass – Whether to allow subclasses when checking for type matches.
- CODE_WRONG_TYPE = 'wrong_type'
- exception filters.base.UncaughtException(filter_: BaseFilter[Any], value: Any, e: Exception, context: Mapping[str, Any] | None = None)
Indicates that a given value could not be filtered because of a problem with the filter code itself.
Thin of
UncaughtException
like an HTTP 500 response.- Parameters:
filter – The filter that raised the error.
value – The value provided to the filter.
e – The exception object.
context – Additional values that could be useful for troubleshooting the error.