Skip to content

SpecStore

dcmspec.spec_store.SpecStore

Bases: ABC

Abstract base class for DICOM specification model storage backends.

Subclasses should implement methods for loading and saving models.

Source code in src/dcmspec/spec_store.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class SpecStore(ABC):
    """Abstract base class for DICOM specification model storage backends.

    Subclasses should implement methods for loading and saving models.
    """

    def __init__(self, logger: Optional[logging.Logger] = None):
        """Initialize the model store with an optional logger.

        Args:
            logger (Optional[logging.Logger]): Logger instance to use. If None, a default logger is created.

        """
        if logger is not None and not isinstance(logger, logging.Logger):
            raise TypeError("logger must be an instance of logging.Logger or None")
        self.logger = logger or logging.getLogger(self.__class__.__name__)

    @abstractmethod
    def load(self, path: str) -> SpecModel:
        """Load a model from the specified path.

        Args:
            path (str): The path to the file or resource to load from.

        Returns:
            SpecModel: The loaded model.

        """
        pass

    @abstractmethod
    def save(self, model: SpecModel, path: str) -> None:
        """Save a model to the specified path.

        Args:
            model (SpecModel): The model to save.
            path (str): The path to the file or resource to save to.

        """
        pass

__init__(logger=None)

Initialize the model store with an optional logger.

PARAMETER DESCRIPTION
logger

Logger instance to use. If None, a default logger is created.

TYPE: Optional[Logger] DEFAULT: None

Source code in src/dcmspec/spec_store.py
17
18
19
20
21
22
23
24
25
26
def __init__(self, logger: Optional[logging.Logger] = None):
    """Initialize the model store with an optional logger.

    Args:
        logger (Optional[logging.Logger]): Logger instance to use. If None, a default logger is created.

    """
    if logger is not None and not isinstance(logger, logging.Logger):
        raise TypeError("logger must be an instance of logging.Logger or None")
    self.logger = logger or logging.getLogger(self.__class__.__name__)

load(path) abstractmethod

Load a model from the specified path.

PARAMETER DESCRIPTION
path

The path to the file or resource to load from.

TYPE: str

RETURNS DESCRIPTION
SpecModel

The loaded model.

TYPE: SpecModel

Source code in src/dcmspec/spec_store.py
28
29
30
31
32
33
34
35
36
37
38
39
@abstractmethod
def load(self, path: str) -> SpecModel:
    """Load a model from the specified path.

    Args:
        path (str): The path to the file or resource to load from.

    Returns:
        SpecModel: The loaded model.

    """
    pass

save(model, path) abstractmethod

Save a model to the specified path.

PARAMETER DESCRIPTION
model

The model to save.

TYPE: SpecModel

path

The path to the file or resource to save to.

TYPE: str

Source code in src/dcmspec/spec_store.py
41
42
43
44
45
46
47
48
49
50
@abstractmethod
def save(self, model: SpecModel, path: str) -> None:
    """Save a model to the specified path.

    Args:
        model (SpecModel): The model to save.
        path (str): The path to the file or resource to save to.

    """
    pass