Skip to content

SpecParser

dcmspec.spec_parser.SpecParser

Bases: ABC

Abstract base class for DICOM specification parsers.

Handles DICOM specifications in various in-memory formats (e.g., DOM for XHTML/XML, CSV). Subclasses must implement the parse method to parse the specification content and build a structured model.

Source code in src/dcmspec/spec_parser.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
class SpecParser(ABC):
    """Abstract base class for DICOM specification parsers.

    Handles DICOM specifications in various in-memory formats (e.g., DOM for XHTML/XML, CSV).
    Subclasses must implement the `parse` method to parse the specification content and build a structured model.
    """

    def __init__(self, logger: Optional[logging.Logger] = None):
        """Initialize the DICOM Specification parser 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 parse(self, *args, **kwargs) -> Tuple[Node, Node]:
        """Parse the DICOM specification and return metadata and attribute tree nodes.

        Returns:
            Tuple[Node, Node]: The metadata node and the content node.

        """
        pass

__init__(logger=None)

Initialize the DICOM Specification parser 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_parser.py
18
19
20
21
22
23
24
25
26
27
def __init__(self, logger: Optional[logging.Logger] = None):
    """Initialize the DICOM Specification parser 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__)

parse(*args, **kwargs) abstractmethod

Parse the DICOM specification and return metadata and attribute tree nodes.

RETURNS DESCRIPTION
Tuple[Node, Node]

Tuple[Node, Node]: The metadata node and the content node.

Source code in src/dcmspec/spec_parser.py
29
30
31
32
33
34
35
36
37
@abstractmethod
def parse(self, *args, **kwargs) -> Tuple[Node, Node]:
    """Parse the DICOM specification and return metadata and attribute tree nodes.

    Returns:
        Tuple[Node, Node]: The metadata node and the content node.

    """
    pass