Skip to content

Commit

Permalink
atom: add xml:base. for #78, snarfed/facebook-atom#10
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Feb 21, 2016
1 parent e8f1eff commit 3215af0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion granary/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _encode_ampersands(text):


def activities_to_atom(activities, actor, title=None, request_url=None,
host_url=None):
host_url=None, xml_base=None):
"""Converts ActivityStreams activites to an Atom feed.
Args:
Expand All @@ -35,6 +35,7 @@ def activities_to_atom(activities, actor, title=None, request_url=None,
request_url: the URL of this Atom feed, if any. Used in a link rel="self".
host_url: the home URL for this Atom feed, if any. Used in the top-level
feed <id> element.
xml_base: the base URL, if any. Used in the top-level xml:base attribute.
Returns: unicode string with Atom XML
"""
Expand Down Expand Up @@ -96,6 +97,7 @@ def __unicode__(self):
items=[Defaulter(**a) for a in activities],
host_url=host_url,
request_url=request_url,
xml_base=xml_base,
title=title or 'User feed for ' + source.Source.actor_name(actor),
updated=activities[0]['object'].get('published', '') if activities else '',
actor=Defaulter(**actor),
Expand Down
2 changes: 1 addition & 1 deletion granary/templates/user_feed.atom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:georss="http://www.georss.org/georss"
xmlns:ostatus="http://ostatus.org/schema/1.0"
xmlns:thr="http://purl.org/syndication/thread/1.0"
>
{% if xml_base %}xml:base="{{ xml_base }}"{% endif %}>
<generator uri="https://github.com/snarfed/granary" version="0.1">granary</generator>
<id>{{ host_url }}</id>
<title>{{ title }}</title>
Expand Down
12 changes: 12 additions & 0 deletions granary/test/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,15 @@ def test_attachments(self):
article content
</blockquote>
""", got)

def test_xml_base(self):
self.assert_multiline_in("""
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US"
xmlns="http://www.w3.org/2005/Atom"
xmlns:activity="http://activitystrea.ms/spec/1.0/"
xmlns:georss="http://www.georss.org/georss"
xmlns:ostatus="http://ostatus.org/schema/1.0"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:base="http://my.xml/base">
""", atom.activities_to_atom([], {}, xml_base='http://my.xml/base'))

0 comments on commit 3215af0

Please sign in to comment.