Small changes to do_atom(), make it validate.
Tue Dec 13 14:12:44 UTC 2005 Alberto Bertogli <albertogli@telpin.com.ar>
* Small changes to do_atom(), make it validate.
diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi
--- old-darcsweb/darcsweb.cgi 2015-10-01 14:29:19.000000000 +0000
+++ new-darcsweb/darcsweb.cgi 2015-10-01 14:29:19.000000000 +0000
@@ -19,6 +19,7 @@
import urllib
import xml.sax
from xml.sax.saxutils import escape as xml_escape
+import email.Utils
iso_datetime = '%Y-%m-%dT%H:%M:%SZ'
@@ -233,6 +234,8 @@
<link rel="stylesheet" type="text/css" href="%(css)s"/>
<link rel="alternate" title="%(reponame)s" href="%(url)s;a=rss"
type="application/rss+xml"/>
+<link rel="alternate" title="%(reponame)s" href="%(url)s;a=atom"
+ type='application/atom+xml'/>
<link rel="shortcut icon" href="%(fav)s"/>
<link rel="icon" href="%(fav)s"/>
</head>
@@ -1721,10 +1724,14 @@
print '<?xml version="1.0" encoding="utf-8"?>'
inv = config.repodir + '/_darcs/inventory'
repo_lastmod = os.stat(inv).st_mtime
- print """<feed xmlns="http://www.w3.org/2005/Atom">
+ str_lastmod = time.strftime(iso_datetime,
+ time.localtime(repo_lastmod))
+
+ print """
+<feed xmlns="http://www.w3.org/2005/Atom">
<title>%(reponame)s darcs repository</title>
<link rel="alternate" type="text/html" href="%(url)s"/>
- <link rel="self" type="application/atom+xml" href="%(url)s/%(reponame)s;a=atom"/>
+ <link rel="self" type="application/atom+xml" href="%(url)s;a=atom"/>
<id>%(url)s</id> <!-- TODO: find a better <id>, see RFC 4151 -->
<author><name>darcs repository (several authors)</name></author>
<generator>darcsweb.cgi</generator>
@@ -1734,7 +1741,9 @@
'reponame': config.reponame,
'url': config.myurl + '/' + config.myreponame,
'desc': config.repodesc,
- 'lastmod': time.strftime(iso_datetime, time.localtime(repo_lastmod))}
+ 'lastmod': str_lastmod,
+ }
+
ps = get_last_patches(20)
for p in ps:
title = time.strftime('%d %b %H:%M', time.localtime(p.date))
@@ -1744,25 +1753,38 @@
link = '%s/%s;a=commit;h=%s' % (config.myurl,
config.myreponame, p.hash)
+ addr, author = email.Utils.parseaddr(p.author)
+ if not addr:
+ addr = "unknown_email@example.com"
+ if not author:
+ author = addr
+
print """
<entry>
<title>%(title)s</title>
- <author><name>%(author)s</name><!-- TODO: parse it to get the email. Not obvious, darcs authors can be anything --></author>
+ <author>
+ <name>%(author)s</name>
+ <email>%(email)s</email>
+ </author>
<updated>%(pdate)s</updated>
- <id>%(url)s/%(pname)s</id> <!-- TODO: find a better <id>, see RFC 4151 -->
+ <id>%(link)s</id>
<link rel="alternate" href="%(link)s"/>
<summary>%(desc)s</summary>
+ <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>
""" % {
'title': escape(title),
- 'author': p.author,
+ 'author': author,
+ 'email': addr,
'url': config.myurl + '/' + config.myreponame,
'pdate': pdate,
+ 'myrname': config.myreponame,
+ 'hash': p.hash,
'pname': escape(p.name),
'link': link,
'desc': escape(p.name),
}
+
# TODO: allow to get plain text, not HTML?
- print ' <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>'
print escape(p.name) + '<br/>'
if p.comment:
print '<br/>'
@@ -1777,7 +1799,7 @@
print '</p></div>'
print '</content></entry>'
print '</feed>'
-
+
def do_rss():
print "Content-type: text/xml; charset=utf-8\n"
print '<?xml version="1.0" encoding="utf-8"?>'