# HG changeset patch # User Jeff Hammel # Date 1385851963 28800 # Node ID a20fd4fef72732f476489fa905e56f09d7b40fb9 # Parent c29d58e79fc6922320d5c9360c9f3ce16ff98c14 fix methodnotallowed diff -r c29d58e79fc6 -r a20fd4fef727 bitsyblog/bitsyblog.py --- 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