From 6b606aaa242245c30df7de35664f94105e9de6be Mon Sep 17 00:00:00 2001 From: mdipierro Date: Tue, 28 Aug 2012 20:38:11 -0500 Subject: [PATCH] lots of simplifications (again) --- VERSION | 2 +- gluon/http.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/VERSION b/VERSION index 7a27f3d6..baa88dee 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.1 (2012-08-28 20:30:26) rc4 +Version 2.00.1 (2012-08-28 20:38:06) rc4 diff --git a/gluon/http.py b/gluon/http.py index e659bbdc..548ac6d9 100644 --- a/gluon/http.py +++ b/gluon/http.py @@ -77,40 +77,45 @@ class HTTP(BaseException): str(cookie)[11:] for cookie in cookies.values()] def to(self, responder): - if self.status in defined_status: - status = '%d %s' % (self.status, defined_status[self.status]) + status = self.status + headers = self.headers + if status in defined_status: + status = '%d %s' % (status, defined_status[status]) else: - status = str(self.status) + ' ' - if not 'Content-Type' in self.headers: - self.headers['Content-Type'] = 'text/html; charset=UTF-8' + status = str(status) + ' ' + if not 'Content-Type' in headers: + headers['Content-Type'] = 'text/html; charset=UTF-8' body = self.body if status[:1] == '4': if not body: body = status if isinstance(body, str): - if len(body)<512 and self.headers['Content-Type'].startswith('text/html'): + if len(body)<512 and headers['Content-Type'].startswith('text/html'): body += '' % ('x'*512) ### trick IE - self.headers['Content-Length'] = len(body) - headers = [] - for k, v in self.headers.iteritems(): + headers['Content-Length'] = len(body) + rheaders = [] + for k, v in headers.iteritems(): if isinstance(v, list): - headers += [(k, str(item)) for item in v] + rheaders += [(k, str(item)) for item in v] else: - headers.append((k, str(v))) - responder(status, headers) - if hasattr(body, '__iter__') and not isinstance(self.body,str): + rheaders.append((k, str(v))) + responder(status, rheaders) + if isinstance(body,str): + return [body] + elif hasattr(body, '__iter__'): return body - return [str(body)] + else: + return [str(body)] @property def message(self): - ''' + """ compose a message describing this exception - "status defined_status [web2py_error]" + "status defined_status [web2py_error]" message elements that are not defined are omitted - ''' + """ msg = '%(status)d' if self.status in defined_status: msg = '%(status)d %(defined_status)s'