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()]
|
str(cookie)[11:] for cookie in cookies.values()]
|
||||||
|
|
||||||
def to(self, responder):
|
def to(self, responder):
|
||||||
if self.status in defined_status:
|
status = self.status
|
||||||
status = '%d %s' % (self.status, defined_status[self.status])
|
headers = self.headers
|
||||||
|
if status in defined_status:
|
||||||
|
status = '%d %s' % (status, defined_status[status])
|
||||||
else:
|
else:
|
||||||
status = str(self.status) + ' '
|
status = str(status) + ' '
|
||||||
if not 'Content-Type' in self.headers:
|
if not 'Content-Type' in headers:
|
||||||
self.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
headers['Content-Type'] = 'text/html; charset=UTF-8'
|
||||||
body = self.body
|
body = self.body
|
||||||
if status[:1] == '4':
|
if status[:1] == '4':
|
||||||
if not body:
|
if not body:
|
||||||
body = status
|
body = status
|
||||||
if isinstance(body, str):
|
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
|
body += '<!-- %s //-->' % ('x'*512) ### trick IE
|
||||||
self.headers['Content-Length'] = len(body)
|
headers['Content-Length'] = len(body)
|
||||||
headers = []
|
rheaders = []
|
||||||
for k, v in self.headers.iteritems():
|
for k, v in headers.iteritems():
|
||||||
if isinstance(v, list):
|
if isinstance(v, list):
|
||||||
headers += [(k, str(item)) for item in v]
|
rheaders += [(k, str(item)) for item in v]
|
||||||
else:
|
else:
|
||||||
headers.append((k, str(v)))
|
rheaders.append((k, str(v)))
|
||||||
responder(status, headers)
|
responder(status, rheaders)
|
||||||
if hasattr(body, '__iter__') and not isinstance(self.body,str):
|
if isinstance(body,str):
|
||||||
|
return [body]
|
||||||
|
elif hasattr(body, '__iter__'):
|
||||||
return body
|
return body
|
||||||
return [str(body)]
|
else:
|
||||||
|
return [str(body)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def message(self):
|
def message(self):
|
||||||
'''
|
"""
|
||||||
compose a message describing this exception
|
compose a message describing this exception
|
||||||
|
|
||||||
"status defined_status [web2py_error]"
|
"status defined_status [web2py_error]"
|
||||||
|
|
||||||
message elements that are not defined are omitted
|
message elements that are not defined are omitted
|
||||||
'''
|
"""
|
||||||
msg = '%(status)d'
|
msg = '%(status)d'
|
||||||
if self.status in defined_status:
|
if self.status in defined_status:
|
||||||
msg = '%(status)d %(defined_status)s'
|
msg = '%(status)d %(defined_status)s'
|
||||||
|
|||||||
Reference in New Issue
Block a user