Make any exception human readable in easy way.
Project description
Pretty-Exception for Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~
prettyexc provides common exception representation to make human-readable exception in easy way.
You can install the package from PyPI
$ pip install prettyexc
Example
-------
>>> from prettyexc import PrettyException
Put and get your arguments always
>>> class SimpleException(PrettyException):
... pass
...
>>> e = SimpleException('any', 'plain', 'args', code=200, description='OK')
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.SimpleException: "any","plain","args",code=200,description="OK"
SimpleException("any","plain","args",code=200,description="OK")
>>> print [e, e]
[<SimpleException("any","plain","args",code=200,description="OK")>, <SimpleException("any","plain","args",code=200,description="OK")>]
Set default message
>>> class MessageException(PrettyException):
... message = u'You should select a user'
...
>>> e = MessageException(user_id=10)
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.MessageException: You should select a user
>>> print [e, e]
[<MessageException(user_id=10)>, <MessageException(user_id=10)>]
Set message formatter
>>> class FormatException(PrettyException):
... message_format = u'User {user_id} has no permission.'
...
>>> e = FormatException(user_id=10)
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.FormatException: User 10 has no permission.
>>> print e.message
User 10 has no permission.
Patch existing exceptions
>>> from prettyexc import patch
>>> class AnException(Exception): pass
...
>>> patch(AnException, PrettyException)
>>> raise AnException(status=404)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.AnException: status=404
~~~~~~~~~~~~~~~~~~~~~~~~~~~
prettyexc provides common exception representation to make human-readable exception in easy way.
You can install the package from PyPI
$ pip install prettyexc
Example
-------
>>> from prettyexc import PrettyException
Put and get your arguments always
>>> class SimpleException(PrettyException):
... pass
...
>>> e = SimpleException('any', 'plain', 'args', code=200, description='OK')
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.SimpleException: "any","plain","args",code=200,description="OK"
SimpleException("any","plain","args",code=200,description="OK")
>>> print [e, e]
[<SimpleException("any","plain","args",code=200,description="OK")>, <SimpleException("any","plain","args",code=200,description="OK")>]
Set default message
>>> class MessageException(PrettyException):
... message = u'You should select a user'
...
>>> e = MessageException(user_id=10)
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.MessageException: You should select a user
>>> print [e, e]
[<MessageException(user_id=10)>, <MessageException(user_id=10)>]
Set message formatter
>>> class FormatException(PrettyException):
... message_format = u'User {user_id} has no permission.'
...
>>> e = FormatException(user_id=10)
>>> raise e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.FormatException: User 10 has no permission.
>>> print e.message
User 10 has no permission.
Patch existing exceptions
>>> from prettyexc import patch
>>> class AnException(Exception): pass
...
>>> patch(AnException, PrettyException)
>>> raise AnException(status=404)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
__main__.AnException: status=404
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
prettyexc-0.4.tar.gz
(5.8 kB
view details)
File details
Details for the file prettyexc-0.4.tar.gz.
File metadata
- Download URL: prettyexc-0.4.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f10e37766fc02f76d515a978f3978adcbb3b9faf89a1a35cb5b386481da12061
|
|
| MD5 |
15b2120202e75ea042bd8467f25271fb
|
|
| BLAKE2b-256 |
1abad984687e4664c53655a43d1e566b4816c935cfef9854403189b8c353b7fa
|