{ "info": { "author": "John Thorvald Wodder II", "author_email": "inplace@varonathe.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "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", "Topic :: System :: Filesystems", "Topic :: Text Processing :: Filters" ], "description": ".. image:: http://www.repostatus.org/badges/latest/active.svg\n :target: http://www.repostatus.org/#active\n :alt: Project Status: Active - The project has reached a stable, usable\n state and is being actively developed.\n\n.. image:: https://travis-ci.org/jwodder/inplace.svg?branch=master\n :target: https://travis-ci.org/jwodder/inplace\n\n.. image:: https://codecov.io/gh/jwodder/inplace/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/jwodder/inplace\n\n.. image:: https://img.shields.io/pypi/pyversions/in_place.svg\n :target: https://pypi.python.org/pypi/in_place\n\n.. image:: https://img.shields.io/github/license/jwodder/inplace.svg?maxAge=2592000\n :target: https://opensource.org/licenses/MIT\n :alt: MIT License\n\n`GitHub `_\n| `PyPI `_\n| `Issues `_\n\nThe ``in_place`` module provides an ``InPlace`` class for reading & writing a\nfile \"in-place\": data that you write ends up at the same filepath that you read\nfrom, and ``in_place`` takes care of all the necessary mucking about with\ntemporary files for you.\n\nFor example, given the file ``somefile.txt``::\n\n 'Twas brillig, and the slithy toves\n Did gyre and gimble in the wabe;\n All mimsy were the borogoves,\n And the mome raths outgrabe.\n\nand the program ``disemvowel.py``::\n\n import in_place\n\n with in_place.InPlace('somefile.txt') as fp:\n for line in fp:\n fp.write(''.join(c for c in line if c not in 'AEIOUaeiou'))\n\nafter running the program, ``somefile.txt`` will have been edited in place,\nreducing it to just::\n\n 'Tws brllg, nd th slthy tvs\n Dd gyr nd gmbl n th wb;\n ll mmsy wr th brgvs,\n nd th mm rths tgrb.\n\nand no sign of those pesky vowels remains! If you want a sign of those pesky\nvowels to remain, you can instead save the file's original contents in, say,\n``somefile.txt~`` by constructing the filehandle with::\n\n in_place.InPlace('somefile.txt', backup_ext='~')\n\nor save to ``someotherfile.txt`` with::\n\n in_place.InPlace('somefile.txt', backup='someotherfile.txt')\n\nCompared to the in-place filtering implemented by the Python standard library's\n|fileinput|_ module, ``in_place`` offers the following benefits:\n\n- Instead of hijacking ``sys.stdout``, a new filehandle is returned for\n writing.\n- The filehandle supports all of the standard I/O methods, not just\n ``readline()``.\n- There are options for setting the encoding, encoding error handling, and\n newline policy for opening the file, along with support for opening files in\n binary mode, and these options apply to both input and output.\n- The complete filename of the backup file can be specified; you aren't\n constrained to just adding an extension.\n- When used as a context manager, ``in_place`` will restore the original file\n if an exception occurs.\n- The creation of temporary files won't silently clobber innocent bystander\n files.\n\n.. |fileinput| replace:: ``fileinput``\n.. _fileinput: https://docs.python.org/3/library/fileinput.html\n\n\nInstallation\n============\nJust use `pip `_ (You have pip, right?) to install\n``in_place``::\n\n pip install in_place\n\n\nBasic Usage\n===========\n``in_place`` provides a single class, ``InPlace``. Its constructor takes the\nfollowing arguments:\n\n``name=`` (required)\n The path to the file to open & edit in-place\n\n``mode=<'b'|'t'|None>``\n Whether to operate on the file in binary or text mode. If ``mode`` is\n ``'b'``, the file will be opened in binary mode, and data will be read &\n written as ``str`` (Python 2) or ``bytes`` (Python 3) objects. If ``mode``\n is ``'t'``, the file will be opened in text mode, and data will be read &\n written as ``unicode`` (Python 2) or ``str`` (Python 3) objects. If\n ``mode`` is ``None`` (the default), the file will be opened with ``open``\n using the default mode, and data will be read & written as ``str`` objects,\n whatever those happen to be in your version of Python.\n\n``backup=``\n If set, the original contents of the file will be saved to the given path\n when the instance is closed.\n\n``backup_ext=``\n If set, the path to the backup file will be created by appending\n ``backup_ext`` to the original file path.\n\n ``backup`` and ``backup_ext`` are mutually exclusive. ``backup_ext`` cannot\n be set to the empty string.\n\n``delay_open=``\n By default, the instance is opened (including creating temporary files and\n so forth) as soon as it's created. Setting ``delay_open=True`` disables\n this; the instance must then be opened either via the ``open()`` method or\n by using it as a context manager.\n\n``move_first=``\n If ``True``, move the input file to a temporary location first and create\n the output file in its place (\u00e0 la ``fileinput``) rather than the default\n behavior of creating the output file at a temporary location and only moving\n things around once ``close()`` is called (\u00e0 la GNU ``sed(1)``).\n\n``**kwargs``\n Any additional keyword arguments (such as ``encoding``, ``errors``, and\n ``newline``) will be forwarded to ``io.open()`` (or the builtin ``open`` if\n ``mode`` is ``None``) when opening both the input and output file strems.\n\n``name``, ``backup``, and ``backup_ext`` can be either ``str`` or\nfilesystem-encoded ``bytes`` in Python 3, and in Python 3.6 or later, path-like\nobjects are also accepted.\n\nNote:\n\n Earlier versions of this library provided separate ``InPlaceText`` and\n ``InPlaceBytes`` classes for operating in text and binary mode. As of\n version 0.4.0, these classes are deprecated and will be removed in a future\n version. Code written for earlier versions should be updated to use\n ``InPlace`` with the ``mode`` argument instead::\n\n InPlaceText(name, ...) -> InPlace(name, 't', ...)\n InPlaceBytes(name, ...) -> InPlace(name, 'b', ...)\n\nOnce open, ``InPlace`` instances act as filehandles with the usual filehandle\nattributes, specifically::\n\n __iter__() close() closed\n flush() name read()\n readall() * readinto() * readline()\n readlines() write() writelines()\n\n * binary mode only\n\n``InPlace`` instances also feature the following new or modified attributes:\n\n``open()``\n Open the instance, creating filehandles for reading & writing. This method\n must be called first before any of the other I/O methods can be used. It is\n normally called automatically upon instance initialization unless\n ``delay_open`` was set to ``True``. A ``ValueError`` is raised if this\n method is called more than once in an instance's lifetime.\n\n``close()``\n Close filehandles and move files to their final destinations. If called\n after the filhandle has already been closed, ``close()`` does nothing.\n\n Be sure to always close your instances when you're done with them by calling\n ``close()`` or ``rollback()`` either explicity or implicitly (i.e., via use\n as a context manager).\n\n``rollback()``\n Like ``close()``, but discard the output data (keeping the original file\n intact) instead of replacing the original file with it\n\n``__enter__()``, ``__exit__()``\n When an ``InPlace`` instance is used as a context manager, it will be opened\n (if not open already) on entering and either closed (if all went well) or\n rolled back (if an exception occurred) on exiting. ``InPlace`` context\n managers are not `reusable`_ but are `reentrant`_ (as long as no further\n operations are performed after the innermost context ends).\n\n``input``\n The actual filehandle that data is read from, in case you need to access it\n directly\n\n``output``\n The actual filehandle that data is written to, in case you need to access it\n directly\n\n.. _reentrant: https://docs.python.org/3/library/contextlib.html#reentrant-cms\n.. _reusable: https://docs.python.org/3/library/contextlib.html#reusable-context-managers\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/jwodder/inplace", "keywords": "inplace,in-place,io,open,file,tmpfile,tempfile,sed,redirection,fileinput", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "in-place", "package_url": "https://pypi.org/project/in-place/", "platform": "", "project_url": "https://pypi.org/project/in-place/", "project_urls": { "Homepage": "https://github.com/jwodder/inplace" }, "release_url": "https://pypi.org/project/in-place/0.4.0/", "requires_dist": null, "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "summary": "In-place file processing", "version": "0.4.0" }, "last_serial": 4344694, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "b91719d65ba16e481fa492b92a73508e", "sha256": "e0732b6bdc2f1bfc4e1b96c1de2fbbd053bb2a9534547474a0485baa339bfa97" }, "downloads": -1, "filename": "in_place-0.1.1-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "b91719d65ba16e481fa492b92a73508e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11499, "upload_time": "2017-01-27T23:41:06", "url": "https://files.pythonhosted.org/packages/34/81/2baaaa588ee1a6faa6354b7c9bc365f1b3da867707cd136dfedff7c06608/in_place-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b9df50747f5973fccd3a3a12b1f2032", "sha256": "ffa729fd0b818ac750aa31bafc886f266380e1c8557ba38f70f422d2f6a77e23" }, "downloads": -1, "filename": "in_place-0.1.1.tar.gz", "has_sig": true, "md5_digest": "5b9df50747f5973fccd3a3a12b1f2032", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11461, "upload_time": "2017-01-27T23:41:08", "url": "https://files.pythonhosted.org/packages/b9/ba/f1c67fb32c37ba4263326ae4ac6fd00b128025c9289b2fb31a60a0a22f90/in_place-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "68fbc8a65364e599f766804548eef1bf", "sha256": "e1ad42a41dfde02092b411b1634a4be228e28c27553499a81ef04b377b28857c" }, "downloads": -1, "filename": "in_place-0.2.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "68fbc8a65364e599f766804548eef1bf", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11799, "upload_time": "2017-02-23T16:49:00", "url": "https://files.pythonhosted.org/packages/9f/46/9f5679f3b2068e10b33c16a628a78b2b36531a9df08671bd0104f11d8461/in_place-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6da56a2e2b32ba545c7722e7941146c6", "sha256": "ff783dca5d06f85b8d084871abd11a170d732423edb48c53ccb68c55fcbbeb76" }, "downloads": -1, "filename": "in_place-0.2.0.tar.gz", "has_sig": true, "md5_digest": "6da56a2e2b32ba545c7722e7941146c6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12060, "upload_time": "2017-02-23T16:49:02", "url": "https://files.pythonhosted.org/packages/f0/51/c30f1fad2b857f7b5d5ff76ec01f1f80dd0f2ab6b6afcde7b2aed54faa7e/in_place-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "a456e91eccbda64a90d15127cc4bda19", "sha256": "af5ce9bd309f85a6bbe4119acbc0a67cda68f0ae616f0a76a947addc62791fda" }, "downloads": -1, "filename": "in_place-0.3.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "a456e91eccbda64a90d15127cc4bda19", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 8936, "upload_time": "2018-06-28T15:10:15", "url": "https://files.pythonhosted.org/packages/6f/84/ced31e646df335f8cd1b7884e3740b8c012314a28504542ef5631cdc1449/in_place-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cede92280549025c5a91b487c968111d", "sha256": "4758db1457c8addcd5f5b15ef870eab66b238e46e7d784bff99ab1b2126660ea" }, "downloads": -1, "filename": "in_place-0.3.0.tar.gz", "has_sig": true, "md5_digest": "cede92280549025c5a91b487c968111d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 14178, "upload_time": "2018-06-28T15:10:16", "url": "https://files.pythonhosted.org/packages/b6/cd/1dc736d5248420b15dd1546c2938aec7e6dab134e698e0768f54f1757af7/in_place-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "f29402fa1fb1782d1f2b439088a5e364", "sha256": "b30446b0e1cae2a9200a5c311b3d8627d4ddd7bc61ae926adcceba743927df9a" }, "downloads": -1, "filename": "in_place-0.4.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "f29402fa1fb1782d1f2b439088a5e364", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 9174, "upload_time": "2018-10-05T15:36:27", "url": "https://files.pythonhosted.org/packages/fe/97/fbee88bb787facbc81db0f5ba80537ecaedfae2d55681532b4838c0a24b5/in_place-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4b4bfd14d451114292671ea911e05098", "sha256": "3d89b9865226410b19fb226f6cf1e1f84976b6347172e390e88f1c96cd731925" }, "downloads": -1, "filename": "in_place-0.4.0.tar.gz", "has_sig": true, "md5_digest": "4b4bfd14d451114292671ea911e05098", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 15333, "upload_time": "2018-10-05T15:36:29", "url": "https://files.pythonhosted.org/packages/7b/33/d2ead6e52c88a23f0fcc37cbe24d49c46b28306799dcb08f2d90b4df03af/in_place-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f29402fa1fb1782d1f2b439088a5e364", "sha256": "b30446b0e1cae2a9200a5c311b3d8627d4ddd7bc61ae926adcceba743927df9a" }, "downloads": -1, "filename": "in_place-0.4.0-py2.py3-none-any.whl", "has_sig": true, "md5_digest": "f29402fa1fb1782d1f2b439088a5e364", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 9174, "upload_time": "2018-10-05T15:36:27", "url": "https://files.pythonhosted.org/packages/fe/97/fbee88bb787facbc81db0f5ba80537ecaedfae2d55681532b4838c0a24b5/in_place-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4b4bfd14d451114292671ea911e05098", "sha256": "3d89b9865226410b19fb226f6cf1e1f84976b6347172e390e88f1c96cd731925" }, "downloads": -1, "filename": "in_place-0.4.0.tar.gz", "has_sig": true, "md5_digest": "4b4bfd14d451114292671ea911e05098", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", "size": 15333, "upload_time": "2018-10-05T15:36:29", "url": "https://files.pythonhosted.org/packages/7b/33/d2ead6e52c88a23f0fcc37cbe24d49c46b28306799dcb08f2d90b4df03af/in_place-0.4.0.tar.gz" } ] }