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 (#3)
  • Loading branch information
davisagli authored and hannosch committed Feb 5, 2017
1 parent e708274 commit 8cd7601
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 8cd7601

Please sign in to comment.