{ "info": { "author": "Jay Marcyes", "author_email": "jay@marcyes.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "Decorators\n==========\n\nThe problem\n-----------\n\nPython has a few forms for decorators, you can have a plain simple\ndecorator, with no arguments:\n\n.. code:: python\n\n @mydecorator\n def foo(): pass\n\nOr a decorator with some arguments:\n\n.. code:: python\n\n @mydecorator(1, 2)\n def foo(): pass\n\nYou can even decorate a class:\n\n.. code:: python\n\n @mydecorator\n class Foo(object): pass\n\nand each form is a little different to implement. This was frustrating\nif you wanted to create easy to use decorators where the developer\ndidn't need to worry about ``@mydecorator()`` working differently than\n``@mydecorator``.\n\ndecorators module\n-----------------\n\nThe ``decorators.Decorator`` class allows you to easily create broad\ndecorators that encompass all forms and all types (functions, methods,\nclasses) using the same interface:\n\n.. code:: python\n\n import decorators\n\n class mydecorator(decorators.Decorator):\n def decorate_func(self, func, *dec_args, **dec_kwargs):\n def decorator(*args, *kwargs):\n print \"You passed into the decorator these arguments\", dec_args, dec_kwargs\n print \"You passed into your function these arguments\", args, kwargs\n print \"Your function is\", func\n return func(*args, **kwargs)\n\n return decorator\n\n def decorate_class(self, klass, *dec_args, **dec_kwargs):\n print \"You passed into the decorator these arguments\", dec_args, dec_kwargs\n print \"Your class is\", klass\n return klass\n\nYou can then use this decorator:\n\n.. code:: python\n\n @mydecorator\n def foo(): print \"foo()\"\n\n @mydecorator(1, 2, boom=\"blam\")\n def bar(*args, **kwargs): print \"bar()\"\n\n @mydecorator\n class Baz(object): pass\n\n @mydecorator(1, 2, boom=\"blam\")\n class Che(object): pass\n\nNow, your decorator can decorate functions or classes, pass in\narguments, or not, and you never have to worry about the subtle\ndifferences between the decorators, and best of all, you don't have to\nduplicate code.\n\nOther decorators\n----------------\n\nThe ``Decorator`` class is good if you want to create a decorator that\nis totally flexible, if you want to enforce your decorator only being\nused for a function/method, you can use ``FuncDecorator``. If you want\nto only decorate a class, use ``ClassDecorator``, and if you want to\ndecorate every instance of a class, use ``InstanceDecorator``.\n\nWhatever child class you use, you override the ``decorate`` method to\nreturn your decorator function:\n\n.. code:: python\n\n import decorators\n\n class only_func(FuncDecorator):\n def decorate(self, func, *dec_a, **dec_kw):\n def decorator(*args, **kwargs):\n return func(*args, **kwargs)\n return decorator\n\n # this will work\n @only_func\n def foo(): pass\n\n # this will fail\n @only_func\n class Foo(object): pass\n\nInstallation\n------------\n\nUse pip:\n\n::\n\n pip install decorators\n\nOr, to get the latest and greatest from source:\n\n::\n\n pip install git+https://github.com/firstopinion/decorators#egg=decorators\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/firstopinion/decorators", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "decorators", "package_url": "https://pypi.org/project/decorators/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/decorators/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/firstopinion/decorators" }, "release_url": "https://pypi.org/project/decorators/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "Quickly create flexible Python decorators", "version": "0.1.1" }, "last_serial": 2570951, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "755857960408500848d1adc9d6495e98", "sha256": "9d1ebf1c0ecb0cbb376c00d4b218ef3a0cc3c54ccdfd4c0884a75826c08f3a86" }, "downloads": -1, "filename": "decorators-0.1.tar.gz", "has_sig": false, "md5_digest": "755857960408500848d1adc9d6495e98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3929, "upload_time": "2013-11-13T21:23:36", "url": "https://files.pythonhosted.org/packages/e9/57/4ce9b1211b65d69db884fa912d912845c129ed6db833fa0c00ce43fb1f4d/decorators-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "0e902a05b52f12edb3bdc70ed74dd97f", "sha256": "196ac810d92cffb65eea66ee76f54834904451dca9a1a06288f39f4855e30d44" }, "downloads": -1, "filename": "decorators-0.1.1.tar.gz", "has_sig": false, "md5_digest": "0e902a05b52f12edb3bdc70ed74dd97f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4966, "upload_time": "2017-01-12T23:30:41", "url": "https://files.pythonhosted.org/packages/5f/41/34f2e384f5eefbad1e84b0a28afc54f8846eb5ea6044a8bf2c7fb1b67416/decorators-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0e902a05b52f12edb3bdc70ed74dd97f", "sha256": "196ac810d92cffb65eea66ee76f54834904451dca9a1a06288f39f4855e30d44" }, "downloads": -1, "filename": "decorators-0.1.1.tar.gz", "has_sig": false, "md5_digest": "0e902a05b52f12edb3bdc70ed74dd97f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4966, "upload_time": "2017-01-12T23:30:41", "url": "https://files.pythonhosted.org/packages/5f/41/34f2e384f5eefbad1e84b0a28afc54f8846eb5ea6044a8bf2c7fb1b67416/decorators-0.1.1.tar.gz" } ] }