Skip to content

trestle_base_model

trestle.core.trestle_base_model ¤

Trestle Base Model.

Attributes¤

Model = TypeVar('Model', bound='BaseModel') module-attribute ¤

Classes¤

TrestleBaseModel ¤

Bases: BaseModel

Trestle Base Model. Serves as wrapper around BaseModel for overriding methods.

Source code in trestle/core/trestle_base_model.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class TrestleBaseModel(BaseModel):
    """Trestle Base Model. Serves as wrapper around BaseModel for overriding methods."""

    @classmethod
    def parse_obj(cls: Type['Model'], obj: Any) -> 'Model':
        """Parse object to the given class."""
        try:
            return super().parse_obj(obj)
        except ValidationError as e:
            # check if failed due to the wrong OSCAL version:
            oscal_version_error = False
            for err in e.errors():
                for field in err['loc']:
                    if field == 'oscal-version':
                        message = err['msg']
                        oscal_version_error = True
                        break
            if oscal_version_error:
                raise TrestleError(f'{message}')
            else:
                raise
Functions¤
parse_obj(obj) classmethod ¤

Parse object to the given class.

Source code in trestle/core/trestle_base_model.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@classmethod
def parse_obj(cls: Type['Model'], obj: Any) -> 'Model':
    """Parse object to the given class."""
    try:
        return super().parse_obj(obj)
    except ValidationError as e:
        # check if failed due to the wrong OSCAL version:
        oscal_version_error = False
        for err in e.errors():
            for field in err['loc']:
                if field == 'oscal-version':
                    message = err['msg']
                    oscal_version_error = True
                    break
        if oscal_version_error:
            raise TrestleError(f'{message}')
        else:
            raise

handler: python