Skip to content

comicbox.validate.base

Base validator.

BaseValidator

Base validator.

Source code in comicbox/validate/base.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class BaseValidator:
    """Base validator."""

    def __init__(self, schema_path: Path | str) -> None:
        """Set the full schema path."""
        self.schema_path = SCHEMA_PATH / schema_path

    def validate(self, data: str | bytes | Path) -> None:
        """Validate the data against this validator's schema."""
        raise NotImplementedError

    @staticmethod
    def get_data_str(data: str | bytes | Path) -> str:
        """Get data string from bytes or a path."""
        if isinstance(data, bytes):
            data = data.decode()
        elif isinstance(data, Path):
            data = data.read_text()
        return data

__init__(schema_path)

Set the full schema path.

Source code in comicbox/validate/base.py
11
12
13
def __init__(self, schema_path: Path | str) -> None:
    """Set the full schema path."""
    self.schema_path = SCHEMA_PATH / schema_path

get_data_str(data) staticmethod

Get data string from bytes or a path.

Source code in comicbox/validate/base.py
19
20
21
22
23
24
25
26
@staticmethod
def get_data_str(data: str | bytes | Path) -> str:
    """Get data string from bytes or a path."""
    if isinstance(data, bytes):
        data = data.decode()
    elif isinstance(data, Path):
        data = data.read_text()
    return data

validate(data)

Validate the data against this validator’s schema.

Source code in comicbox/validate/base.py
15
16
17
def validate(self, data: str | bytes | Path) -> None:
    """Validate the data against this validator's schema."""
    raise NotImplementedError