Skip to content

core

Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.

FoSpy.core

Synthesis

Bases: FileBlock

Represents a Synthesis loaded from a FOS file.

Source code in FoSpy/blocks/synthesis.py
class Synthesis(FileBlock):
    """
    Represents a Synthesis loaded from a FOS file.
    """

    def insert_material(self, mat, idx=-1):
        # placeholder. modify for insertion at idx
        self.materials.append(mat)

    def insert_treatment(self, treat, idx=-1):
        # placeholder. modify for insertion at idx
        self.treatments.append(treat)

insert_material

insert_material(mat, idx=-1)
Source code in FoSpy/blocks/synthesis.py
def insert_material(self, mat, idx=-1):
    # placeholder. modify for insertion at idx
    self.materials.append(mat)

insert_treatment

insert_treatment(treat, idx=-1)
Source code in FoSpy/blocks/synthesis.py
def insert_treatment(self, treat, idx=-1):
    # placeholder. modify for insertion at idx
    self.treatments.append(treat)

TemplateBlock

Bases: SingleBlock

Source code in FoSpy/blocks/template.py
class TemplateBlock(SingleBlock):
    def __init__(self, blockDict, _dispatched=False):
        self._full_class = None
        super().__init__(blockDict, _dispatched=_dispatched)

    def fill(self,incomplete=False,**kwargs):
        if not self._full_class is not None and issubclass(self._full_class, SingleBlock):
            raise TypeError("A Template Block must be initialized from an existing class in order to be filled.")


        serial = self.serialize(keepListType=True)
        serial.pop("template_name",None)
        for kw, arg in kwargs.items():
            serial[kw] = arg

        if incomplete:
            return self._full_class.reflex(serialize=False,**serial)
        return self._full_class.dispatch_subclass(serial)

    def serialize(self,keepListType=False, shallow=False, clean=False):
        from ..parsing.validation import required_keys
        from ..parsing.format_fos import format_field
        required = self._full_class.build_req_validators()
        required.pop('ext',None)
        serial = super().serialize(keepListType=keepListType, shallow=shallow, clean=clean)

        out = {"template_name":serial.pop("template_name","")}
        for key,validator in required.items():
            if isinstance(validator,type):
                if issubclass(validator,TemplateBlock):
                    val = serial.pop(key, validator.reflex())
                elif issubclass(validator, TemplateList):
                    val = serial.pop(key, validator([]).serialize())
                else:
                    val = serial.pop(key, TemplateField("").serialize())
            else:
                val = serial.pop(key, TemplateField("").serialize())
            out[key] = val

        for key in serial:
            out[key] = serial[key]

        return out

_full_class instance-attribute

_full_class = None

__init__

__init__(blockDict, _dispatched=False)
Source code in FoSpy/blocks/template.py
def __init__(self, blockDict, _dispatched=False):
    self._full_class = None
    super().__init__(blockDict, _dispatched=_dispatched)

fill

fill(incomplete=False, **kwargs)
Source code in FoSpy/blocks/template.py
def fill(self,incomplete=False,**kwargs):
    if not self._full_class is not None and issubclass(self._full_class, SingleBlock):
        raise TypeError("A Template Block must be initialized from an existing class in order to be filled.")


    serial = self.serialize(keepListType=True)
    serial.pop("template_name",None)
    for kw, arg in kwargs.items():
        serial[kw] = arg

    if incomplete:
        return self._full_class.reflex(serialize=False,**serial)
    return self._full_class.dispatch_subclass(serial)

serialize

serialize(keepListType=False, shallow=False, clean=False)
Source code in FoSpy/blocks/template.py
def serialize(self,keepListType=False, shallow=False, clean=False):
    from ..parsing.validation import required_keys
    from ..parsing.format_fos import format_field
    required = self._full_class.build_req_validators()
    required.pop('ext',None)
    serial = super().serialize(keepListType=keepListType, shallow=shallow, clean=clean)

    out = {"template_name":serial.pop("template_name","")}
    for key,validator in required.items():
        if isinstance(validator,type):
            if issubclass(validator,TemplateBlock):
                val = serial.pop(key, validator.reflex())
            elif issubclass(validator, TemplateList):
                val = serial.pop(key, validator([]).serialize())
            else:
                val = serial.pop(key, TemplateField("").serialize())
        else:
            val = serial.pop(key, TemplateField("").serialize())
        out[key] = val

    for key in serial:
        out[key] = serial[key]

    return out