Mercurial > hg > bitsyblog
comparison bitsyblog/bitsyblog.py @ 97:a20fd4fef727
fix methodnotallowed
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 30 Nov 2013 14:52:43 -0800 |
parents | fa221a2d24d9 |
children | 9e1e736958a2 |
comparison
equal
deleted
inserted
replaced
96:c29d58e79fc6 | 97:a20fd4fef727 |
---|---|
34 | 34 |
35 ### exceptions | 35 ### exceptions |
36 | 36 |
37 class BlogPathException(Exception): | 37 class BlogPathException(Exception): |
38 """exception when trying to retrieve the blog""" | 38 """exception when trying to retrieve the blog""" |
39 | |
39 | 40 |
40 ### the main course | 41 ### the main course |
41 | 42 |
42 class BitsyBlog(object): | 43 class BitsyBlog(object): |
43 """a very tiny blog""" | 44 """a very tiny blog""" |
121 self.handlers.append(handler) | 122 self.handlers.append(handler) |
122 except: | 123 except: |
123 print 'Cant load entry point %s' % entry_point.name | 124 print 'Cant load entry point %s' % entry_point.name |
124 raise | 125 raise |
125 | 126 |
127 | |
126 ### methods dealing with HTTP | 128 ### methods dealing with HTTP |
127 | 129 |
128 def __call__(self, environ, start_response): | 130 def __call__(self, environ, start_response): |
129 request = Request(environ) | 131 request = Request(environ) |
130 | 132 |
135 'logo': self.logo(request), | 137 'logo': self.logo(request), |
136 'header': self.header, | 138 'header': self.header, |
137 'user_url': self.user_url, | 139 'user_url': self.user_url, |
138 'permalink': self.permalink } | 140 'permalink': self.permalink } |
139 | 141 |
140 res = self.response_functions.get(request.method, self.error())(request) | 142 res = self.response_functions.get(request.method, self.method_not_allowed)(request) |
141 return res(environ, start_response) | 143 return res(environ, start_response) |
142 | 144 |
143 def get_response(self, text, content_type='text/html'): | 145 def get_response(self, text, content_type='text/html'): |
144 # XXX to deprecate | 146 # XXX to deprecate |
145 res = Response(content_type=content_type, body=text) | 147 res = Response(content_type=content_type, body=text) |
382 self.blog.post(user, datestamp, entries[i], 'public') | 384 self.blog.post(user, datestamp, entries[i], 'public') |
383 | 385 |
384 return exc.HTTPOk("%s posts blogged" % len(entries)) | 386 return exc.HTTPOk("%s posts blogged" % len(entries)) |
385 | 387 |
386 | 388 |
387 def error(self): | 389 def method_not_allowed(self, request): |
388 """deal with non-supported methods""" | 390 """deal with non-supported methods""" |
389 methods = ', '.join(self.response_functions.keys()[:1]) | 391 allowed = self.response_functions.keys() |
390 methods += ' and %s' % self.response_functions.keys()[-1] | 392 methods = ', '.join(allowed[:1]) |
393 methods += ((' and %s' % (allowed[-1])) | |
394 if (len(allowed) > 1) | |
395 else allowed[0] | |
396 ) | |
391 return exc.HTTPMethodNotAllowed("Only %s operations are allowed" % methods) | 397 return exc.HTTPMethodNotAllowed("Only %s operations are allowed" % methods) |
392 | 398 |
393 ### auth/auth functions | 399 ### auth/auth functions |
394 | 400 |
395 def passwords(self): | 401 def passwords(self): |