def deserialize(self, cstruct=null): if cstruct is null: return null schema_type = self._deserialize_type(cstruct) subschema = self._build_schema(schema_type) return MappingSchema.deserialize(subschema, cstruct)
def deserialize(self, cstruct=null): if cstruct is null: return null schema_type = self._deserialize_type(cstruct) subschema = self._build_schema(schema_type) return MappingSchema.deserialize(subschema, cstruct)
def _validate_dict_schema(schema: MappingSchema, cstruct: dict, request: Request, location='body'): validated = {} try: validated = schema.deserialize(cstruct) except Invalid as err: for child in err.children: _add_colander_invalid_error_to_request(child, request, location) request.validated.update(validated)
def _deserialize_type(self, cstruct): """ Get the type of the entity based on `cstruct`. """ # Build a schema containing only the type key. type_schema = MappingSchema() type_schema[self.type_key] = self[self.type_key] # Assign the proper name to the subschema so that # Invalid exceptions contains the right hierarchy. type_schema.name = self.name return type_schema.deserialize(cstruct)[self.type_key]
def _deserialize_type(self, cstruct): """ Get the type of the entity based on `cstruct`. """ # Build a schema containing only the type key. type_schema = MappingSchema() type_schema[self.type_key] = self[self.type_key] # Assign the proper name to the subschema so that # Invalid exceptions contains the right hierarchy. type_schema.name = self.name return type_schema.deserialize(cstruct)[self.type_key]
def _validate_dict_schema(schema: MappingSchema, cstruct: dict, request: Request, location='body'): validated = {} try: validated = schema.deserialize(cstruct) except Invalid as err: for child in err.children: _add_colander_invalid_error_to_request(child, request, location) if not err.children: _add_colander_invalid_error_to_request(err, request, location) request.validated.update(validated)
def deserialize(self, cstruct): if 'field' in cstruct and not isinstance(cstruct['field'], list): cstruct['field'] = [cstruct['field']] return MappingSchema.deserialize(self, cstruct)
def deserialize(self, cstruct): if 'body' in cstruct and cstruct['body'] == b'hello,open,yeah': values = cstruct['body'].decode().split(',') cstruct['body'] = dict(zip(['foo', 'bar', 'yeah'], values)) return MappingSchema.deserialize(self, cstruct)
def deserialize(self, cstruct): if 'field' in cstruct and not isinstance(cstruct['field'], list): cstruct['field'] = [cstruct['field']] return MappingSchema.deserialize(self, cstruct)
def deserialize(self, cstruct): if 'body' in cstruct and cstruct['body'] == b'hello,open,yeah': values = cstruct['body'].decode().split(',') cstruct['body'] = dict(zip(['foo', 'bar', 'yeah'], values)) return MappingSchema.deserialize(self, cstruct)