Python marshmallow.pre_load() Examples

The following are 6 code examples of marshmallow.pre_load(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module marshmallow , or try the search function .
Example #1
Source File: invitation.py    From aries-cloudagent-python with Apache License 2.0 5 votes vote down vote up
def pre_load(self, data, **kwargs):
        """Pre load hook."""
        data["service_dids"] = []
        data["service_blocks"] = []

        for service_entry in data["service"]:
            if type(service_entry) is str:
                data["service_dids"].append(service_entry)
            if type(service_entry) is dict:
                data["service_blocks"].append(service_entry)

        del data["service"]

        return data 
Example #2
Source File: schemas.py    From sota-extractor with Apache License 2.0 5 votes vote down vote up
def pre_load(self, data, **kwargs):
        data = deepcopy(data)
        if "dataset" in data:
            data["name"] = data["dataset"]
            data["is_subdataset"] = False
            del data["dataset"]
        elif "subdataset" in data:
            data["name"] = data["subdataset"]
            data["is_subdataset"] = True
            del data["subdataset"]
        else:
            data["name"] = ""
            data["is_subdataset"] = False
        return data 
Example #3
Source File: schemas.py    From incubator-superset with Apache License 2.0 5 votes vote down vote up
def pre_load(self, data: Dict[str, Any]) -> None:  # pylint: disable=no-self-use
        if data.get("slug"):
            data["slug"] = data["slug"].strip()
            data["slug"] = data["slug"].replace(" ", "-")
            data["slug"] = re.sub(r"[^\w\-]+", "", data["slug"]) 
Example #4
Source File: base_schemas.py    From incubator-superset with Apache License 2.0 5 votes vote down vote up
def pre_load(self, data: Dict[Any, Any]) -> None:
        # if PUT request don't set owners to empty list
        if not self.instance:
            data[self.owners_field_name] = data.get(self.owners_field_name, []) 
Example #5
Source File: invitation.py    From aries-cloudagent-python with Apache License 2.0 4 votes vote down vote up
def __init__(
        self,
        # _id: str = None,
        *,
        comment: str = None,
        label: str = None,
        handshake_protocols: Sequence[Text] = None,
        request_attach: Sequence[AttachDecorator] = None,
        # When loading, we sort service in the two lists
        service: Sequence[Union[Service, Text]] = [],
        service_blocks: Sequence[Service] = [],
        service_dids: Sequence[Text] = [],
        **kwargs,
    ):
        """
        Initialize invitation object.

        Args:
            request_attach: request attachments

        """
        # super().__init__(_id=_id, **kwargs)
        super().__init__(**kwargs)
        self.label = label
        self.handshake_protocols = (
            list(handshake_protocols) if handshake_protocols else []
        )
        self.request_attach = list(request_attach) if request_attach else []

        # In order to accept and validate both string entries and
        # dict block entries, we include both in schema and manipulate
        # data in pre_load and post_dump
        self.service_blocks = list(service_blocks) if service_blocks else []
        self.service_dids = list(service_dids) if service_dids else []

        # In the case of loading, we need to sort
        # the entries into relevant lists for schema validation
        for s in service:
            if type(s) is Service:
                self.service_blocks.append(s)
            if type(s) is str:
                self.service_dids.append(s) 
Example #6
Source File: marshmallow.py    From flask-unchained with MIT License 4 votes vote down vote up
def __init__(self):
        self.Serializer = flask_ma.Schema
        self.ModelSerializer = ModelSerializer

        # alias marshmallow stuffs
        self.pre_load = ma.pre_load
        self.post_load = ma.post_load
        self.pre_dump = ma.pre_dump
        self.post_dump = ma.post_dump
        self.validates = ma.validates
        self.validates_schema = ma.validates_schema
        self.ValidationError = ma.ValidationError

        # alias marshmallow fields
        self.Bool = ma.fields.Bool
        self.Boolean = ma.fields.Boolean
        self.Constant = ma.fields.Constant
        self.Date = ma.fields.Date
        self.DateTime = ma.fields.DateTime
        self.NaiveDateTime = ma.fields.NaiveDateTime
        self.AwareDateTime = ma.fields.AwareDateTime
        self.Decimal = ma.fields.Decimal
        self.Dict = ma.fields.Dict
        self.Email = ma.fields.Email
        self.Field = ma.fields.Field
        self.Float = ma.fields.Float
        self.Function = ma.fields.Function
        self.Int = ma.fields.Int
        self.Integer = ma.fields.Integer
        self.List = ma.fields.List
        self.Mapping = ma.fields.Mapping
        self.Method = ma.fields.Method
        self.Nested = ma.fields.Nested
        self.Number = ma.fields.Number
        self.Pluck = ma.fields.Pluck
        self.Raw = ma.fields.Raw
        self.Str = ma.fields.Str
        self.String = ma.fields.String
        self.Time = ma.fields.Time
        self.TimeDelta = ma.fields.TimeDelta
        self.Tuple = ma.fields.Tuple
        self.UUID = ma.fields.UUID
        self.Url = ma.fields.Url
        self.URL = ma.fields.URL

        # alias flask_marshmallow fields
        self.AbsoluteUrlFor = flask_ma.fields.AbsoluteUrlFor
        self.AbsoluteURLFor = flask_ma.fields.AbsoluteURLFor
        self.UrlFor = flask_ma.fields.UrlFor
        self.URLFor = flask_ma.fields.URLFor
        self.Hyperlinks = flask_ma.fields.Hyperlinks
        self.HyperlinkRelated = HyperlinkRelated