コード例 #1
0
    def parse_data(cls, title, body, itemtype=u'Article'):
        body = body.replace('\r\n', '\n')

        default_data = {
            'name': title,
            'schema': schema.get_itemtype_path(itemtype)
        }

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value'))
                                  for m in re.finditer(cls.re_data, body))

        if itemtype == u'Article' or u'Article' in schema.get_schema(
                itemtype)[u'ancestors']:
            default_section = u'articleBody'
        else:
            default_section = u'longDescription'
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
コード例 #2
0
    def parse_data(cls, title, body, itemtype=u'Article'):
        # collect data
        default_data = {'name': title, 'schema': schema.get_itemtype_path(itemtype)}
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value')) for m in re.finditer(cls.re_data, body))
        data = merge_dicts([default_data, yaml_data, body_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
コード例 #3
0
    def parse_data(cls, title, body, itemtype=u"Article"):
        body = body.replace("\r\n", "\n")

        default_data = {"name": title, "schema": schema.get_itemtype_path(itemtype)}

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group("name"), m.group("value")) for m in re.finditer(cls.re_data, body))

        if itemtype == u"Article" or u"Article" in schema.get_schema(itemtype)[u"ancestors"]:
            default_section = u"articleBody"
        else:
            default_section = u"longDescription"
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
コード例 #4
0
ファイル: page_operation_mixin.py プロジェクト: 0hoo/ecogwiki
    def parse_data(cls, title, body, itemtype=u'Article'):
        body = body.replace('\r\n', '\n')

        default_data = {'name': title, 'schema': schema.get_itemtype_path(itemtype)}

        # collect
        yaml_data = cls.parse_schema_yaml(body)
        body_data = pairs_to_dict((m.group('name'), m.group('value')) for m in re.finditer(cls.re_data, body))

        if itemtype == u'Article' or u'Article' in schema.get_schema(itemtype)[u'ancestors']:
            default_section = u'articleBody'
        else:
            default_section = u'longDescription'
        section_data = cls.parse_sections(body, default_section)

        # merge
        data = merge_dicts([default_data, yaml_data, body_data, section_data])

        # validation and type conversion
        typed = schema.SchemaConverter.convert(itemtype, data)

        return typed
コード例 #5
0
ファイル: test_models_utils.py プロジェクト: 0hoo/ecogwiki
 def test_normal_pairs(self):
     self.assertEqual({'a': 1, 'b': 2}, pairs_to_dict([('a', 1), ('b', 2)]))
コード例 #6
0
ファイル: test_models_utils.py プロジェクト: 0hoo/ecogwiki
 def test_duplicated_key_and_value(self):
     self.assertEqual({'a': 1}, pairs_to_dict([('a', 1), ('a', 1)]))
コード例 #7
0
ファイル: test_models_utils.py プロジェクト: 0hoo/ecogwiki
 def test_empty(self):
     self.assertEqual({}, pairs_to_dict([]))
コード例 #8
0
ファイル: test_models_utils.py プロジェクト: 0hoo/ecogwiki
 def test_duplicated_key(self):
     self.assertEqual({'a': [1, 2]}, pairs_to_dict([('a', 1), ('a', 2)]))
コード例 #9
0
 def test_normal_pairs(self):
     self.assertEqual({'a': 1, 'b': 2}, pairs_to_dict([('a', 1), ('b', 2)]))
コード例 #10
0
 def test_empty(self):
     self.assertEqual({}, pairs_to_dict([]))
コード例 #11
0
 def test_duplicated_key_and_value(self):
     self.assertEqual({'a': 1}, pairs_to_dict([('a', 1), ('a', 1)]))
コード例 #12
0
 def test_duplicated_key(self):
     self.assertEqual({'a': [1, 2]}, pairs_to_dict([('a', 1), ('a', 2)]))