colander_data_converter.base.common

class colander_data_converter.base.common.BasePydanticEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Base class for creating Pydantic-compatible enums with flexible member resolution.

This class extends Python’s Enum to provide seamless integration with Pydantic models. It allows enum members to be resolved from various input types including codes, enum members, member values, or dictionary representations.

The enum members are expected to have a code attribute for string-based lookup and support Pydantic model validation for dictionary inputs.

classmethod __get_pydantic_core_schema__(_source, _handler)[source]

Define the Pydantic core schema for enum validation and serialization.

This method configures how Pydantic should validate and serialize enum instances. It sets up flexible input validation that accepts multiple input formats and serializes enum members using their code attribute.

Parameters:
  • _source (Any) – The source type being processed (unused)

  • _handler (GetCoreSchemaHandler) – Core schema handler from Pydantic (unused)

Returns:

A Pydantic core schema that handles JSON and Python validation

with custom serialization to the member’s code attribute

Return type:

core_schema

class colander_data_converter.base.common.Level[source]

Bases: BaseModel

A Pydantic model representing a hierarchical level with ordering capabilities.

This class defines a level with a code, name, ordering value, and optional description. It provides comparison operators based on the ordering_value field, allowing levels to be sorted and compared in a meaningful hierarchy.

Example

>>> level1 = Level(code="LOW", name="Low Priority", ordering_value=10)
>>> level2 = Level(code="HIGH", name="High Priority", ordering_value=20)
>>> level1 < level2
True
>>> str(level1)
'Low Priority'
Fields:
field code: str [Required]
field name: str [Required]
field ordering_value: int [Required]
field description: str | None = None
ser_model()[source]
Return type:

str

class colander_data_converter.base.common.Singleton[source]

Bases: type

Metaclass implementation of the Singleton design pattern.

This metaclass ensures that only one instance of a class can exist at any time. Subsequent instantiation attempts will return the existing instance rather than creating a new one.

Note

The singleton instance is created lazily on first instantiation and persists for the lifetime of the Python process.

Classes using this metaclass should be designed to handle reinitialization gracefully, as __init__ may be called multiple times on the same instance.

Example

>>> class Configuration(metaclass=Singleton):
...     def __init__(self, value=None):
...         if not hasattr(self, 'initialized'):
...             self.value = value
...             self.initialized = True
...
>>> config1 = Configuration(value=42)
>>> config2 = Configuration(value=99)
>>> print(config1 is config2)  # Both variables point to the same instance
True
>>> print(config1.value)  # The value from first initialization
42
__call__(*args, **kwargs)[source]

Control instance creation to ensure singleton behavior.

Parameters:
  • cls (type) – The class being instantiated

  • *args – Positional arguments for class initialization

  • **kwargs – Keyword arguments for class initialization

Returns:

The singleton instance of the class

Return type:

type

Note

If an instance already exists, __init__ will still be called with the provided arguments, but no new instance is created.

class colander_data_converter.base.common.TlpPapLevel(*values)[source]

Bases: BasePydanticEnum

Traffic Light Protocol (TLP) and Permissible Actions Protocol (PAP) classification levels.

The TLP is a set of designations used to ensure that sensitive information is shared with the appropriate audience. PAP complements TLP by providing guidance on what actions can be taken with the information.

Note

See FIRST TLP Standard for complete specification.

Example

>>> level = TlpPapLevel.RED
>>> print(level)
RED
>>> str(level) == "RED"
True
classmethod by_name(name)[source]

Retrieve a TLP/PAP level enum member by its name.

This method provides a convenient way to access enum members using their string names (e.g., “RED”, “AMBER”, “GREEN”, “WHITE”).

Parameters:

name (str) – The name of the TLP/PAP level to retrieve. Must match exactly one of the enum member names: “RED”, “AMBER”, “GREEN”, or “WHITE”.

Returns:

The Level object associated with the specified enum member

Return type:

Level

Raises:

AttributeError – If the provided name does not correspond to any enum member

Example

>>> level = TlpPapLevel.by_name("RED")
>>> print(level.name)
RED
>>> print(level.value.ordering_value)
40
__str__()[source]

Return the string representation of the TLP level.

Returns:

The TLP level value as a string

Return type:

str

AMBER = Level(code='AMBER', name='AMBER', ordering_value=30, description=None)

Sensitive information, limited to a defined group.

GREEN = Level(code='GREEN', name='GREEN', ordering_value=20, description=None)

Information that can be shared within the community.

RED = Level(code='RED', name='RED', ordering_value=40, description=None)

Highly sensitive information, restricted to specific recipients.

WHITE = Level(code='WHITE', name='WHITE', ordering_value=10, description=None)

Information that can be shared publicly.