Skip to content

Commit e4a97a7

Browse files
barneygalehugovk
andauthored
pythonGH-119054: Add "Permissions and ownership" section to pathlib docs. (python#120505)
Add dedicated subsection for `pathlib.owner()`, `group()`, `chmod()` and `lchmod()`. Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 375b723 commit e4a97a7

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

Doc/library/pathlib.rst

+51-47
Original file line numberDiff line numberDiff line change
@@ -1543,30 +1543,39 @@ Copying, renaming and deleting
15431543
Remove this directory. The directory must be empty.
15441544

15451545

1546-
Other methods
1547-
^^^^^^^^^^^^^
1546+
Permissions and ownership
1547+
^^^^^^^^^^^^^^^^^^^^^^^^^
15481548

1549-
.. classmethod:: Path.cwd()
1549+
.. method:: Path.owner(*, follow_symlinks=True)
15501550

1551-
Return a new path object representing the current directory (as returned
1552-
by :func:`os.getcwd`)::
1551+
Return the name of the user owning the file. :exc:`KeyError` is raised
1552+
if the file's user identifier (UID) isn't found in the system database.
15531553

1554-
>>> Path.cwd()
1555-
PosixPath('/home/antoine/pathlib')
1554+
This method normally follows symlinks; to get the owner of the symlink, add
1555+
the argument ``follow_symlinks=False``.
15561556

1557+
.. versionchanged:: 3.13
1558+
Raises :exc:`UnsupportedOperation` if the :mod:`pwd` module is not
1559+
available. In earlier versions, :exc:`NotImplementedError` was raised.
15571560

1558-
.. classmethod:: Path.home()
1561+
.. versionchanged:: 3.13
1562+
The *follow_symlinks* parameter was added.
15591563

1560-
Return a new path object representing the user's home directory (as
1561-
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1562-
directory can't be resolved, :exc:`RuntimeError` is raised.
15631564

1564-
::
1565+
.. method:: Path.group(*, follow_symlinks=True)
15651566

1566-
>>> Path.home()
1567-
PosixPath('/home/antoine')
1567+
Return the name of the group owning the file. :exc:`KeyError` is raised
1568+
if the file's group identifier (GID) isn't found in the system database.
15681569

1569-
.. versionadded:: 3.5
1570+
This method normally follows symlinks; to get the group of the symlink, add
1571+
the argument ``follow_symlinks=False``.
1572+
1573+
.. versionchanged:: 3.13
1574+
Raises :exc:`UnsupportedOperation` if the :mod:`grp` module is not
1575+
available. In earlier versions, :exc:`NotImplementedError` was raised.
1576+
1577+
.. versionchanged:: 3.13
1578+
The *follow_symlinks* parameter was added.
15701579

15711580

15721581
.. method:: Path.chmod(mode, *, follow_symlinks=True)
@@ -1589,57 +1598,52 @@ Other methods
15891598
.. versionchanged:: 3.10
15901599
The *follow_symlinks* parameter was added.
15911600

1592-
.. method:: Path.expanduser()
15931601

1594-
Return a new path with expanded ``~`` and ``~user`` constructs,
1595-
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1596-
resolved, :exc:`RuntimeError` is raised.
1602+
.. method:: Path.lchmod(mode)
15971603

1598-
::
1604+
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1605+
symbolic link's mode is changed rather than its target's.
15991606

1600-
>>> p = PosixPath('~/films/Monty Python')
1601-
>>> p.expanduser()
1602-
PosixPath('/home/eric/films/Monty Python')
16031607

1604-
.. versionadded:: 3.5
1608+
Other methods
1609+
^^^^^^^^^^^^^
16051610

1611+
.. classmethod:: Path.cwd()
16061612

1607-
.. method:: Path.group(*, follow_symlinks=True)
1613+
Return a new path object representing the current directory (as returned
1614+
by :func:`os.getcwd`)::
16081615

1609-
Return the name of the group owning the file. :exc:`KeyError` is raised
1610-
if the file's gid isn't found in the system database.
1616+
>>> Path.cwd()
1617+
PosixPath('/home/antoine/pathlib')
16111618

1612-
This method normally follows symlinks; to get the group of the symlink, add
1613-
the argument ``follow_symlinks=False``.
16141619

1615-
.. versionchanged:: 3.13
1616-
Raises :exc:`UnsupportedOperation` if the :mod:`grp` module is not
1617-
available. In previous versions, :exc:`NotImplementedError` was raised.
1620+
.. classmethod:: Path.home()
16181621

1619-
.. versionchanged:: 3.13
1620-
The *follow_symlinks* parameter was added.
1622+
Return a new path object representing the user's home directory (as
1623+
returned by :func:`os.path.expanduser` with ``~`` construct). If the home
1624+
directory can't be resolved, :exc:`RuntimeError` is raised.
16211625

1626+
::
16221627

1623-
.. method:: Path.lchmod(mode)
1628+
>>> Path.home()
1629+
PosixPath('/home/antoine')
16241630

1625-
Like :meth:`Path.chmod` but, if the path points to a symbolic link, the
1626-
symbolic link's mode is changed rather than its target's.
1631+
.. versionadded:: 3.5
16271632

16281633

1629-
.. method:: Path.owner(*, follow_symlinks=True)
1634+
.. method:: Path.expanduser()
16301635

1631-
Return the name of the user owning the file. :exc:`KeyError` is raised
1632-
if the file's uid isn't found in the system database.
1636+
Return a new path with expanded ``~`` and ``~user`` constructs,
1637+
as returned by :meth:`os.path.expanduser`. If a home directory can't be
1638+
resolved, :exc:`RuntimeError` is raised.
16331639

1634-
This method normally follows symlinks; to get the owner of the symlink, add
1635-
the argument ``follow_symlinks=False``.
1640+
::
16361641

1637-
.. versionchanged:: 3.13
1638-
Raises :exc:`UnsupportedOperation` if the :mod:`pwd` module is not
1639-
available. In previous versions, :exc:`NotImplementedError` was raised.
1642+
>>> p = PosixPath('~/films/Monty Python')
1643+
>>> p.expanduser()
1644+
PosixPath('/home/eric/films/Monty Python')
16401645

1641-
.. versionchanged:: 3.13
1642-
The *follow_symlinks* parameter was added.
1646+
.. versionadded:: 3.5
16431647

16441648

16451649
.. method:: Path.readlink()

0 commit comments

Comments
 (0)