Python marshmallow.fields 模块,Dict() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用marshmallow.fields.Dict()

项目:lymph-schema    作者:deliveryhero    | 项目源码 | 文件源码
def dump_schema(schema_obj):
    json_schema = {
        "type": "object",
        "properties": {},
        "required": [],
    }
    mapping = {v: k for k, v in schema_obj.TYPE_MAPPING.items()}
    mapping[fields.Email] = text_type
    mapping[fields.Dict] = dict
    mapping[fields.List] = list
    mapping[fields.Url] = text_type
    mapping[fields.LocalDateTime] = datetime.datetime

    for field_name, field in sorted(schema_obj.fields.items()):
        schema = None

        if field.__class__ in mapping:
            pytype = mapping[field.__class__]
            schema = _from_python_type(field, pytype)
        elif isinstance(field, fields.Nested):
            schema = _from_nested_schema(field)
        elif issubclass(field.__class__, fields.Field):
            for cls in mapping.keys():
                if issubclass(field.__class__, cls):
                    pytype = mapping[cls]
                    schema = _from_python_type(field, pytype)
                    break

        if schema is None:
            raise ValueError('unsupported field type %s' % field)

        field_name = field.dump_to or field.name
        json_schema['properties'][field_name] = schema
        if field.required:
            json_schema['required'].append(field.name)
    return json_schema
项目:umongo    作者:Scille    | 项目源码 | 文件源码
def __init__(self, *args, **kwargs):
        kwargs.setdefault('default', {})
        kwargs.setdefault('missing', Dict)
        super().__init__(*args, **kwargs)
项目:umongo    作者:Scille    | 项目源码 | 文件源码
def _deserialize(self, value, attr, data):
        value = super()._deserialize(value, attr, data)
        return Dict(value)
项目:umongo    作者:Scille    | 项目源码 | 文件源码
def _deserialize_from_mongo(self, value):
        if value:
            return Dict(value)
        else:
            return Dict()