Commit a8b516e4 authored by 's avatar

- small refactoring for better readability: moved some code in separate _setBCIHeaders method

parent 2d0f0209
...@@ -755,21 +755,7 @@ class HTTPResponse(BaseResponse): ...@@ -755,21 +755,7 @@ class HTTPResponse(BaseResponse):
m = m + '<p>\nNo Authorization header found.</p>' m = m + '<p>\nNo Authorization header found.</p>'
raise Unauthorized, m raise Unauthorized, m
def exception(self, fatal=0, info=None, def _setBCIHeaders(self, t, tb):
absuri_match=re.compile(r'\w+://[\w\.]+').match,
tag_search=re.compile('[a-zA-Z]>').search,
abort=1
):
if isinstance(info, tuple) and len(info) == 3:
t, v, tb = info
else:
t, v, tb = sys.exc_info()
if issubclass(t, Unauthorized):
self._unauthorized()
stb = tb # note alias between tb and stb
try: try:
# Try to capture exception info for bci calls # Try to capture exception info for bci calls
et = translate(str(t), nl2sp) et = translate(str(t), nl2sp)
...@@ -794,13 +780,26 @@ class HTTPResponse(BaseResponse): ...@@ -794,13 +780,26 @@ class HTTPResponse(BaseResponse):
self.setHeader('bobo-exception-file', ef) self.setHeader('bobo-exception-file', ef)
self.setHeader('bobo-exception-line', el) self.setHeader('bobo-exception-line', el)
except: except:
# Dont try so hard that we cause other problems ;) # Don't try so hard that we cause other problems ;)
pass pass
tb = stb # original traceback del tb
del stb
def exception(self, fatal=0, info=None,
absuri_match=re.compile(r'\w+://[\w\.]+').match,
tag_search=re.compile('[a-zA-Z]>').search,
abort=1
):
if isinstance(info, tuple) and len(info) == 3:
t, v, tb = info
else:
t, v, tb = sys.exc_info()
if issubclass(t, Unauthorized):
self._unauthorized()
self._setBCIHeaders(t, tb)
self.setStatus(t) self.setStatus(t)
if self.status >= 300 and self.status < 400: if self.status >= 300 and self.status < 400:
if isinstance(v, str) and absuri_match(v) is not None: if isinstance(v, str) and absuri_match(v) is not None:
......
...@@ -1280,6 +1280,23 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -1280,6 +1280,23 @@ class HTTPResponseTests(unittest.TestCase):
self.assertEqual(len(lines), 1) self.assertEqual(len(lines), 1)
self.assertEqual(lines[0], 'Kilroy was here!') self.assertEqual(lines[0], 'Kilroy was here!')
def test__setBCIHeaders(self):
response = self._makeOne()
try:
raise AttributeError('ERROR VALUE')
except AttributeError:
t, v, tb = sys.exc_info()
response._setBCIHeaders(t, tb)
# required by Bobo Call Interface (BCI)
self.assertEqual(response.headers['bobo-exception-type'],
"<type 'exceptions.AttributeError'>")
self.assertEqual(response.headers['bobo-exception-value'],
'See the server error log for details')
self.failUnless('bobo-exception-file' in response.headers)
self.failUnless('bobo-exception-line' in response.headers)
finally:
del tb
def test_exception_Internal_Server_Error(self): def test_exception_Internal_Server_Error(self):
response = self._makeOne() response = self._makeOne()
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment