reverted HTTP(status_message) because redundant
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.4.6-stable+timestamp.2013.05.17.14.52.19
|
Version 2.4.6-stable+timestamp.2013.05.19.22.13.58
|
||||||
|
|||||||
+9
-19
@@ -69,14 +69,12 @@ class HTTP(BaseException):
|
|||||||
status,
|
status,
|
||||||
body='',
|
body='',
|
||||||
cookies=None,
|
cookies=None,
|
||||||
status_message='',
|
|
||||||
**headers
|
**headers
|
||||||
):
|
):
|
||||||
self.status = status
|
self.status = status
|
||||||
self.body = body
|
self.body = body
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
self.cookies2headers(cookies)
|
self.cookies2headers(cookies)
|
||||||
self.status_message = status_message
|
|
||||||
|
|
||||||
def cookies2headers(self, cookies):
|
def cookies2headers(self, cookies):
|
||||||
if cookies and len(cookies) > 0:
|
if cookies and len(cookies) > 0:
|
||||||
@@ -87,14 +85,10 @@ class HTTP(BaseException):
|
|||||||
env = env or {}
|
env = env or {}
|
||||||
status = self.status
|
status = self.status
|
||||||
headers = self.headers
|
headers = self.headers
|
||||||
status_message = status
|
|
||||||
if status in defined_status:
|
if status in defined_status:
|
||||||
if status_message:
|
status = '%d %s' % (status, defined_status[status])
|
||||||
status = str(status) + ' ' + str(status_message)
|
|
||||||
else:
|
|
||||||
status = '%d %s' % (status, defined_status[status])
|
|
||||||
else:
|
else:
|
||||||
status = str(status) + ' ' + status_message
|
status = str(status)
|
||||||
if not regex_status.match(status):
|
if not regex_status.match(status):
|
||||||
status = '500 %s' % (defined_status[500])
|
status = '500 %s' % (defined_status[500])
|
||||||
headers.setdefault('Content-Type', 'text/html; charset=UTF-8')
|
headers.setdefault('Content-Type', 'text/html; charset=UTF-8')
|
||||||
@@ -129,19 +123,15 @@ class HTTP(BaseException):
|
|||||||
|
|
||||||
message elements that are not defined are omitted
|
message elements that are not defined are omitted
|
||||||
"""
|
"""
|
||||||
msg = '%(status)d'
|
msg = '%(status)s'
|
||||||
status_message = ''
|
if self.status in defined_status:
|
||||||
if self.status_message:
|
msg = '%(status)s %(defined_status)s'
|
||||||
status_message = self.status_message
|
|
||||||
elif self.status in defined_status:
|
|
||||||
status_message = defined_status.get(self.status)
|
|
||||||
if status_message:
|
|
||||||
msg = '%(status)d %(defined_status)s'
|
|
||||||
if 'web2py_error' in self.headers:
|
if 'web2py_error' in self.headers:
|
||||||
msg += ' [%(web2py_error)s]'
|
msg += ' [%(web2py_error)s]'
|
||||||
return msg % dict(status=self.status,
|
return msg % dict(
|
||||||
defined_status=status_message,
|
status=self.status,
|
||||||
web2py_error=self.headers.get('web2py_error'))
|
defined_status=defined_status.get(self.status),
|
||||||
|
web2py_error=self.headers.get('web2py_error'))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"stringify me"
|
"stringify me"
|
||||||
|
|||||||
@@ -24,17 +24,21 @@ class TestHTTP(unittest.TestCase):
|
|||||||
|
|
||||||
def gen_status_str(code, message):
|
def gen_status_str(code, message):
|
||||||
return str(code) + ' ' + str(message)
|
return str(code) + ' ' + str(message)
|
||||||
message = 'This is a custom message'
|
message = '1423 This is a custom message'
|
||||||
code = 1423
|
code = 1423
|
||||||
self.assertEqual(str(h(code, status_message=message)), gen_status_str(code, message))
|
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||||
|
gen_status_str(code, message))
|
||||||
|
|
||||||
# test predefined codes
|
# test predefined codes
|
||||||
for code in defined_status.keys():
|
for code in defined_status.keys():
|
||||||
self.assertEqual(str(h(code)), gen_status_str(code, defined_status[code]))
|
self.assertEqual(
|
||||||
|
str(h(code)),
|
||||||
|
gen_status_str(code, defined_status[code]))
|
||||||
|
|
||||||
# test correct use of status_message
|
# test correct use of status_message
|
||||||
for code in defined_status.keys():
|
for code in defined_status.keys():
|
||||||
self.assertEqual(str(h(code, status_message=message)), gen_status_str(code, message))
|
self.assertEqual(str(h(gen_status_str(code, message))),
|
||||||
|
gen_status_str(code, message))
|
||||||
|
|
||||||
# test wrong call detection
|
# test wrong call detection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user