Esempio n. 1
0
class ComplicatedXMLNested(XMLSchema):
    r1 = fields.Int(required=True, attribute='result_field1', data_key='X')
    r2 = fields.List(fields.Int(),
                     required=True,
                     attribute='result_field2',
                     data_key='Y')
    nested = fields.XMLNested(ComplicatedXMLNested2,
                              many=True,
                              attribute='result_field3',
                              data_key='Z')
Esempio n. 2
0
class RedditSchema(XMLSchema):
    title = fields.Str(required=True)
    author = fields.Nested(RedditSchemaAuthor, required=True)
    link = fields.Nested(RedditSchemaLink, required=True)
    description = fields.Nested(RedditSchemaContent, data_key='content')
    updated = fields.DateTime(required=True, attribute='dt_create')
    category = fields.XMLNested(RedditSchemaCategory, attribute='tags',
                                many=True)

    @post_load
    def prepare_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
        tags = data.get('tags')
        if tags:
            tag_list = []
            for tag in tags:
                tag_list.append(tag['cat'])
            data['tags'] = tag_list
        return data
Esempio n. 3
0
class ComplicatedXMLNested2(JSONSchema):
    z1 = fields.Str(required=True, attribute='result_field4', data_key='Q')
    z2 = fields.XMLNested(ComplicatedXMLNested3,
                          attribute='result_field5',
                          data_key='ddd')
Esempio n. 4
0
class ComplicatedXML(XMLSchema):
    root = fields.XMLNested(ComplicatedXMLNested, required=True)

    @post_load
    def data_from_root(self, item):
        return item[self.fields['root'].name]
Esempio n. 5
0
class RedditSchemaEntry(XMLSchema):
    entry = fields.XMLNested(RedditSchema, required=True, many=True)
Esempio n. 6
0
class HabraSchemaRSS(XMLSchema):
    rss = fields.XMLNested(HabraSchemaChannel)

    @post_load
    def make_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
        return data['rss']['channel']['item']