Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4b29e2e
Add `pathlib._VirtualPath`
barneygale Jun 23, 2023
8ce0139
Add tests for `pathlib._VirtualPath`
barneygale Jul 2, 2023
b850d11
Fix tests on Windows
barneygale Jul 2, 2023
39bf6b3
Fix tests on Windows (take 2)
barneygale Jul 3, 2023
0515dea
Fix tests on Windows (take 3)
barneygale Jul 3, 2023
596016f
Fix tests on Windows (take 4)
barneygale Jul 3, 2023
1a6122b
Add `tarfile.TarPath`
barneygale Jul 3, 2023
6833ed8
Add docs for `tarfile.TarPath`
barneygale Jul 3, 2023
4d2e8a9
Add tests for `tarfile.TarPath`
barneygale Jul 3, 2023
e4daac9
Merge branch 'main' into gh-89812-omgtarpath
barneygale Jul 3, 2023
e3f2509
Merge branch 'main' into gh-89812-omgtarpath
barneygale Jul 12, 2023
508cabe
Undo changes to tarfile.
barneygale Jul 12, 2023
2c56591
`_VirtualPath` --> `_PathBase`
barneygale Jul 12, 2023
42fe91a
Merge branch 'main' into gh-89812-omgtarpath
barneygale Jul 19, 2023
8944098
Apply suggestions from code review
barneygale Aug 28, 2023
b61141a
Improve _PathBase docstring
barneygale Aug 28, 2023
1e462b0
Explain use of nullcontext() in comment
barneygale Aug 28, 2023
6318eb7
Merge branch 'main' into gh-89812-omgtarpath
barneygale Aug 28, 2023
d321cad
Align and test Path/PathBase docstrings
barneygale Aug 28, 2023
acfc1b0
Revise `_PathBase.is_junction()`
barneygale Aug 28, 2023
bc82225
Make is_junction() code more consistent with other is_*() methods.
barneygale Aug 28, 2023
9b6377a
Merge branch 'main' into gh-89812-omgtarpath
barneygale Sep 2, 2023
c3127b8
Improve `UnsupportedOperation` exception message.
barneygale Sep 2, 2023
3540ae1
Slightly improve symlink loop code, exception message.
barneygale Sep 2, 2023
c9f0f20
Restore deleted comment in `cwd()`, expand `_scandir()` comment.
barneygale Sep 2, 2023
0ee10ca
Make `_PathBase.is_junction()` immediately return false.
barneygale Sep 2, 2023
17eee2f
MAX_SYMLINKS --> _MAX_SYMLINKS
barneygale Sep 9, 2023
c7c46bc
`return self._unsupported()` --> `self._unsupported()`
barneygale Sep 9, 2023
a51d7a0
WIP
barneygale Sep 15, 2023
7e3729e
Undo test change.
barneygale Sep 23, 2023
b945cf8
Merge branch 'main' into gh-89812-omgtarpath
barneygale Sep 26, 2023
703fe5c
Ensure `..` segments are resolved in non-strict mode
barneygale Sep 26, 2023
e5e5be5
Move symlink loop resolution test from `PosixPathTest` to `DummyPathT…
barneygale Sep 26, 2023
38769a0
Add `PathBase._split_stack()` helper method.
barneygale Sep 26, 2023
7c78952
Use path object as stat/link target cache key
barneygale Sep 26, 2023
fe57725
Optimise resolve(): skip stat() in non-strict mode if readlink() is u…
barneygale Sep 27, 2023
cf9c8b6
Address code review comments
barneygale Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add docs for tarfile.TarPath
  • Loading branch information
barneygale committed Jul 3, 2023
commit 6833ed8a006ca90d811e2efb59330307b77c5c19
41 changes: 41 additions & 0 deletions Doc/library/tarfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,47 @@ A :class:`TarInfo` object also provides some convenient query methods:
Return :const:`True` if it is one of character device, block device or FIFO.


TarPath Objects
---------------

The :class:`TarPath` class provides an interface for tar files that's
compatible with :class:`pathlib.Path`.

.. class:: TarPath(*pathsegments, tarfile)

Create a :class:`TarPath` object from a given :class:`TarFile` object.
If *pathsegments* are supplied, they are joined together to form a path
within the archive; otherwise the path is positioned at the archive root.

.. versionadded:: 3.13

.. attribute:: TarPath.tarfile

The backing :class:`TarFile` instance, as supplied to the initializer.

Features such as testing file types, reading or writing files, and iterating
or globbing directories are supported::

import tarfile
with tarfile.open("sample.tar.gz", "r:gz") as tar:
root = tarfile.TarPath(tarfile=tar)
for readme in root.glob("**/README*", case_sensitive=False):
print(f"Found README file at {readme}:")
print(readme.read_text())
break

Some :class:`TarPath` methods unconditionally raise
:exc:`pathlib.UnsupportedOperation`. They are:

- ``absolute()``, ``cwd()``, ``expanduser()``, ``home()`` and ``as_uri()``,
because tar archives lack these features.
- ``touch()``, ``rename()``, ``replace()``, ``chmod()``, ``lchmod()``,
``unlink()`` and ``rmdir()``, because the :class:`TarFile` class does not
support reading and writing the same archive.

Refer to the :mod:`pathlib` documentation for information about other methods.


.. _tarfile-extraction-filter:

Extraction filters
Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ pathlib
:meth:`~pathlib.Path.is_dir`.
(Contributed by Barney Gale in :gh:`77609` and :gh:`105793`.)

tarfile
-------

* Add :class:`tarfile.TarPath` class, which provides access to tar archive
members via the :class:`pathlib.Path` interface.
(Contributed by Barney Gale in :gh:`89812`.)

traceback
---------

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :class:`tarfile.TarPath` class, which provides access to tar archive
members via the :class:`pathlib.Path` interface.