当前位置: 首页>>代码示例>>Python>>正文


Python marshmallow.pre_load方法代码示例

本文整理汇总了Python中marshmallow.pre_load方法的典型用法代码示例。如果您正苦于以下问题:Python marshmallow.pre_load方法的具体用法?Python marshmallow.pre_load怎么用?Python marshmallow.pre_load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marshmallow的用法示例。


在下文中一共展示了marshmallow.pre_load方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pre_load

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:16,代码来源:invitation.py

示例2: pre_load

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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 
开发者ID:paperswithcode,项目名称:sota-extractor,代码行数:16,代码来源:schemas.py

示例3: pre_load

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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"]) 
开发者ID:apache,项目名称:incubator-superset,代码行数:7,代码来源:schemas.py

示例4: pre_load

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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, []) 
开发者ID:apache,项目名称:incubator-superset,代码行数:6,代码来源:base_schemas.py

示例5: __init__

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:44,代码来源:invitation.py

示例6: __init__

# 需要导入模块: import marshmallow [as 别名]
# 或者: from marshmallow import pre_load [as 别名]
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 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:54,代码来源:marshmallow.py


注:本文中的marshmallow.pre_load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。