lkiesow / python-feedgen

Python module to generate ATOM feeds, RSS feeds and Podcasts.
https://feedgen.kiesow.be/
BSD 2-Clause "Simplified" License
723 stars 123 forks source link

Rename url to uri in Atom feeds for RFC 4287 compliance #54

Closed zmwangx closed 7 years ago

zmwangx commented 7 years ago

According to RFC 4287, there is no atom:url element, only atom:uri, so replace occurrences of atom:url with atom:uri for compliance.

Also rename variables holding atom:uri from email to uri to better indicate what they actually are.


Previously, generated feeds would fail the W3 Feed Validation Service. A simple test script gen.py:

#!/usr/bin/env python3
from feedgen.feed import FeedGenerator

author = {'name': 'Zhiming Wang', 'email': 'zmwangx@gmail.com', 'uri': 'https://zhimingwang.org'}

fg = FeedGenerator()
fg.id('https://zhimingwang.org/test.atom')
fg.title('Test feed')
fg.author(author)

fe = fg.add_entry()
fe.id('https://zhimingwang.org/1970/1/1/test.html')
fe.title('Test entry')
fe.author(author)
fe.content('Test piece.')

print(fg.atom_str().decode('utf-8'))

Pass it through the validator:

$ curl -sS -X POST --data-urlencode "rawdata=$(./gen.py)" --data-urlencode 'output=soap12' https://validator.w3.org/feed/check.cgi | xmllint --format -

Response:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
  <env:Body>
    <m:feedvalidationresponse xmlns:m="http://www.w3.org/2005/10/feed-validator" env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
      <m:uri/>
      <m:checkedby>http://validator.w3.org/feed/check.cgi</m:checkedby>
      <m:date>2016-12-19T05:51:39.782184</m:date>
      <m:validity>false</m:validity>
      <m:errors>
        <m:errorcount>1</m:errorcount>
        <m:errorlist>
          <error>
            <level>error</level>
            <type>UndefinedElement</type>
            <line>2</line>
            <column>224</column>
            <text>Undefined author element: url</text>
            <msgcount>2</msgcount>
            <backupcolumn>224</backupcolumn>
            <backupline>2</backupline>
            <element>url</element>
            <parent>author</parent>
          </error>
        </m:errorlist>
      </m:errors>
      <m:warnings>
        <m:warningcount>1</m:warningcount>
        <m:warninglist>
          <warning>
            <level>warning</level>
            <type>MissingSelf</type>
            <line>2</line>
            <column>0</column>
            <text>Missing atom:link with rel="self"</text>
            <msgcount>1</msgcount>
            <backupcolumn>320</backupcolumn>
            <backupline>2</backupline>
            <element>feed</element>
            <parent>root</parent>
          </warning>
        </m:warninglist>
      </m:warnings>
      <m:informations>
        <m:infocount>0</m:infocount>
        <m:infolist/>
      </m:informations>
    </m:feedvalidationresponse>
  </env:Body>
</env:Envelope>

Note the error:

Undefined author element: url
lkiesow commented 7 years ago

Thanks for the patch. Does make sense → merged

zmwangx commented 7 years ago

Thanks. Would you please consider a patch release?

lkiesow commented 7 years ago

I do. I found some other minor issues no one noticed so far. I'm just fixing them. I will bring out a release in the next days.

zmwangx commented 7 years ago

Cool, thanks.

lkiesow commented 7 years ago

Sorry that it took so long. I've released two new versions: 0.4.1 and 0.5.1

zmwangx commented 7 years ago

No problem, thanks for letting me know!