constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit ef15ee700321a3fa7b6aad519a8f1644dc701c00
parent d78b313afff4b31c52f9b500fc441cea400ef81c
Author: Dan Callaghan <djc@djc.id.au>
Date:   Thu,  4 Dec 2008 18:35:05 +1000

serve atom with .atom extension

Diffstat:
Mapp.py | 6+++++-
Mitemtypes.py | 6++++--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/app.py b/app.py
@@ -52,7 +52,11 @@ class Constance(object):
             (r'/blog/([^/]+)/comments/\+new$', 'add_post_comment')]
     urls = [(re.compile(patt), method) for patt, method in urls]
     def dispatch(self):
-        format = self.req.accept.best_match(['text/html', 'application/atom+xml']) # XXX don't hardcode
+        if self.req.path_info.endswith('.atom'):
+            format = 'application/atom+xml'
+            self.req.path_info = self.req.path_info[:-5]
+        else:
+            format = self.req.accept.best_match(['text/html', 'application/atom+xml']) # XXX don't hardcode
 
         if self.req.path_info == '/':
             return self.index(format)
diff --git a/itemtypes.py b/itemtypes.py
@@ -126,10 +126,11 @@ class BlogEntrySet(object):
         self.base_dir = base_dir
         assert os.path.isdir(self.base_dir), self.base_dir
         self.prefix = prefix
+        self.index_patt = re.compile(re.escape(prefix) + r'/?(index)?$')
         self.entry_patt = re.compile(re.escape(prefix) + r'/([^/]+)/?$')
 
     def get(self, path_info):
-        if path_info == self.prefix or path_info == self.prefix + '/':
+        if self.index_patt.match(path_info):
             return iter(self)
         m = self.entry_patt.match(path_info)
         if m is None:
@@ -178,9 +179,10 @@ class ReadingLogEntrySet(object):
         self.filename = filename
         assert os.path.isfile(self.filename), self.filename
         self.prefix = prefix
+        self.index_patt = re.compile(re.escape(prefix) + r'/?(index)?$')
 
     def get(self, path_info):
-        if path_info == self.prefix or path_info == self.prefix + '/':
+        if self.index_patt.match(path_info):
             return iter(self)
         raise NotExistError(path_info)