DictContextHandlerMixin#

class tollan.pipeline.DictContextHandlerMixin[source]#

Bases: ContextHandlerMixinBase, Generic

A helper class to access context stored in dict.

Methods Summary

get_context(data)

Get context from dictionary.

get_context_dict(data)

Get dictionary storing contexts.

has_context(data)

Check if context key exists in dictionary.

set_context(data, context_obj)

Set context in dictionary.

Methods Documentation

classmethod get_context(data: Any) ContextT[source]#

Get context from dictionary.

Validates and converts raw context data to proper type if needed.

Parameters:

data (Any) – Dictionary containing context

Returns:

The context object (validated and typed)

Return type:

ContextT

classmethod get_context_dict(data: Any) dict[KeyT, ContextT][source]#

Get dictionary storing contexts.

Parameters:

data (Any) – Data object (should be a dict)

Returns:

Dictionary containing contexts keyed by handler name

Return type:

dict[KeyT, ContextT]

classmethod has_context(data: Any) bool[source]#

Check if context key exists in dictionary.

Parameters:

data (Any) – Dictionary to check

Returns:

True if context key exists, False otherwise

Return type:

bool

classmethod set_context(data: Any, context_obj: ContextT) ContextT[source]#

Set context in dictionary.

Parameters:
  • data (Any) – Dictionary to store context in

  • context_obj (ContextT) – Context object to store

Returns:

The stored context object

Return type:

ContextT