{ "info": { "author": "Sergey Arkhipov", "author_email": "serge@aerialsounds.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "pep3134\n=======\n\n|Build Status| |Code Coverage| |Static Analysis| |PyPI Package|\n\nThis library is intended to give you an ability to use exception chaining and embedded tracebacks with both\nPython 2 and Python 3 (>= 3.3 only). Exception Chaining and Embedded Tracebacks are also well known as\nPEP3134 that's why I have such geeky name for that library.\n\nNo, it is not. Geeky name is kinda ``PEP3134 (feat. PEP409, PEP415 Remix)`` but I think it is an overkill.\n\nIf you want to get more about exception chaining and tracebacks please refer to the documentation for\n`Python 3 `__ with modifications done \nin `Python 3.3 `__.\n\nShort excerpt for those who still sit with Python 2 as me.\n\n1. Exceptions have new attributes: ``__traceback__``, ``__context__``, ``__suppress_context__`` \n and ``__cause__``.\n2. Exceptions have new syntax for explicit chaining: \n ``raise CustomError(\"Cannot read settings\") from IOError(\"Cannot open /etc/settings\")``.\n3. Exceptions always have their own tracebacks attached in ``__traceback__`` attribute.\n4. If exception was raised without explicit cause, it has its own context \n (say, from ``sys.exc_info()``) in ``__context__`` attribute. In this case ``__cause__`` \n keeps ``None``.\n5. If exception was raised by implicit cause, then ``__suppress_context__`` is ``False``.\n6. If exception was raised with explicit cause (``raise ... from ...``) then\n ``__cause__`` has a cause, ``__suppress_context__`` is ``True`` and ``__context__`` is\n (suddenly) ``None``.\n\nSo this is pretty convenient to have chaining if you want to build human-readable error messages\nafterwards, right? \n\nThis library helps you to keep the same ``__context__``, ``__cause__`` and ``__suppress_context__``\nbehavior with both Python 2 and Python 3.\n\nI did not mentioned ``__traceback__``. This is a reason\n\n\n\n``__traceback__`` in Python 2\n-----------------------------\n\nTracebacks are very convenient data structure to work with but really irritating and magical\nif you want to deal with it using pure Python, without patching code or hacking interpreter \ninternals. If you want to see some magic, please checkout, let's say, \n`Jinja sources `__. Armin is rather\ngood but I am trying to escape magic if possible.\n\nI cannot keep the same tracebacks to any exceptions even if I want because it requires to do some\nwork on interpreter internals. But anyway this method will return you something.\n\nThe rule of thumb is: if it returns an object, it is the proper object you expect. If it returns None\nthen no luck. Moreover: ``__traceback__`` implemented as property so sometimes it raises traceback but afterwards\nit returns ``None`` on the same object. Unfortunately I do not know a good way how to deal with it.\n\nBut I can you give some guarantees:\n\n1. ``__traceback__`` on implicit (``__context__``) and explicit causes (``__cause__``) always correct.\n2. ``__traceback__`` in the associated ``except`` clause is always correct.\n3. Sometimes it works in other cases but do not rely on that.\n\nThis works like this because of _fixed_ ``sys.exc_info()`` behavior. Let's check one example.\n\n.. code-block:: python\n\n import sys\n\n def example():\n try:\n raise KeyError(\"WOW SUCH ERROR\")\n except KeyError:\n first = sys.exc_info()\n \n second = sys.exc_info()\n return first, second\n \n first, second = example()\n assert first == second\n\nIt works as a charm in Python2 but raises ``AssertionError`` in Python3. So it is not possible to\nkeep tracebacks in the same way in both Python2 and Python3. Sad story.\n\nSo if we will rewrite given example with PEP3134\n\n.. code-block:: python\n\n import sys\n import pep3134\n \n def example():\n error = -1\n try:\n pep3134.raise_(KeyError(\"WOW SUCH ERROR\"))\n except KeyError as err:\n error = err\n first = sys.exc_info()\n assert error.__traceback__ is first[2]\n \n second = sys.exc_info()\n assert error.__traceback__ is not second[2] # works in Python 2 only\n \n example()\n\n\nThis is the only pitfall. Causes, as I mentioned, work well.\n\n\n\nPEP3134 library\n---------------\n\nThis library gives you 3 functions you can use. Only 3 so no need to have full documentation on\nany external source.\n\n\n\n``pep3134.raise_``\n------------------\n\nWorks with the same signature as ``raise`` clause in both Python 2 and Python 3. Just a reminder:\n\n.. code-block:: python\n\n raise exc_type, [exc_value, [exc_traceback]]\n\nRaises exceptions on the same problems.\n\n\n\n``pep3134.reraise``\n-------------------\n\nWorks in the same way as ``raise`` clause without any arguments does in Python 2.\n\n\n\n``pep3134.raise_from``\n----------------------\n\nWorks absolutely in the same way as ``raise ... from ...`` clause does in Python 3.\n\n\n\n.. |Build Status| image:: https://travis-ci.org/9seconds/pep3134.svg?branch=master\n :target: https://travis-ci.org/9seconds/pep3134\n\n.. |Code Coverage| image:: https://coveralls.io/repos/9seconds/pep3134/badge.png?branch=master \n :target: https://coveralls.io/r/9seconds/pep3134?branch=master\n\n.. |Static Analysis| image:: https://landscape.io/github/9seconds/pep3134/master/landscape.png\n :target: https://landscape.io/github/9seconds/pep3134/master\n\n.. |PyPI Package| image:: https://badge.fury.io/py/pep3134.svg\n :target: http://badge.fury.io/py/pep3134", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/9seconds/pep3134/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "pep3134", "package_url": "https://pypi.org/project/pep3134/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pep3134/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/9seconds/pep3134/" }, "release_url": "https://pypi.org/project/pep3134/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "Backport of PEP 3134 (with PEP 415 and PEP 409) to Python 2 as close as possible", "version": "0.1.4" }, "last_serial": 1203215, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "95ce2c254f329b2bffd34240e5a39484", "sha256": "e73a389d9b51d36f2ad22c7d6deaec435ee7f3d5559787180161556bf62aff31" }, "downloads": -1, "filename": "pep3134-0.1.0-py2-none-any.whl", "has_sig": false, "md5_digest": "95ce2c254f329b2bffd34240e5a39484", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5137, "upload_time": "2014-08-25T19:07:25", "url": "https://files.pythonhosted.org/packages/ce/82/fc56dbd98d006d0026bf2b62d66a085f220f0e61846d7bc19b62e132bcce/pep3134-0.1.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3ab43eec2e5076e2b08f346b911c2497", "sha256": "7d60fd2758176f83bf689e91263346c368ad20b8cd00481c93c4f890d06ad702" }, "downloads": -1, "filename": "pep3134-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3ab43eec2e5076e2b08f346b911c2497", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4978, "upload_time": "2014-08-25T19:07:23", "url": "https://files.pythonhosted.org/packages/f8/42/527804054d8207d230a941a9fb3cf1e745143de2d768931b0783f1f308bd/pep3134-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "aea6ff9ea84327d394c4a92f5cc45890", "sha256": "48ee989ec6f04c2b402581ce3437ee69cc2959ae588164e23dbc5b5d33b0f763" }, "downloads": -1, "filename": "pep3134-0.1.1-py2-none-any.whl", "has_sig": false, "md5_digest": "aea6ff9ea84327d394c4a92f5cc45890", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5135, "upload_time": "2014-08-25T19:13:56", "url": "https://files.pythonhosted.org/packages/35/35/8dd093ee097025f6f940708747bec259d94b40de932da9ee2013f7d90abe/pep3134-0.1.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "502628baecb0c5256fbab9e3e87218cb", "sha256": "891389fa25eeecceb746d8c24fb1b141ec7434ac27ef20fae341223c91c0a8a8" }, "downloads": -1, "filename": "pep3134-0.1.1.tar.gz", "has_sig": false, "md5_digest": "502628baecb0c5256fbab9e3e87218cb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4999, "upload_time": "2014-08-25T19:13:53", "url": "https://files.pythonhosted.org/packages/6f/d4/a752805541e2a67e9eea321bf2cf86abe0d07221014675d3564eeccb0fed/pep3134-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "296e7298b10a2083d0e25677cbb8b72e", "sha256": "31ab7b267f6c3e00f222c222380c331b24a6dfc77ed2569478e33978cd7ea61a" }, "downloads": -1, "filename": "pep3134-0.1.2-py2-none-any.whl", "has_sig": false, "md5_digest": "296e7298b10a2083d0e25677cbb8b72e", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5434, "upload_time": "2014-08-26T03:16:08", "url": "https://files.pythonhosted.org/packages/36/55/9354aa3a7691b2467142f548d4c26bbe4d1ecd627bd6c5f4426622812f2d/pep3134-0.1.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "696dfd975c58f7a19b876e8b620e8365", "sha256": "c86dfd5ce2f1df84513198f2afed2e95d34b3a920067b34466c8c3e581677498" }, "downloads": -1, "filename": "pep3134-0.1.2.tar.gz", "has_sig": false, "md5_digest": "696dfd975c58f7a19b876e8b620e8365", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5252, "upload_time": "2014-08-26T03:16:05", "url": "https://files.pythonhosted.org/packages/fe/dc/2280b6b53bd93bdce7b675420a6cc7c7b278dfd05b0b1b3aee9f47549b2d/pep3134-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "db7d7eaf5975386ff88f3969f1dfb23f", "sha256": "d3d300533103a912edeff263401aa36378e2e1965da19e1fe1b51ce2e9fe807e" }, "downloads": -1, "filename": "pep3134-0.1.3-py2-none-any.whl", "has_sig": false, "md5_digest": "db7d7eaf5975386ff88f3969f1dfb23f", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5604, "upload_time": "2014-08-26T15:56:41", "url": "https://files.pythonhosted.org/packages/62/37/e164f2c251112bf95d124866bc2946f3fc952cbd674cabb8ef1780a9f4e5/pep3134-0.1.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "78fb827b71671a880a6f957048701717", "sha256": "9164e7d95ea759478bdf145d882a8aa888597db0621ecc4665f8b5320a408dbd" }, "downloads": -1, "filename": "pep3134-0.1.3.tar.gz", "has_sig": false, "md5_digest": "78fb827b71671a880a6f957048701717", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5413, "upload_time": "2014-08-26T15:56:39", "url": "https://files.pythonhosted.org/packages/ae/ce/3820c1d2233ba1e6cd2e2c57850b82a699c340af063cb38d93c6c9b4b9a5/pep3134-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "bfa06a990938e8f9d04f1a050b4849a7", "sha256": "3a7270e41202afe0c849794baa27e2f503ebffa530456a1fd70e471a6f39dca3" }, "downloads": -1, "filename": "pep3134-0.1.4-py2-none-any.whl", "has_sig": false, "md5_digest": "bfa06a990938e8f9d04f1a050b4849a7", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5422, "upload_time": "2014-08-26T18:08:35", "url": "https://files.pythonhosted.org/packages/9c/e6/d973121fd05d0bc86019e5d2cef3dd94ca65369eece1158f7e026edf098d/pep3134-0.1.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e307d0a6e691912a9336210d406c1abc", "sha256": "2f879413caf4d4c502fbabcd25dca859a25f4ca3169672b6156b2ed0201e2584" }, "downloads": -1, "filename": "pep3134-0.1.4.tar.gz", "has_sig": false, "md5_digest": "e307d0a6e691912a9336210d406c1abc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5402, "upload_time": "2014-08-26T18:08:31", "url": "https://files.pythonhosted.org/packages/65/bb/f337e80c82bf921cc04ec66862f03d1d88471da5687eeabf1623965b0b31/pep3134-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bfa06a990938e8f9d04f1a050b4849a7", "sha256": "3a7270e41202afe0c849794baa27e2f503ebffa530456a1fd70e471a6f39dca3" }, "downloads": -1, "filename": "pep3134-0.1.4-py2-none-any.whl", "has_sig": false, "md5_digest": "bfa06a990938e8f9d04f1a050b4849a7", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 5422, "upload_time": "2014-08-26T18:08:35", "url": "https://files.pythonhosted.org/packages/9c/e6/d973121fd05d0bc86019e5d2cef3dd94ca65369eece1158f7e026edf098d/pep3134-0.1.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e307d0a6e691912a9336210d406c1abc", "sha256": "2f879413caf4d4c502fbabcd25dca859a25f4ca3169672b6156b2ed0201e2584" }, "downloads": -1, "filename": "pep3134-0.1.4.tar.gz", "has_sig": false, "md5_digest": "e307d0a6e691912a9336210d406c1abc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5402, "upload_time": "2014-08-26T18:08:31", "url": "https://files.pythonhosted.org/packages/65/bb/f337e80c82bf921cc04ec66862f03d1d88471da5687eeabf1623965b0b31/pep3134-0.1.4.tar.gz" } ] }