changeset 97:a20fd4fef727

fix methodnotallowed
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 30 Nov 2013 14:52:43 -0800
parents c29d58e79fc6
children 9e1e736958a2
files bitsyblog/bitsyblog.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/bitsyblog.py	Tue May 14 15:55:42 2013 -0700
+++ b/bitsyblog/bitsyblog.py	Sat Nov 30 14:52:43 2013 -0800
@@ -37,6 +37,7 @@
 class BlogPathException(Exception):
     """exception when trying to retrieve the blog"""
 
+
 ### the main course
 
 class BitsyBlog(object):
@@ -123,6 +124,7 @@
                   print 'Cant load entry point %s' % entry_point.name
                   raise
 
+
     ### methods dealing with HTTP
 
     def __call__(self, environ, start_response):
@@ -137,7 +139,7 @@
                                     'user_url': self.user_url,
                                     'permalink': self.permalink }
 
-        res = self.response_functions.get(request.method, self.error())(request)
+        res = self.response_functions.get(request.method, self.method_not_allowed)(request)
         return res(environ, start_response)
 
     def get_response(self, text, content_type='text/html'):
@@ -384,10 +386,14 @@
         return exc.HTTPOk("%s posts blogged" % len(entries))
 
 
-    def error(self):
+    def method_not_allowed(self, request):
         """deal with non-supported methods"""
-        methods = ', '.join(self.response_functions.keys()[:1])
-        methods += ' and %s' % self.response_functions.keys()[-1]
+        allowed = self.response_functions.keys()
+        methods = ', '.join(allowed[:1])
+        methods += ((' and %s' % (allowed[-1]))
+                    if (len(allowed) > 1)
+                    else allowed[0]
+                    )
         return exc.HTTPMethodNotAllowed("Only %s operations are allowed" % methods)
 
     ### auth/auth functions