{ "info": { "author": "Mattias Sluis", "author_email": "mattias.sluis@kpn.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP" ], "description": "FQN Decorators\n==============\n\n.. image:: https://secure.travis-ci.org/kpn-digital/py-fqn-decorators.svg?branch=master\n :target: http://travis-ci.org/kpn-digital/py-fqn-decorators?branch=master\n\n.. image:: https://img.shields.io/codecov/c/github/kpn-digital/py-fqn-decorators/master.svg\n :target: http://codecov.io/github/kpn-digital/py-fqn-decorators?branch=master\n\n.. image:: https://img.shields.io/pypi/v/fqn-decorators.svg\n :target: https://pypi.python.org/pypi/fqn-decorators\n\n.. image:: https://readthedocs.org/projects/fqn-decorators/badge/?version=latest\n :target: http://fqn-decorators.readthedocs.org/en/latest/?badge=latest\n\n\nInstallation\n------------\n.. start_installation\n\nAt the command line::\n\n $ pip install fqn-decorators\n\n\n.. end_installation\n\nUsage\n-----\n.. start_usage\n.. py:currentmodule:: fqn_decorators.decorators\n\nIntroduction\n------------\n\nBy extending the :class:`~Decorator` class you can create simple decorators.\nImplement the :meth:`~Decorator.before` and/or :meth:`~Decorator.after` methods to perform actions before or after execution of the decorated item.\nThe :meth:`~Decorator.before` method can access the arguments of the decorated item by changing the :attr:`~Decorator.args` and :attr:`~Decorator.kwargs` attributes.\nThe :meth:`~Decorator.after` method can access or change the result using the :attr:`~Decorator.result` attribute.\nThe :meth:`~Decorator.exception` method can be used for do something with an Exception that has been raised.\nIn all three methods the :attr:`~Decorator.fqn` and :attr:`~Decorator.func` attributes are available.\n\nSimple decorator\n----------------\n\nCreate a simple decorator::\n\n import fqn_decorators\n import time\n\n class time_it(fqn_decorators.Decorator):\n\n def before(self):\n self.start = time.time()\n\n def after(self):\n duration = time.time() - self.start\n print(\"{0} took {1} seconds\".format(self.fqn, duration))\n\n\n @time_it\n def my_function():\n time.sleep(1)\n\n >>>my_function()\n __main__.my_function took 1.00293397903 seconds\n\n\nDecorator with arguments\n------------------------\n\nIt is also very easy to create a decorator with arguments.\n\n.. note::\n It is not possible to create decorators with *non-keyworded* arguments.\n To create a decorator that supports non-keyworded arguments see the :ref:`Advanced Usage ` section.\n\nExample::\n\n import fqn_decorators\n import time\n\n class threshold(fqn_decorators.Decorator):\n\n def before(self):\n self.start = time.time()\n\n def after(self):\n duration = time.time() - self.start\n treshold = self.params.get('threshold')\n if threshold and duration > threshold:\n raise Exception('Execution took longer than the threshold')\n\n\n @threshold(threshold=2)\n def my_function():\n time.sleep(3)\n\n >>> my_function()\n Exception: Execution took longer than the threshold\n\n\nAsync Decorator\n---------------\n\nThere's also support for decorating coroutines (or any awaitable), for Python >=3.5 only.\n\nThe implementation is the same as with the sync version, just inherit from\n:class:`~fqn_decorators.async.AsyncDecorator` instead.\n\nExample::\n\n import asyncio\n import time\n from fqn_decorators.async import AsyncDecorator\n\n class time_it_async(AsyncDecorator):\n\n def before(self):\n self.start = time.time()\n\n def after(self):\n duration = time.time() - self.start\n print(\"{0} took {1} seconds\".format(self.fqn, duration))\n\n @time_it_async\n async def coro():\n await asyncio.sleep(1)\n\n >>> loop = asyncio.get_event_loop()\n >>> loop.run_until_complete(coro())\n __main__.coro took 1.001493215560913 seconds\n\n\n.. end_usage", "description_content_type": "", "docs_url": "https://pythonhosted.org/fqn-decorators/", "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kpn-digital/py-fqn-decorators", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "fqn-decorators", "package_url": "https://pypi.org/project/fqn-decorators/", "platform": "", "project_url": "https://pypi.org/project/fqn-decorators/", "project_urls": { "Homepage": "https://github.com/kpn-digital/py-fqn-decorators" }, "release_url": "https://pypi.org/project/fqn-decorators/1.2.3/", "requires_dist": null, "requires_python": "", "summary": "Easily create multi-purpose decorators that have access to the FQN of the original function.", "version": "1.2.3" }, "last_serial": 4660423, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "d4f0e385fb3ade3634262ca3ff6536dc", "sha256": "08153106f21482c29222296b11493642da7274cfd05ea756d06f5cb2d65113b6" }, "downloads": -1, "filename": "fqn-decorators-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d4f0e385fb3ade3634262ca3ff6536dc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13301, "upload_time": "2016-05-12T13:45:08", "url": "https://files.pythonhosted.org/packages/0e/e4/2a33ba95abf6399fb4bf9fc3bf8a1a62b81fb2691f96ac897c489c196e6b/fqn-decorators-1.0.0.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "361582f255ded9e9b8982c2b72442d62", "sha256": "d69407cedc527de98a9d2da5c8f6628e0f3874c1b67ce9cfea70017359ea0ff8" }, "downloads": -1, "filename": "fqn-decorators-1.0.2.tar.gz", "has_sig": false, "md5_digest": "361582f255ded9e9b8982c2b72442d62", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14282, "upload_time": "2016-10-12T09:10:44", "url": "https://files.pythonhosted.org/packages/d3/79/dfe534a0222bb5e7bef4d20639b292326a856834370d9bba6ceaa0bd4da9/fqn-decorators-1.0.2.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "4a92f1c3f2b49aefd21d964dedb528c7", "sha256": "bb7e1f1df0f0507b62e0a947f071b248328c5b4f85375a8964668e5270933d54" }, "downloads": -1, "filename": "fqn-decorators-1.1.0.tar.gz", "has_sig": false, "md5_digest": "4a92f1c3f2b49aefd21d964dedb528c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15820, "upload_time": "2017-07-11T11:08:49", "url": "https://files.pythonhosted.org/packages/30/4f/0a098dc818a7bc641f1672aa74915ad996077492205aa2c325cdba3fe3f0/fqn-decorators-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "df6b909f9d0a79ad86c4a55dfabe3922", "sha256": "2ff15ffb2e2808337ebbc18200bf2ba272f29a42f6b7252ca13f921b5f1819b2" }, "downloads": -1, "filename": "fqn-decorators-1.2.0.tar.gz", "has_sig": false, "md5_digest": "df6b909f9d0a79ad86c4a55dfabe3922", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15985, "upload_time": "2017-08-15T11:19:15", "url": "https://files.pythonhosted.org/packages/9d/01/7549db2b55bfd2fc47f56845cdb4cfb954c61acb6d52b1022d466c722bd7/fqn-decorators-1.2.0.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "c708a22474e530508a59addc7e11e72b", "sha256": "9277ef77af6f8a863dd99d8b1a4a96e4b37632f63d4841f79a01a73b7af12180" }, "downloads": -1, "filename": "fqn-decorators-1.2.3.tar.gz", "has_sig": false, "md5_digest": "c708a22474e530508a59addc7e11e72b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14719, "upload_time": "2019-01-04T14:38:03", "url": "https://files.pythonhosted.org/packages/88/f6/236e47f82c40209b449fdbf9f1bdb49b6c3892dd51817c22ab004b3b2c65/fqn-decorators-1.2.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c708a22474e530508a59addc7e11e72b", "sha256": "9277ef77af6f8a863dd99d8b1a4a96e4b37632f63d4841f79a01a73b7af12180" }, "downloads": -1, "filename": "fqn-decorators-1.2.3.tar.gz", "has_sig": false, "md5_digest": "c708a22474e530508a59addc7e11e72b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14719, "upload_time": "2019-01-04T14:38:03", "url": "https://files.pythonhosted.org/packages/88/f6/236e47f82c40209b449fdbf9f1bdb49b6c3892dd51817c22ab004b3b2c65/fqn-decorators-1.2.3.tar.gz" } ] }