{ "info": { "author": "Liyu Gong", "author_email": "gongliyu@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "*decoutils*: Utilities for writing decorators\n\n[![Build Status](https://travis-ci.com/gongliyu/decoutils.svg?branch=master)](https://travis-ci.com/gongliyu/decoutils)\n[![Documentation Status](https://readthedocs.org/projects/decoutils/badge/?version=latest)](https://decoutils.readthedocs.io/en/latest/?badge=latest)\n[![Coverage Status](https://coveralls.io/repos/github/gongliyu/decoutils/badge.svg)](https://coveralls.io/github/gongliyu/decoutils)\n\n## Rationale\n\nPython *decorator*s are very useful. However, writing decorators with\narguments is not straightforward. Take the following function as an\nexample:\n\n``` python\nregister_plugin(plugin, arg1=1):\n print('registering ', plugin.__name__, ' with arg1=', arg1)\n```\nThis function registers a input function somewhere in the system. If this function could work as a decorator, that will be convinient. In order to make it a decorator, we just need it to return the input plugin trivially:\n``` python\nregister_plugin(plugin, arg1=1):\n print('registering ', plugin.__name__, ' with arg1=', arg1)\n return plugin\n\n@register_plugin\ndef plugin1(): pass\n```\nIt is pretty easy so far. What if we want *register_plugin* works as a decorator with arguments? That's to say, we want to use it as:\n\n``` python\n@register_plugin(arg1=2)\ndef plugin2(): pass\n```\n\nIn order to accomplish this goal, we need to wrap the function\n*register_plugin* so that it return a decorated plugin if the first\ninput is a callable object, otherwise return a decorator with\narguments. The *decoutils.decorator_with_args* is intend to abstract that wrapping, so that we can reuse it.\n\n\n## Installation\n\n### Install from PyPI\n\n``` shell\npip install decoutils\n```\n\n### Install from Anaconda\n\n``` shell\nconda install -c liyugong decoutils\n```\n\n## Simple example\nBasically, *decorator_with_args* enables a ordinary decorator function to be a decorator with arguments.\n``` python\n@decorator_with_args\ndef register_plugin(plugin, arg1=1):\n print('registering ', plugin.__name__, ' with arg1=', arg1)\n return plugin\n\n@register_plugin(arg1=10)\ndef plugin1(): pass\n```\n\nMoreover, *decorator_with_args* itself is also a decorator with arguments: one argument *return_original* which can be used to convert a non-decorator function to be a decorator\n``` python\n@decorator_with_args\ndef register_plugin(plugin, arg1=1):\n print('registering ', plugin.__name__, ' with arg1=', arg1)\n # Note here the function does not return the plugin, so it cannot work as a decorator originally\n\n@register_plugin(arg1=10)\ndef plugin1(): pass\n```\n\n*decorator_with_args* can also convert a function to decorator whose decorating target is not its first argument, e.g.\n\n``` python\ndecorator_with_args(target_pos=1)\ndef register_plugin(arg1, plugin):\n return plugin\n\n@register_plugin(100) # plugin2 will be registered with arg1=100\ndef plugin2(): pass\n```\n\n*return_original* control whether the resultant decorator return the original plugin, or the result of function *register_plugin*.\n\n\n## License\n\nThe *decoutils* package is released under the [MIT License](LICENSE)\n\n## Documentation\n\nhttps://decoutils.readthedocs.io\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gongliyu/decoutils", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "decoutils", "package_url": "https://pypi.org/project/decoutils/", "platform": "", "project_url": "https://pypi.org/project/decoutils/", "project_urls": { "Homepage": "https://github.com/gongliyu/decoutils" }, "release_url": "https://pypi.org/project/decoutils/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "Common interface for archive manipulation", "version": "0.0.3" }, "last_serial": 4661199, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "dc8fdfbcb030fd42d7834c6eeb73e7f2", "sha256": "b4aa5798b863c1056b002d8f9599e51a0dd93cfe4c39ccc4dae98f25116817f3" }, "downloads": -1, "filename": "decoutils-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dc8fdfbcb030fd42d7834c6eeb73e7f2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3120, "upload_time": "2018-12-14T17:29:34", "url": "https://files.pythonhosted.org/packages/86/3b/506ee8e8bef87e2c80d91879952c7db84abe12647cf8cec3dc8221cfe049/decoutils-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d608e89a14dddaebc4803b76ebf0f077", "sha256": "040dbd6e1fec19b8ee96f578384b1aff6eda2b9f075a8673dfd265ae635f6c06" }, "downloads": -1, "filename": "decoutils-0.0.1.tar.gz", "has_sig": false, "md5_digest": "d608e89a14dddaebc4803b76ebf0f077", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3920, "upload_time": "2018-12-14T17:29:36", "url": "https://files.pythonhosted.org/packages/6e/5d/f87780707f070baef4a6d39d93328f33f4fc987051a7d74cc59831ad78cc/decoutils-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "49f0a29fa5dd45c85e21fe31e2ab3dc6", "sha256": "d91f2ab2fb671ead6544a6eaaf000b27f865e12570538208cb0f70aa61fd842d" }, "downloads": -1, "filename": "decoutils-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "49f0a29fa5dd45c85e21fe31e2ab3dc6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3122, "upload_time": "2018-12-14T17:46:54", "url": "https://files.pythonhosted.org/packages/2e/3b/01f36a337136b3954bf515004b0123f3a5cb8dc0f317871495b1fd0f36f2/decoutils-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "24c9e4fde9b9cc06fb3a445a1eade93c", "sha256": "81c35bb1071e6ae522b081df930fb81d9b94fbb72cb19cf661a44177a58d8a40" }, "downloads": -1, "filename": "decoutils-0.0.2.tar.gz", "has_sig": false, "md5_digest": "24c9e4fde9b9cc06fb3a445a1eade93c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3909, "upload_time": "2018-12-14T17:46:55", "url": "https://files.pythonhosted.org/packages/3b/51/69dc65e860caa4056009aba47fd1d3ae8a0bbd5335972ea0071617f60ac6/decoutils-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "6d01c9161ac8457f644bd00c7bbdcfea", "sha256": "bf2d52a1bf2753870c668370c7c96d790323c51b3e526fd638dfb80e0fd7cffd" }, "downloads": -1, "filename": "decoutils-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6d01c9161ac8457f644bd00c7bbdcfea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3402, "upload_time": "2019-01-04T17:51:34", "url": "https://files.pythonhosted.org/packages/56/53/33601de73b75f1f9d72df460c0d9b75ad92604a61afaf66ad89efe6430b5/decoutils-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "852be6366035db9141fe4d70a796eeab", "sha256": "680d2f21832e79f64044e84e28732dd96b3fafe8727ca248ab27a776786dd7d5" }, "downloads": -1, "filename": "decoutils-0.0.3.tar.gz", "has_sig": false, "md5_digest": "852be6366035db9141fe4d70a796eeab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4276, "upload_time": "2019-01-04T17:51:35", "url": "https://files.pythonhosted.org/packages/fb/ca/757c4de1ed8f37abacbc59c0c66c07d9aed0bf70a8b67edaefce7fc50b66/decoutils-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6d01c9161ac8457f644bd00c7bbdcfea", "sha256": "bf2d52a1bf2753870c668370c7c96d790323c51b3e526fd638dfb80e0fd7cffd" }, "downloads": -1, "filename": "decoutils-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6d01c9161ac8457f644bd00c7bbdcfea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3402, "upload_time": "2019-01-04T17:51:34", "url": "https://files.pythonhosted.org/packages/56/53/33601de73b75f1f9d72df460c0d9b75ad92604a61afaf66ad89efe6430b5/decoutils-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "852be6366035db9141fe4d70a796eeab", "sha256": "680d2f21832e79f64044e84e28732dd96b3fafe8727ca248ab27a776786dd7d5" }, "downloads": -1, "filename": "decoutils-0.0.3.tar.gz", "has_sig": false, "md5_digest": "852be6366035db9141fe4d70a796eeab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4276, "upload_time": "2019-01-04T17:51:35", "url": "https://files.pythonhosted.org/packages/fb/ca/757c4de1ed8f37abacbc59c0c66c07d9aed0bf70a8b67edaefce7fc50b66/decoutils-0.0.3.tar.gz" } ] }