{ "info": { "author": "Michael Foord", "author_email": "michael@voidspace.org.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.4", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.0", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "If you're a library or framework creator then it is nice to be able to create\r\nAPIs that can be used *either* as decorators or context managers.\r\n\r\nThe contextdecorator module is a backport of new features added to the\r\n`contextlib module `_ in \r\nPython 3.2. contextdecorator works with Python 2.4+ including Python 3.\r\n\r\nContext managers inheriting from ``ContextDecorator`` have to implement \r\n``__enter__`` and ``__exit__`` as normal. \r\n`__exit__ `_ \r\nretains its optional exception handling even when used as a decorator.\r\n\r\nExample::\r\n\r\n from contextdecorator import ContextDecorator\r\n\r\n class mycontext(ContextDecorator):\r\n def __enter__(self):\r\n print 'Starting'\r\n return self\r\n\r\n def __exit__(self, *exc):\r\n print 'Finishing'\r\n return False\r\n\r\n >>> @mycontext()\r\n ... def function():\r\n ... print 'The bit in the middle'\r\n ...\r\n >>> function()\r\n Starting\r\n The bit in the middle\r\n Finishing\r\n\r\n >>> with mycontext():\r\n ... print 'The bit in the middle'\r\n ...\r\n Starting\r\n The bit in the middle\r\n Finishing\r\n\r\nExisting context managers that already have a base class can be extended by\r\nusing ``ContextDecorator`` as a mixin class::\r\n\r\n from contextdecorator import ContextDecorator\r\n\r\n class mycontext(ContextBaseClass, ContextDecorator):\r\n def __enter__(self):\r\n return self\r\n\r\n def __exit__(self, *exc):\r\n return False\r\n\r\ncontextdecorator also contains an implementation of `contextlib.contextmanager\r\n`_\r\nthat uses ``ContextDecorator``. The context managers it creates can be used as\r\ndecorators as well as in with statements. ::\r\n\r\n from contextdecorator import contextmanager\r\n \r\n @contextmanager\r\n def mycontext(*args):\r\n print 'Started'\r\n try:\r\n yield\r\n finally:\r\n print 'Finished!'\r\n\r\n >>> @mycontext('some', 'args')\r\n ... def function():\r\n ... print 'In the middle'\r\n ... \r\n Started\r\n In the middle\r\n Finished!\r\n \r\n >>> with mycontext('some', 'args'):\r\n ... print 'In the middle'\r\n ... \r\n Started\r\n In the middle\r\n Finished!\r\n\r\nRepository and issue tracker:\r\n\r\n* `contextdecorator on google code `_\r\n\r\nThe project is available for download from `PyPI\r\n`_\r\nso it can be easily installed:\r\n\r\n | ``pip install -U contextdecorator``\r\n | ``easy_install -U contextdecorator``\r\n\r\nThe tests require `unittest2 `_\r\nto run.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "decorator,with,context", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "contextdecorator", "package_url": "https://pypi.org/project/contextdecorator/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/contextdecorator/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/contextdecorator/0.10.0/", "requires_dist": null, "requires_python": null, "summary": "Create APIs that work as decorators and as context managers.", "version": "0.10.0" }, "last_serial": 788400, "releases": { "0.0": [], "0.10.0": [ { "comment_text": "", "digests": { "md5": "779973c0e9502c9fdc7add9628cbb58d", "sha256": "44645affa722c72b4931d48a4ff9265a8df19373e20e12334bca4ec2104f8619" }, "downloads": -1, "filename": "contextdecorator-0.10.0.tar.gz", "has_sig": false, "md5_digest": "779973c0e9502c9fdc7add9628cbb58d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4584, "upload_time": "2010-06-30T14:38:17", "url": "https://files.pythonhosted.org/packages/77/43/03f264fa07fb0f794bfe174751eb6e6e294a89fc53af87ea1cb0df26ac18/contextdecorator-0.10.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "2ef3ed0500116cc2ee42714b38e2c893", "sha256": "e6ee12393ea89a6222152cd103d8f55397ff13e08cb513f48ccc2739768b9171" }, "downloads": -1, "filename": "contextdecorator-0.10.0.zip", "has_sig": false, "md5_digest": "2ef3ed0500116cc2ee42714b38e2c893", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6775, "upload_time": "2010-06-30T14:38:56", "url": "https://files.pythonhosted.org/packages/f6/8b/bb30402c613cb77ab5822ed71ac00f4349231519161ed0265bfb5f5aaae4/contextdecorator-0.10.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "779973c0e9502c9fdc7add9628cbb58d", "sha256": "44645affa722c72b4931d48a4ff9265a8df19373e20e12334bca4ec2104f8619" }, "downloads": -1, "filename": "contextdecorator-0.10.0.tar.gz", "has_sig": false, "md5_digest": "779973c0e9502c9fdc7add9628cbb58d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4584, "upload_time": "2010-06-30T14:38:17", "url": "https://files.pythonhosted.org/packages/77/43/03f264fa07fb0f794bfe174751eb6e6e294a89fc53af87ea1cb0df26ac18/contextdecorator-0.10.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "2ef3ed0500116cc2ee42714b38e2c893", "sha256": "e6ee12393ea89a6222152cd103d8f55397ff13e08cb513f48ccc2739768b9171" }, "downloads": -1, "filename": "contextdecorator-0.10.0.zip", "has_sig": false, "md5_digest": "2ef3ed0500116cc2ee42714b38e2c893", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6775, "upload_time": "2010-06-30T14:38:56", "url": "https://files.pythonhosted.org/packages/f6/8b/bb30402c613cb77ab5822ed71ac00f4349231519161ed0265bfb5f5aaae4/contextdecorator-0.10.0.zip" } ] }