Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettyexc

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettyexc

Toolkit for human-friendly exception interface.

  • 0.6.0
  • PyPI
  • Socket score

Maintainers
1

Pretty-Exception for Python


.. image:: https://travis-ci.org/youknowone/prettyexc.svg?branch=master
    :target: https://travis-ci.org/youknowone/prettyexc

prettyexc provides common exception representation to make human-readable exception in easy way.

You can install the package from PyPI

    $ pip install prettyexc


Example
-------

Prelude::
	>>> 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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc