lots of simplifications (again)
This commit is contained in:
@@ -1 +1 @@
|
||||
Version 2.00.1 (2012-08-28 20:30:26) rc4
|
||||
Version 2.00.1 (2012-08-28 20:38:06) rc4
|
||||
|
||||
+22
-17
@@ -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 += '<!-- %s //-->' % ('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'
|
||||
|
||||
Reference in New Issue
Block a user