|
9 | 9 | 'Programming Language :: Python',
|
10 | 10 | 'Programming Language :: Python :: 2',
|
11 | 11 | 'Programming Language :: Python :: 2.7',
|
| 12 | + 'Programming Language :: Python :: 3', |
| 13 | + 'Programming Language :: Python :: 3.5', |
| 14 | + 'Programming Language :: Python :: 3.6', |
12 | 15 | 'Topic :: Internet :: WWW/HTTP'],
|
13 |
| - 'description': 'Easily create multi-purpose decorators that have access to the FQN of the original function.', |
| 16 | + 'description': 'Easily create multi-purpose decorators that have access to ' |
| 17 | + 'the FQN of the original function.', |
14 | 18 | 'include_package_data': True,
|
15 |
| - 'install_requires': ['pkgversion'], |
16 |
| - 'long_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 <usage_advanced_non_keyword_decorators>` 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.. end_usage\n', |
| 19 | + 'install_requires': [], |
| 20 | + 'long_description': 'FQN Decorators\n' |
| 21 | + '==============\n' |
| 22 | + '\n' |
| 23 | + '.. image:: ' |
| 24 | + 'https://secure.travis-ci.org/kpn-digital/py-fqn-decorators.svg?branch=master\n' |
| 25 | + ' :target: ' |
| 26 | + 'http://travis-ci.org/kpn-digital/py-fqn-decorators?branch=master\n' |
| 27 | + '\n' |
| 28 | + '.. image:: ' |
| 29 | + 'https://img.shields.io/codecov/c/github/kpn-digital/py-fqn-decorators/master.svg\n' |
| 30 | + ' :target: ' |
| 31 | + 'http://codecov.io/github/kpn-digital/py-fqn-decorators?branch=master\n' |
| 32 | + '\n' |
| 33 | + '.. image:: ' |
| 34 | + 'https://img.shields.io/pypi/v/fqn-decorators.svg\n' |
| 35 | + ' :target: ' |
| 36 | + 'https://pypi.python.org/pypi/fqn-decorators\n' |
| 37 | + '\n' |
| 38 | + '.. image:: ' |
| 39 | + 'https://readthedocs.org/projects/fqn-decorators/badge/?version=latest\n' |
| 40 | + ' :target: ' |
| 41 | + 'http://fqn-decorators.readthedocs.org/en/latest/?badge=latest\n' |
| 42 | + '\n' |
| 43 | + '\n' |
| 44 | + 'Installation\n' |
| 45 | + '------------\n' |
| 46 | + '.. start_installation\n' |
| 47 | + '\n' |
| 48 | + 'At the command line::\n' |
| 49 | + '\n' |
| 50 | + ' $ pip install fqn-decorators\n' |
| 51 | + '\n' |
| 52 | + '\n' |
| 53 | + '.. end_installation\n' |
| 54 | + '\n' |
| 55 | + 'Usage\n' |
| 56 | + '-----\n' |
| 57 | + '.. start_usage\n' |
| 58 | + '.. py:currentmodule:: fqn_decorators.decorators\n' |
| 59 | + '\n' |
| 60 | + 'Introduction\n' |
| 61 | + '------------\n' |
| 62 | + '\n' |
| 63 | + 'By extending the :class:`~Decorator` class you can ' |
| 64 | + 'create simple decorators.\n' |
| 65 | + 'Implement the :meth:`~Decorator.before` and/or ' |
| 66 | + ':meth:`~Decorator.after` methods to perform actions ' |
| 67 | + 'before or after execution of the decorated item.\n' |
| 68 | + 'The :meth:`~Decorator.before` method can access the ' |
| 69 | + 'arguments of the decorated item by changing the ' |
| 70 | + ':attr:`~Decorator.args` and :attr:`~Decorator.kwargs` ' |
| 71 | + 'attributes.\n' |
| 72 | + 'The :meth:`~Decorator.after` method can access or change ' |
| 73 | + 'the result using the :attr:`~Decorator.result` ' |
| 74 | + 'attribute.\n' |
| 75 | + 'The :meth:`~Decorator.exception` method can be used for ' |
| 76 | + 'do something with an Exception that has been raised.\n' |
| 77 | + 'In all three methods the :attr:`~Decorator.fqn` and ' |
| 78 | + ':attr:`~Decorator.func` attributes are available.\n' |
| 79 | + '\n' |
| 80 | + 'Simple decorator\n' |
| 81 | + '----------------\n' |
| 82 | + '\n' |
| 83 | + 'Create a simple decorator::\n' |
| 84 | + '\n' |
| 85 | + ' import fqn_decorators\n' |
| 86 | + ' import time\n' |
| 87 | + '\n' |
| 88 | + ' class time_it(fqn_decorators.Decorator):\n' |
| 89 | + '\n' |
| 90 | + ' def before(self):\n' |
| 91 | + ' self.start = time.time()\n' |
| 92 | + '\n' |
| 93 | + ' def after(self):\n' |
| 94 | + ' duration = time.time() - self.start\n' |
| 95 | + ' print("{0} took {1} ' |
| 96 | + 'seconds".format(self.fqn, duration))\n' |
| 97 | + '\n' |
| 98 | + '\n' |
| 99 | + ' @time_it\n' |
| 100 | + ' def my_function():\n' |
| 101 | + ' time.sleep(1)\n' |
| 102 | + '\n' |
| 103 | + ' >>>my_function()\n' |
| 104 | + ' __main__.my_function took 1.00293397903 seconds\n' |
| 105 | + '\n' |
| 106 | + '\n' |
| 107 | + 'Decorator with arguments\n' |
| 108 | + '------------------------\n' |
| 109 | + '\n' |
| 110 | + 'It is also very easy to create a decorator with ' |
| 111 | + 'arguments.\n' |
| 112 | + '\n' |
| 113 | + '.. note::\n' |
| 114 | + ' It is not possible to create decorators with ' |
| 115 | + '*non-keyworded* arguments.\n' |
| 116 | + ' To create a decorator that supports non-keyworded ' |
| 117 | + 'arguments see the :ref:`Advanced Usage ' |
| 118 | + '<usage_advanced_non_keyword_decorators>` section.\n' |
| 119 | + '\n' |
| 120 | + 'Example::\n' |
| 121 | + '\n' |
| 122 | + ' import fqn_decorators\n' |
| 123 | + ' import time\n' |
| 124 | + '\n' |
| 125 | + ' class threshold(fqn_decorators.Decorator):\n' |
| 126 | + '\n' |
| 127 | + ' def before(self):\n' |
| 128 | + ' self.start = time.time()\n' |
| 129 | + '\n' |
| 130 | + ' def after(self):\n' |
| 131 | + ' duration = time.time() - self.start\n' |
| 132 | + " treshold = self.params.get('threshold')\n" |
| 133 | + ' if threshold and duration > threshold:\n' |
| 134 | + " raise Exception('Execution took longer " |
| 135 | + "than the threshold')\n" |
| 136 | + '\n' |
| 137 | + '\n' |
| 138 | + ' @threshold(threshold=2)\n' |
| 139 | + ' def my_function():\n' |
| 140 | + ' time.sleep(3)\n' |
| 141 | + '\n' |
| 142 | + ' >>> my_function()\n' |
| 143 | + ' Exception: Execution took longer than the threshold\n' |
| 144 | + '\n' |
| 145 | + '\n' |
| 146 | + 'Async Decorator\n' |
| 147 | + '---------------\n' |
| 148 | + '\n' |
| 149 | + "There's also support for decorating coroutines (or any " |
| 150 | + 'awaitable), for Python >=3.5 only.\n' |
| 151 | + '\n' |
| 152 | + 'The implementation is the same as with the sync version, ' |
| 153 | + 'just inherit from\n' |
| 154 | + ':class:`~fqn_decorators.async.AsyncDecorator` instead.\n' |
| 155 | + '\n' |
| 156 | + 'Example::\n' |
| 157 | + '\n' |
| 158 | + ' import asyncio\n' |
| 159 | + ' import time\n' |
| 160 | + ' from fqn_decorators.async import AsyncDecorator\n' |
| 161 | + '\n' |
| 162 | + ' class time_it_async(AsyncDecorator):\n' |
| 163 | + '\n' |
| 164 | + ' def before(self):\n' |
| 165 | + ' self.start = time.time()\n' |
| 166 | + '\n' |
| 167 | + ' def after(self):\n' |
| 168 | + ' duration = time.time() - self.start\n' |
| 169 | + ' print("{0} took {1} ' |
| 170 | + 'seconds".format(self.fqn, duration))\n' |
| 171 | + '\n' |
| 172 | + ' @time_it_async\n' |
| 173 | + ' async def coro():\n' |
| 174 | + ' await asyncio.sleep(1)\n' |
| 175 | + '\n' |
| 176 | + ' >>> loop = asyncio.get_event_loop()\n' |
| 177 | + ' >>> loop.run_until_complete(coro())\n' |
| 178 | + ' __main__.coro took 1.001493215560913 seconds\n' |
| 179 | + '\n' |
| 180 | + '\n' |
| 181 | + '.. end_usage\n', |
17 | 182 | 'name': 'fqn-decorators',
|
18 | 183 | 'packages': ['fqn_decorators'],
|
19 | 184 | 'tests_require': ['tox'],
|
20 |
| - 'url': 'ssh://git@github.com:kpn-digital/py-fqn-decorators.git', |
21 |
| - 'version': '1.0.0', |
| 185 | + 'url': 'https://github.com/kpn-digital/py-fqn-decorators', |
| 186 | + 'version': '1.2.0', |
22 | 187 | 'zip_safe': False})
|
0 commit comments