當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。