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
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
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
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
def test_normal_pairs(self): self.assertEqual({'a': 1, 'b': 2}, pairs_to_dict([('a', 1), ('b', 2)]))
def test_duplicated_key_and_value(self): self.assertEqual({'a': 1}, pairs_to_dict([('a', 1), ('a', 1)]))
def test_empty(self): self.assertEqual({}, pairs_to_dict([]))
def test_duplicated_key(self): self.assertEqual({'a': [1, 2]}, pairs_to_dict([('a', 1), ('a', 2)]))