Skip to content

Commit

Permalink
add support for finding the zException HTTPException class with the s…
Browse files Browse the repository at this point in the history
…ame name as an arbitrary exception class
  • Loading branch information
davisagli committed Feb 3, 2017
1 parent e708274 commit e8b812b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,9 @@ Changelog

- Add a `setHeader` method to add a response header to an HTTPException.

- `upgradeException` now also supports finding an HTTPException class
with the same name as a non-HTTPException class.

3.4 (2016-09-08)
----------------

Expand Down
4 changes: 4 additions & 0 deletions src/zExceptions/__init__.py
Expand Up @@ -528,4 +528,8 @@ def upgradeException(t, v):
else:
v = t, v
t = InternalError
else:
etype = convertExceptionType(t.__name__)
if etype is not None:
t = etype
return t, v
9 changes: 9 additions & 0 deletions src/zExceptions/tests/test___init__.py
Expand Up @@ -172,3 +172,12 @@ def test_string_miss_returns_InternalError(self):
t, v = self._callFUT('Nonesuch', 'TEST')
self.assertEqual(t, InternalError)
self.assertEqual(v, ('Nonesuch', 'TEST'))

def test_non_string_match_by_name(self):
class NotFound(Exception):
pass

t, v = self._callFUT(NotFound, 'TEST')
from zExceptions import NotFound as zExceptions_NotFound
self.assertIs(t, zExceptions_NotFound)
self.assertEqual(v, 'TEST')

0 comments on commit e8b812b

Please sign in to comment.