{ "info": { "author": "Alexander Kozhevnikov", "author_email": "mentalisttraceur@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.3", "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", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: IronPython", "Programming Language :: Python :: Implementation :: Jython", "Programming Language :: Python :: Implementation :: PyPy", "Programming Language :: Python :: Implementation :: Stackless" ], "description": "Python ``with`` as a Function\n=============================\n\nUse context managers with a function instead of a statement.\n\nProvides a minimal, clean and portable interface for using context\nmanagers with all the advantages of functions over syntax.\n\n\nWhy\n---\n\nBecause context managers are awesome, but currently can't be used in\nas many places as I would like, and this is the first step towards\nmaking that possible with less boilerplate and more portability.\n\n\nVersioning\n----------\n\nThis library's version numbers follow the `SemVer 2.0.0 specification\n`_.\n\nThe current version number is available in the variable ``__version__``\nas is normal for Python modules.\n\n\nInstallation\n------------\n\n::\n\n pip install with-as-a-function\n\n\nUsage\n-----\n\nThe ``with_`` function implements the raw basic logic of executing a\ncontext manager as described in PEP-343:\n\n.. code:: python\n\n from with_ import with_\n\nWith it we can do things like this:\n\n.. code:: python\n\n data = with_(open('my_file.txt'), lambda my_file: my_file.read(4096))\n\nWhich is equivalent to:\n\n.. code:: python\n\n with open('my_file.txt') as my_file:\n data = my_file.read(4096)\n\nYou can think of it as being functionally equivalent to:\n\n.. code:: python\n\n def with_(manager, action):\n with manager as value:\n return action(value)\n return None\n\nexcept that it's also portable to Python implementations and versions\nthat don't support the ``with`` statement.\n\n\nPortability\n-----------\n\nPortable to all releases of both Python 3 and Python 2.\n\n*Even those without the* ``with`` *statement.*\n\n(The oldest tested is 2.5, but it will likely work on all Python 2\nversions and probably on even earlier versions.)\n\nFor Python implementations that do not support ``sys.exc_info``, a\n\"no traceback\" variant can be installed manually, by grabbing the\n``with_no_traceback.py`` file and saving it *as* ``with_.py``.\n(Saving it as ``with_.py`` has the advantage that your code can just do\n``from with_ import with_`` and it'll just work consistently, without\nversion-detecting boilerplate.)\n\nYou are of course welcome to just copy-paste the tiny ``with_``\nfunction definition into your code.\n\n\nDesign Decisions\n----------------\n\n* Not exposing anything special to support the equivalent of wrapping\n ``yield from`` and ``yield`` within ``with`` blocks, because that is\n a more complex problem, and I want to have more experience seeing\n those usecases before I start committing to an interface.\n\n* Not using ``finally`` as the reference code in PEP-343 does because\n the only purpose of the ``finally`` was to catch escaping statements\n like ``return``, ``break``, and ``continue``. Since we use a single\n function instead of a \"suite\" of code, those cannot happen.\n\n* Not using an ``else`` clause for the clean exit variant, because the\n code is still equally clear without it, and arguably is even clearer\n because it's the same number of lines but code paths terminate faster.\n\n* Also not using either ``else`` or ``finally`` because of \"portability\n conservatism\": the principle that when portability matters, it is\n safer to bet on the most conservative feature-set possible. You'd\n think every pragmatically usable Python implementation would get\n ``try`` block ``else`` and ``finally`` clauses right, but it turns out\n no, some don't.\n\n If it made a big difference in code clarity or correness, I would be\n reticent to consider this a sufficient reason by itself, but it is a\n factor worth considering.\n\n* To aid portability of code to Python implementations that do not\n support getting a traceback object for the exception being handled,\n passing ``None`` as ``traceback`` to ``__exit__`` helps writing code\n that portably follows \"progressive enhancement\" or \"graceful\n degradation\" practices: tracebacks are properly used where possible,\n but ignored where not.\n\n This matches the behavior of `MicroPython `_\n and `Transcrypt `_, two implementations of\n Python which support ``with`` but don't support traceback objects,\n so this suggests that it is a reasonable choice.\n\n This is **not** always the wisest choice: some features and behavior\n are relied on for security, correctness, or debugging, and in those\n cases the inability to fulfill the contract of an interface must not\n be silently hidden.\n\n Because of this, the \"no traceback\" variant is \"opt-in\": if you're\n using it, you deliberately included it into your project, or a\n dependency of yours did.\n\n* Using ``from sys import exc_info as _exc_info`` instead of ``import\n sys as _sys`` and then calling ``_sys.exc_info`` because:\n\n 1. Python's dynamic semantics mean that *any other piece of code*\n is allowed to change ``sys.exc_info`` **globally** *at any time*.\n\n 2. Therefore first and foremost, we are communicating our intent that\n we would rather be immune from that *as much as possible*.\n\n 3. Someone could still modify ``sys.exc_info`` before ``with_`` is\n *first* imported, but at that point odds are higher that this was\n done with due care of how it will effect *all* code using it.\n\n 4. Someone could modify *our* ``with_._exc_info`` name directly, but\n at that point they *definitely* deliberately intended to do so.\n\n 5. The important thing is that we opt-out of being effected by casual,\n careless, or experimental reassignments of ``sys.exc_info``.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mentalisttraceur/python-with", "keywords": "", "license": "0BSD (BSD Zero Clause License)", "maintainer": "", "maintainer_email": "", "name": "with-as-a-function", "package_url": "https://pypi.org/project/with-as-a-function/", "platform": "", "project_url": "https://pypi.org/project/with-as-a-function/", "project_urls": { "Homepage": "https://github.com/mentalisttraceur/python-with" }, "release_url": "https://pypi.org/project/with-as-a-function/1.0.2.post2/", "requires_dist": null, "requires_python": "", "summary": "Use context managers with a function instead of a statement.", "version": "1.0.2.post2" }, "last_serial": 5345386, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "a33689d3e82b263e9f7335e9209deda7", "sha256": "ed311bb69c0e529c27adfc64a2a545c075ef2dc5bffdb80d066e56c227a8f020" }, "downloads": -1, "filename": "with_as_a_function-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "a33689d3e82b263e9f7335e9209deda7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6672, "upload_time": "2019-02-18T07:41:03", "url": "https://files.pythonhosted.org/packages/f5/51/89a6449fa7105f5b36be2c62dfe39e9e9fcd0f5c7c9bb27414c1443b4aec/with_as_a_function-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3bd9fe657314ef6324b8928e624870d5", "sha256": "515a908aecd93859a299a371b8b268334ba8785e057a6b527d3bf54ebe0e3b61" }, "downloads": -1, "filename": "with-as-a-function-1.0.0.tar.gz", "has_sig": false, "md5_digest": "3bd9fe657314ef6324b8928e624870d5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4189, "upload_time": "2019-02-18T07:41:05", "url": "https://files.pythonhosted.org/packages/0a/07/5d1041a62a2dfc2cbe2c039af03f1413e547e771ca09b41c49eacbb66bd3/with-as-a-function-1.0.0.tar.gz" } ], "1.0.0.post1": [ { "comment_text": "", "digests": { "md5": "a1c63f7d1187a4b7eefb898db31f9c43", "sha256": "390cfbf39d93e96ff690b89e4c244ee7276c0a2e5384197556d502b7afb811e3" }, "downloads": -1, "filename": "with_as_a_function-1.0.0.post1-py3-none-any.whl", "has_sig": false, "md5_digest": "a1c63f7d1187a4b7eefb898db31f9c43", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6767, "upload_time": "2019-02-18T08:02:42", "url": "https://files.pythonhosted.org/packages/f0/52/28f5d7b2ae86a77dfd1bbdc377dd7ab9ea1cf2ad8067d2b687f32a268c65/with_as_a_function-1.0.0.post1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afcfb7a191643e98c99f83f04ee5c27f", "sha256": "b6a30ddc3e10064eeed5ef81b3dd5b5dee05aa9a45daf64b17ab3e4d10179c02" }, "downloads": -1, "filename": "with-as-a-function-1.0.0.post1.tar.gz", "has_sig": false, "md5_digest": "afcfb7a191643e98c99f83f04ee5c27f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4199, "upload_time": "2019-02-18T08:02:44", "url": "https://files.pythonhosted.org/packages/f9/45/a535e071c1adc5a9c467ce4f0ddd2232a9eed18f3d93e3bdd064704b139c/with-as-a-function-1.0.0.post1.tar.gz" } ], "1.0.0.post2": [ { "comment_text": "", "digests": { "md5": "4db39e2d63ba252fe83241004f4d3875", "sha256": "dd7826aa86d303b97800f02a92fc92de6cd8653e0aebdf94a9df9c5775eb50bb" }, "downloads": -1, "filename": "with_as_a_function-1.0.0.post2-py3-none-any.whl", "has_sig": false, "md5_digest": "4db39e2d63ba252fe83241004f4d3875", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7652, "upload_time": "2019-02-18T08:20:19", "url": "https://files.pythonhosted.org/packages/87/82/7fd5bb1a66f478111c795cfc8a5fca4d7b4bc5ade54e310aff5d4b5aec28/with_as_a_function-1.0.0.post2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d3fcaa550be9eca276e7b9b353dfdef4", "sha256": "1f0f460160811230919fe846f1673dd85862a8d160fcca347472cee2ee5b1c67" }, "downloads": -1, "filename": "with-as-a-function-1.0.0.post2.tar.gz", "has_sig": false, "md5_digest": "d3fcaa550be9eca276e7b9b353dfdef4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4803, "upload_time": "2019-02-18T08:20:22", "url": "https://files.pythonhosted.org/packages/8d/64/1fdf2bcd54af1b05132707162b8a235784ef956a85262821a12d06a61254/with-as-a-function-1.0.0.post2.tar.gz" } ], "1.0.0.post3": [ { "comment_text": "", "digests": { "md5": "6d7e0b460feabc54c967a2dd4df8e9c0", "sha256": "c5e9ffecb8790c28ca60eeca8c07cdc23ce3ac4d372daac320178c2229262873" }, "downloads": -1, "filename": "with_as_a_function-1.0.0.post3-py3-none-any.whl", "has_sig": false, "md5_digest": "6d7e0b460feabc54c967a2dd4df8e9c0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 7656, "upload_time": "2019-02-18T08:42:12", "url": "https://files.pythonhosted.org/packages/1a/eb/ff70c2deb3c4a327150cd761ac53f17167b7ea5964f6c703e47561bc01db/with_as_a_function-1.0.0.post3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b62542c597a1681fae53cebb4b9fdfe", "sha256": "b7bcc93e6744c2b8f9883dd040720b37a3cd9482b7a2659bf57eb0340eab52e6" }, "downloads": -1, "filename": "with-as-a-function-1.0.0.post3.tar.gz", "has_sig": false, "md5_digest": "8b62542c597a1681fae53cebb4b9fdfe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4807, "upload_time": "2019-02-18T08:42:15", "url": "https://files.pythonhosted.org/packages/53/00/a3685ccdbc67306b0b2dd1ed3ec90c777f5793a918ce051eb8b9f2c0a79c/with-as-a-function-1.0.0.post3.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "2885762a5dc3b7b7fe8f6b4ae8e1f643", "sha256": "8fc275411beade84ff492e8dba5519c200a08d553d0cc67141ed8f2e965807dd" }, "downloads": -1, "filename": "with_as_a_function-1.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2885762a5dc3b7b7fe8f6b4ae8e1f643", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5169, "upload_time": "2019-05-16T06:38:15", "url": "https://files.pythonhosted.org/packages/cc/ed/c15a1deb01317370dba20100fd43e96fd23522145dcb29a1bbc5bd2a5f2e/with_as_a_function-1.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c38811fa9cd89a896b087ba5a654a146", "sha256": "5eb49b79e6b343c499615c62466d01a542c3ecb5ec4852e0ca951193f024a288" }, "downloads": -1, "filename": "with-as-a-function-1.0.1.tar.gz", "has_sig": false, "md5_digest": "c38811fa9cd89a896b087ba5a654a146", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4780, "upload_time": "2019-05-16T06:35:58", "url": "https://files.pythonhosted.org/packages/c0/d3/a8b809763a436e5e52bc2515b07d2acf36ea8ccfed9bd5eaddf6b2026488/with-as-a-function-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "cae2ba72ebb3e28623542a091d02d9ca", "sha256": "fb017503c07da227acfe14ad762a87c63d69df33f333cae1273439b3eb7067fa" }, "downloads": -1, "filename": "with_as_a_function-1.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "cae2ba72ebb3e28623542a091d02d9ca", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5539, "upload_time": "2019-05-24T07:37:46", "url": "https://files.pythonhosted.org/packages/ab/9b/1b1f6737d173c7e65e1c451ca2374fab741c0dcfea3268d06ab80921b4d2/with_as_a_function-1.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3261c5618d8f3529b1fd72c17a72cf0d", "sha256": "6d16f3a7f12d7f143d964cf52f131b1460810739dc255f459528535e47d8bb87" }, "downloads": -1, "filename": "with-as-a-function-1.0.2.tar.gz", "has_sig": false, "md5_digest": "3261c5618d8f3529b1fd72c17a72cf0d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5215, "upload_time": "2019-05-24T07:37:49", "url": "https://files.pythonhosted.org/packages/f3/16/7c36ec52456f0eebe03530ccb8aa0e83be23c918df1ba2a8184dec65e6c7/with-as-a-function-1.0.2.tar.gz" } ], "1.0.2.post1": [ { "comment_text": "", "digests": { "md5": "e4969abb281f541512043d8b174e160e", "sha256": "ab0aa545d6bfa071535abd6f98a3ba29fc62933ac4b07ec904bfc30f8815091e" }, "downloads": -1, "filename": "with_as_a_function-1.0.2.post1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e4969abb281f541512043d8b174e160e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5613, "upload_time": "2019-05-24T07:47:56", "url": "https://files.pythonhosted.org/packages/ba/a5/14e88a813516e513aeed99e6c2c4d5dd4a94938b52f74292458873d51dc8/with_as_a_function-1.0.2.post1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4e344809664ec2b743dc8af22a936852", "sha256": "59d8c3b611d4c131f81cd27e8efb4cc7b05b8d20bf0f2dab2accd5a42a9a1877" }, "downloads": -1, "filename": "with-as-a-function-1.0.2.post1.tar.gz", "has_sig": false, "md5_digest": "4e344809664ec2b743dc8af22a936852", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5232, "upload_time": "2019-05-24T07:47:58", "url": "https://files.pythonhosted.org/packages/db/67/9d37d122a5a48c105553cb291036101ae93b266fc2e7851adede35596549/with-as-a-function-1.0.2.post1.tar.gz" } ], "1.0.2.post2": [ { "comment_text": "", "digests": { "md5": "339f7e8e665e865f39d7f33b3c760f60", "sha256": "e92732c4c338c39ef7e17a8f5e70dc0d834cef018e3a8268a8e29182a2311b32" }, "downloads": -1, "filename": "with_as_a_function-1.0.2.post2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "339f7e8e665e865f39d7f33b3c760f60", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5586, "upload_time": "2019-06-01T04:39:46", "url": "https://files.pythonhosted.org/packages/f4/32/43d4039faedeebe70cb483513611f34efcd038883fe1d999bd43357b62dc/with_as_a_function-1.0.2.post2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e606312a9d842fa370f9c9d0eb2fe945", "sha256": "48e77aff4f22f6c0dc2732e1564ef0b7bf3bd27c4cc93cb55c120685da69fd03" }, "downloads": -1, "filename": "with-as-a-function-1.0.2.post2.tar.gz", "has_sig": false, "md5_digest": "e606312a9d842fa370f9c9d0eb2fe945", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5220, "upload_time": "2019-06-01T04:39:49", "url": "https://files.pythonhosted.org/packages/ab/15/233afcffc67000c40ae67b0be818e820913ba13b0fbfecfb30e3553f418b/with-as-a-function-1.0.2.post2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "339f7e8e665e865f39d7f33b3c760f60", "sha256": "e92732c4c338c39ef7e17a8f5e70dc0d834cef018e3a8268a8e29182a2311b32" }, "downloads": -1, "filename": "with_as_a_function-1.0.2.post2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "339f7e8e665e865f39d7f33b3c760f60", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5586, "upload_time": "2019-06-01T04:39:46", "url": "https://files.pythonhosted.org/packages/f4/32/43d4039faedeebe70cb483513611f34efcd038883fe1d999bd43357b62dc/with_as_a_function-1.0.2.post2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e606312a9d842fa370f9c9d0eb2fe945", "sha256": "48e77aff4f22f6c0dc2732e1564ef0b7bf3bd27c4cc93cb55c120685da69fd03" }, "downloads": -1, "filename": "with-as-a-function-1.0.2.post2.tar.gz", "has_sig": false, "md5_digest": "e606312a9d842fa370f9c9d0eb2fe945", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5220, "upload_time": "2019-06-01T04:39:49", "url": "https://files.pythonhosted.org/packages/ab/15/233afcffc67000c40ae67b0be818e820913ba13b0fbfecfb30e3553f418b/with-as-a-function-1.0.2.post2.tar.gz" } ] }