Source code for docp_parsers.parsers.putilities

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
:Purpose:   This module provides parser-specific utility functions for
            the project.

:Platform:  Linux/Windows | Python 3.11+
:Developer: J Berendt
:Email:     development@s3dev.uk

:Comments:  n/a

"""

from docp_core.utilities import utilities
# locals
try:
    from .pdfparser import PDFParser
    from .pptxparser import PPTXParser
except ImportError:
    from docp_parsers.parsers.pdfparser import PDFParser
    from docp_parsers.parsers.pptxparser import PPTXParser


[docs] class ParserUtilities: """Parser-based (cross-project) utility functions."""
[docs] def get_parser(self, path: str) -> PDFParser | PPTXParser: """Return the appropriate parser for the file type. Args: path (str): Full path to the file to be tested. Returns: PDFParser | PPTXParser: The appropriate parser for the file, given the *file signature*; this test is not file extension based. """ if utilities.ispdf(path=path): return PDFParser if utilities.iszip(path=path): return PPTXParser raise NotImplementedError('A parser is not available for: os.path.basename(path)')
putilities = ParserUtilities()