Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atom + utf-8 support. #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

atom + utf-8 support. #5

wants to merge 5 commits into from

Conversation

fliot
Copy link

@fliot fliot commented Oct 14, 2022

No description provided.

@sbordeyne
Copy link
Owner

Thanks for the pull request, I had a look and I'll give you a review before merging it


def tostring(self, nsmap: Optional[Dict[str, str]] = None):
nsmap = nsmap or {}
nsmap = nsmap or {'atom': 'http://www.w3.org/2005/Atom'}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not default to atom mode. The library must be kept consistent as is (i.e. compliant with the original RSS specification).

In order to ease the implementation I am not opposed to dropping the nsmap kwarg and adding an atom / podcast kwarg to generate the nsmap accordingly.

@@ -46,7 +46,7 @@ def _generate_tree_list(root: etree.Element, key: str, value: List[dict]) -> Non
if content is not None:
itemroot.text = content
else:
RSSFeed.generate_tree(itemroot, item)
RSSFeed.generate_tree(itemroot, item, {})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change won't be necessary (see other comments)

RSSFeed.generate_tree(channel, self.dict())
return etree.tostring(rss, pretty_print=True, xml_declaration=True)
RSSFeed.generate_tree(channel, self.dict(), nsmap)
return etree.tostring(rss, pretty_print=True, xml_declaration=True, encoding='UTF-8')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have originally encoded the string as utf-8, I agree, but the original RSS specification didn't mention a specific encoding to use (to be fair, at the time of the spec for RSS 2.0, UTF-8 wasn't widely supported yet).

Encoding as UTF-8 can be the default, but it should be able to be opted out if need be, in order to keep the library consistent with its previous version.

Furthermore, such a change will warrant a major version bump. Please upgrade the version in pyproject.toml to reflect that.

@@ -8,7 +8,7 @@ def test_rss_sample_response(client: TestClient, expected_response: str, capsys)
response = client.get('/1')
assert response.status_code == 200
tree = etree.fromstring(response.content)
pretty: str = etree.tostring(tree, pretty_print=True, xml_declaration=True).decode('ascii')
pretty: str = etree.tostring(tree, pretty_print=True, xml_declaration=True).decode('utf-8')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my other comment, this change is not needed anymore, instead make a new test specifically for the utf8 encoded version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants