Permalink
Browse files

put alternate in rels and rel-urls

  • Loading branch information...
kevinmarks committed Jun 2, 2015
1 parent fffb2fa commit 4dba45200eef11da811f64817d02044ab9e98b77
Showing with 21 additions and 17 deletions.
  1. +15 −16 mf2py/parser.py
  2. +6 −1 test/test_parser.py
View
@@ -275,22 +275,21 @@ def parse_rels(el):
url = urljoin(self.__url__, el.get('href', ''))
# there does not exist alternate in rel attributes
# then parse rels as local
if "alternate" not in rel_attrs:
value_dict = self.__parsed__["rel-urls"].get(url, {})
value_dict["text"] = el.get_text().strip()
url_rels = value_dict.get("rels",[])
value_dict["rels"] = url_rels
for knownattr in ("media","hreflang","type","title"):
x = get_attr(el, knownattr)
if x is not None:
value_dict[knownattr] = x
self.__parsed__["rel-urls"][url] = value_dict
for rel_value in rel_attrs:
value_list = self.__parsed__["rels"].get(rel_value, [])
value_list.append(url)
url_rels.append(rel_value)
self.__parsed__["rels"][rel_value] = value_list
else:
value_dict = self.__parsed__["rel-urls"].get(url, {})
value_dict["text"] = el.get_text().strip()
url_rels = value_dict.get("rels",[])
value_dict["rels"] = url_rels
for knownattr in ("media","hreflang","type","title"):
x = get_attr(el, knownattr)
if x is not None:
value_dict[knownattr] = x
self.__parsed__["rel-urls"][url] = value_dict
for rel_value in rel_attrs:
value_list = self.__parsed__["rels"].get(rel_value, [])
value_list.append(url)
url_rels.append(rel_value)
self.__parsed__["rels"][rel_value] = value_list
if "alternate" in rel_attrs:
alternate_list = self.__parsed__.get("alternates", [])
alternate_dict = {}
alternate_dict["url"] = url
View
@@ -7,6 +7,8 @@
import sys
import glob
import json
from unittest import TestCase
TestCase.maxDiff = None
if sys.version < '3':
text_type = unicode
@@ -317,12 +319,16 @@ def test_rels():
assert result['rels'] == {
u'in-reply-to': [u'http://example.com/1', u'http://example.com/2'],
u'author': [u'http://example.com/a', u'http://example.com/b'],
u'alternate': [u'http://example.com/fr'],
u'home': [u'http://example.com/fr'],
}
assert result['rel-urls'] == {
u'http://example.com/1': {'text': u"post 1", "rels": [u'in-reply-to']},
u'http://example.com/2': {'text': u"post 2", "rels": [u'in-reply-to']},
u'http://example.com/a': {'text': u"author a", "rels": [u'author']},
u'http://example.com/b': {'text': u"author b", "rels": [u'author']},
u'http://example.com/fr': {'text': u'French mobile homepage',
'media': u'handheld', "rels":[u'alternate',u'home'], u'hreflang': u'fr'}
}
@@ -418,7 +424,6 @@ def test_mf2tests():
p = json.loads(Parser(doc=f).to_json())
with open(jsonfile) as g:
s = json.load(g)
p.pop('rel-urls',None)
yield check_mf2, htmlfile, p,s
def check_mf2(htmlfile, p,s):

0 comments on commit 4dba452

Please sign in to comment.