{ "info": { "author": "Marcel Hellkamp", "author_email": "marc@gsites.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "Contexter: A better contextlib\n===============================================================================\n\nContexter is a full replacement of the contextlib_ standard library module. It comes with more features, a nicer API and full support for Python 2.5 up to 3.x from a single source file.\n\nTo keep it short: Contexter allows you to nest and stack context managers in an easy and intuitive way.\n\nEnough talk, let's see an example:\n\n.. code:: python\n\n ''' Copy the content of one file to another\n and protect everything with a lock. '''\n\n with Contexter(lock) as ctx:\n in_file = ctx << open('a.txt')\n out_file = ctx << open('b.txt', 'w')\n out_file.write(in_file.read())\n\nLook at that. It's beautiful, isn't it? Let me explain: You call ``Contexter()`` with any number of context managers as arguments and later attach additional managers with the neat ``value = ctx << thing`` syntax. That's it. Only one level of indentation, no matter how many managers you need.\n\nJust for comparison:\n\n.. code:: python\n\n # Python 2.5 and 2.6\n with lock:\n with open('a.txt') as in_file:\n with open('b.txt', 'w') as out_file:\n out_file.write(in_file.read())\n\n # Starting with Python 2.7 and 3.2\n with lock, open('a.txt') as in_file, open('b.txt', 'w') as out_file:\n out_file.write(in_file.read())\n\n # Deprecated since Python 2.7 and 3.2\n with contextlib.nested(lock, open('a.txt'), open('b.txt', 'w')) as values:\n in_file, out_file = values\n out_file.write(in_file.read())\n\n # Since Python 3.3 (not backported to 2.7)\n with contextlib.ExitStack() as stack:\n stack.enter_context(lock)\n in_file = stack.enter_context(open('a.txt'))\n out_file = stack.enter_context(open('b.txt', 'w'))\n out_file.write(in_file.read())\n\n\nReplacing `contextlib.nested`_\n-------------------------------------------------------------------------------\n\nYou can use ``Contexter(*managers)`` as a drop-in replacement for ``contextlib.nested(*managers)``, just without the `confusing error prone quirks mentioned in the official documentation `_.\n\nReplacing `contextlib.closing`_\n-------------------------------------------------------------------------------\n\nJust forget about it. Contexter turns close-able objects into context managers automatically.\n\nReplacing `contextlib.ExitStack`_\n-------------------------------------------------------------------------------\n\nContexter offeres everything ``contextlib.ExitStack`` does (and more). If you want a drop-in replacement that also works for Python 2.x and 3.2, you can use our backported ``ExitStack``, a subclass of ``Contexter`` that is API compatible to the contextlib variant.\n\nReplacing everything else from contextlib\n-------------------------------------------------------------------------------\n\nIf you really want to stick with the standard API, you can. Contexter implements all public APIs from contextlib and backports new features as soon as they are introduced.\n\n\nMore examples:\n-------------------------------------------------------------------------------\n\nContexter keeps track of the results of all invoked context managers. You can access the results later and don't have to unpack them all at the beginning.\n\n.. code:: python\n\n with Contexter(open('a.txt'), open('b.txt', 'w')) as ctx:\n in_file, out_file = ctx.values()\n assert ctx.value(0) is in_file\n assert ctx[0] is in_file\n assert ctx[0:2] == [in_file, out_file]\n assert len(ctx) == 2\n\nIf you don't like the ``<<`` syntax, there is a method that does the same.\n\n.. code:: python\n\n with Contexter() as ctx:\n in_file = ctx << open('a.txt')\n out_file = ctx.append(open('b.txt', 'w'))\n\nContexter contexts are nestable. Each level of nesting maintains its own stack of context managers and result values. This allows you to control the lifetime of contexts very precisely.\n\n.. code:: python\n\n with Contexter() as ctx:\n out_file = ctx << open('b.txt', 'w')\n\n with ctx:\n in_file = ctx << open('a.txt')\n copy_data(in_file, out_file)\n\n assert in_file.closed == True\n assert out_file.closed == False\n\nLinks\n-------------------------------------------------------------------------------\n\n.. target-notes::\n\n.. _contextlib: http://docs.python.org/3/library/contextlib.html\n.. _contextlib.nested: http://docs.python.org/2/library/contextlib.html#contextlib.nested\n.. _contextlib.closing: http://docs.python.org/3/library/contextlib.html#contextlib.closing\n.. _contextlib.ExitStack: http://docs.python.org/3/library/contextlib.html#contextlib.ExitStack", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/defnull/contexter", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "contexter", "package_url": "https://pypi.org/project/contexter/", "platform": "any", "project_url": "https://pypi.org/project/contexter/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/defnull/contexter" }, "release_url": "https://pypi.org/project/contexter/0.1.4/", "requires_dist": null, "requires_python": null, "summary": "Contexter is a full replacement of the contextlib standard library\nmodule. It comes with more features, a nicer API and full support for\nPython 2.5 up to 3.x from a single source file.", "version": "0.1.4" }, "last_serial": 2554560, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "92a678ee41ed5f422758f8479b21cb5b", "sha256": "ab21f212dbd285c9c0f5a77d5d2150e9083a96edb6e9e05636c4d5131b2e43a6" }, "downloads": -1, "filename": "contexter-0.1.tar.gz", "has_sig": false, "md5_digest": "92a678ee41ed5f422758f8479b21cb5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4455, "upload_time": "2014-01-11T15:28:57", "url": "https://files.pythonhosted.org/packages/ab/24/3546d2113968e86727f38bbb876148f222aa2151ebe91c7dc827bce299a2/contexter-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "e7443d44987ae9d49e031174c4aacb2a", "sha256": "958ab4c050ef654047adbd3bd711f3519fcc7c366071d7c5742e03f5476dda51" }, "downloads": -1, "filename": "contexter-0.1.1.tar.gz", "has_sig": false, "md5_digest": "e7443d44987ae9d49e031174c4aacb2a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4462, "upload_time": "2014-01-11T15:55:38", "url": "https://files.pythonhosted.org/packages/b9/17/262b53a311a7ef8137bc464f5af7d221a1ce35dd3ed784ffb005002b3963/contexter-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "1d4ec86b5fcb231a0166007eea65572c", "sha256": "82cba5de47583fe3b61ff3a2628861b4aecf57ac0ddabdc4f9090e0b3cf5a97a" }, "downloads": -1, "filename": "contexter-0.1.2-py2-none-any.whl", "has_sig": false, "md5_digest": "1d4ec86b5fcb231a0166007eea65572c", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6868, "upload_time": "2015-06-26T20:36:13", "url": "https://files.pythonhosted.org/packages/50/12/9f64897daf8cb6a39ce9143340b4ca0db6136522eb595209013fbe7bfdd2/contexter-0.1.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8259562d80f161fca5d12e14566e7af2", "sha256": "82f03cde820a5980dba6fe8f5267bf151bf263e79243205fd18221a5edaffa8c" }, "downloads": -1, "filename": "contexter-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8259562d80f161fca5d12e14566e7af2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4499, "upload_time": "2014-02-07T13:04:44", "url": "https://files.pythonhosted.org/packages/24/f5/7f94e52492bbaf9a6d4870c38c4f94e7470e187207e4e114cc016d6e22fa/contexter-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "f0628758b9a70bcb9febb11029655e07", "sha256": "da992ea91e82d814ce17c8eaf54d3444242783aa9c13de4155b6b96026e94bef" }, "downloads": -1, "filename": "contexter-0.1.3-py2-none-any.whl", "has_sig": false, "md5_digest": "f0628758b9a70bcb9febb11029655e07", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6971, "upload_time": "2015-06-26T20:47:50", "url": "https://files.pythonhosted.org/packages/bb/69/a13bdcd956a4fa425009f3e28e480a50ffc6ba440045d1e4e1159040c366/contexter-0.1.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "437efd28f5489cccfe929c08c6b269aa", "sha256": "16b1999d24fb80c98fa4d875904d4425db2aa24d9378242704ca27a1bc9c3677" }, "downloads": -1, "filename": "contexter-0.1.3.tar.gz", "has_sig": false, "md5_digest": "437efd28f5489cccfe929c08c6b269aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4551, "upload_time": "2015-06-26T20:47:47", "url": "https://files.pythonhosted.org/packages/f4/a4/a42a6401bfe2a05fe63e328a8e1b37881e4c286a8029fec1577949d6a8b5/contexter-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "d708a80ea47737eeac8ba53f8d53f88a", "sha256": "36a3a6bb80c6e4bab33ec98c6f394fa8deb433eb2154346e4244deef44230822" }, "downloads": -1, "filename": "contexter-0.1.4-py2-none-any.whl", "has_sig": false, "md5_digest": "d708a80ea47737eeac8ba53f8d53f88a", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6973, "upload_time": "2017-01-04T22:17:44", "url": "https://files.pythonhosted.org/packages/84/0f/6368331608d39498fac773e22d4de23c304181f9718b6065161a555e0c1b/contexter-0.1.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "02a40475377ed7be135cd069260dd842", "sha256": "9d268cf13dfef3c1eb28d791b650b959126c500abc5b6ad6349ec502ac32a19c" }, "downloads": -1, "filename": "contexter-0.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "02a40475377ed7be135cd069260dd842", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6984, "upload_time": "2017-01-04T22:19:47", "url": "https://files.pythonhosted.org/packages/51/7d/ec4d7e39f2d941b37a8d629c9c5da5f350088ea8e7e145c338753739b04a/contexter-0.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30b35ec95fe34fa2a268ca562ca2f803", "sha256": "c730890b1a915051414a6350d8ea1cddca7d01d8f756badedb30b9bf305ea0a8" }, "downloads": -1, "filename": "contexter-0.1.4.tar.gz", "has_sig": false, "md5_digest": "30b35ec95fe34fa2a268ca562ca2f803", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4548, "upload_time": "2017-01-04T22:17:42", "url": "https://files.pythonhosted.org/packages/83/8e/fa97d40616c8d1bda8f83b12ab0ccf9fe0420cb89cf73184436bd3c581fe/contexter-0.1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d708a80ea47737eeac8ba53f8d53f88a", "sha256": "36a3a6bb80c6e4bab33ec98c6f394fa8deb433eb2154346e4244deef44230822" }, "downloads": -1, "filename": "contexter-0.1.4-py2-none-any.whl", "has_sig": false, "md5_digest": "d708a80ea47737eeac8ba53f8d53f88a", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6973, "upload_time": "2017-01-04T22:17:44", "url": "https://files.pythonhosted.org/packages/84/0f/6368331608d39498fac773e22d4de23c304181f9718b6065161a555e0c1b/contexter-0.1.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "02a40475377ed7be135cd069260dd842", "sha256": "9d268cf13dfef3c1eb28d791b650b959126c500abc5b6ad6349ec502ac32a19c" }, "downloads": -1, "filename": "contexter-0.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "02a40475377ed7be135cd069260dd842", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 6984, "upload_time": "2017-01-04T22:19:47", "url": "https://files.pythonhosted.org/packages/51/7d/ec4d7e39f2d941b37a8d629c9c5da5f350088ea8e7e145c338753739b04a/contexter-0.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30b35ec95fe34fa2a268ca562ca2f803", "sha256": "c730890b1a915051414a6350d8ea1cddca7d01d8f756badedb30b9bf305ea0a8" }, "downloads": -1, "filename": "contexter-0.1.4.tar.gz", "has_sig": false, "md5_digest": "30b35ec95fe34fa2a268ca562ca2f803", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4548, "upload_time": "2017-01-04T22:17:42", "url": "https://files.pythonhosted.org/packages/83/8e/fa97d40616c8d1bda8f83b12ab0ccf9fe0420cb89cf73184436bd3c581fe/contexter-0.1.4.tar.gz" } ] }