Log message for revision 113761: - small refactoring for better readability: moved some code in separate _setBCIHeaders method
Changed: U Zope/trunk/src/ZPublisher/HTTPResponse.py U Zope/trunk/src/ZPublisher/tests/testHTTPResponse.py -=- Modified: Zope/trunk/src/ZPublisher/HTTPResponse.py =================================================================== --- Zope/trunk/src/ZPublisher/HTTPResponse.py 2010-06-22 13:28:57 UTC (rev 113760) +++ Zope/trunk/src/ZPublisher/HTTPResponse.py 2010-06-22 13:39:12 UTC (rev 113761) @@ -755,21 +755,7 @@ m = m + '<p>\nNo Authorization header found.</p>' raise Unauthorized, m - 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() - - stb = tb # note alias between tb and stb - + def _setBCIHeaders(self, t, tb): try: # Try to capture exception info for bci calls et = translate(str(t), nl2sp) @@ -794,13 +780,26 @@ self.setHeader('bobo-exception-file', ef) self.setHeader('bobo-exception-line', el) - except: - # Dont try so hard that we cause other problems ;) + # Don't try so hard that we cause other problems ;) pass - tb = stb # original traceback - del stb + del tb + + 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) if self.status >= 300 and self.status < 400: if isinstance(v, str) and absuri_match(v) is not None: Modified: Zope/trunk/src/ZPublisher/tests/testHTTPResponse.py =================================================================== --- Zope/trunk/src/ZPublisher/tests/testHTTPResponse.py 2010-06-22 13:28:57 UTC (rev 113760) +++ Zope/trunk/src/ZPublisher/tests/testHTTPResponse.py 2010-06-22 13:39:12 UTC (rev 113761) @@ -1280,6 +1280,23 @@ self.assertEqual(len(lines), 1) 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): response = self._makeOne() try: _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org https://mail.zope.org/mailman/listinfo/zope-checkins