diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-05-08 13:45:06 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2019-05-08 13:45:05 (GMT) |
commit | b2758ff9553d8bebe4e9dd1cb3996212473810e3 (patch) | |
tree | 60ee775ed37a5262b66dec6f4122888da43df2e3 /Doc | |
parent | 70b80541bb044e8cb7037acaf97f64890fef418e (diff) | |
download | cpython-b2758ff9553d8bebe4e9dd1cb3996212473810e3.zip cpython-b2758ff9553d8bebe4e9dd1cb3996212473810e3.tar.gz cpython-b2758ff9553d8bebe4e9dd1cb3996212473810e3.tar.bz2 |
bpo-36832: add zipfile.Path (#13153)
* bpo-36832: add zipfile.Path
* bpo-36832: add documentation for zipfile.Path
* 📜🤖 Added by blurb_it.
* Remove module reference from blurb.
* Sort the imports
* Update docstrings and docs per recommendations.
* Rely on test.support.temp_dir
* Signal that 'root' is the parameter.
* Correct spelling of 'mod'
* Convert docstring to comment for brevity.
* Fix more errors in the docs
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/zipfile.rst | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index 4e9edff..9db9697 100644 --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -52,6 +52,15 @@ The module defines the following items: :ref:`zipfile-objects` for constructor details. +.. class:: Path + :noindex: + + A pathlib-compatible wrapper for zip files. See section + :ref:`path-objects` for details. + + .. versionadded:: 3.8 + + .. class:: PyZipFile :noindex: @@ -456,6 +465,64 @@ The following data attributes are also available: truncated. +.. _path-objects: + +Path Objects +------------ + +.. class:: Path(root, at='') + + Construct a Path object from a ``root`` zipfile (which may be a + :class:`ZipFile` instance or ``file`` suitable for passing to + the :class:`ZipFile` constructor). + + ``at`` specifies the location of this Path within the zipfile, + e.g. 'dir/file.txt', 'dir/', or ''. Defaults to the empty string, + indicating the root. + +Path objects expose the following features of :mod:`pathlib.Path` +objects: + +Path objects are traversable using the ``/`` operator. + +.. attribute:: Path.name + + The final path component. + +.. method:: Path.open(*, **) + + Invoke :meth:`ZipFile.open` on the current path. Accepts + the same arguments as :meth:`ZipFile.open`. + +.. method:: Path.listdir() + + Enumerate the children of the current directory. + +.. method:: Path.is_dir() + + Return ``True`` if the current context references a directory. + +.. method:: Path.is_file() + + Return ``True`` if the current context references a file. + +.. method:: Path.exists() + + Return ``True`` if the current context references a file or + directory in the zip file. + +.. method:: Path.read_text(*, **) + + Read the current file as unicode text. Positional and + keyword arguments are passed through to + :class:`io.TextIOWrapper` (except ``buffer``, which is + implied by the context). + +.. method:: Path.read_bytes() + + Read the current file as bytes. + + .. _pyzipfile-objects: PyZipFile Objects |