Skip to content

Commit 12ceaac

Browse files
committed
Change proposed name to shutil.umask_context
1 parent df59fde commit 12ceaac

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

Doc/library/shutil.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ High-level :term:`context managers <context manager>` for changing a process's e
892892
temporarily relinquished. Unless explicitly desired, you should not yield
893893
within these context managers.
894894

895-
.. class:: umask_of(mask)
895+
.. class:: umask_context(mask)
896896

897897
This is a simple wrapper around :func:`os.umask`. It changes the process's
898898
umask upon entering and restores the old one on exit.
@@ -901,13 +901,13 @@ High-level :term:`context managers <context manager>` for changing a process's e
901901

902902
.. versionadded:: next
903903

904-
In this example, we use a :class:`umask_of` context manager, within which we
905-
create a file that only the user can access:
904+
In this example, we use a :class:`umask_context`, within which we create
905+
a file that only the user can access:
906906

907907
.. code-block:: pycon
908908
909-
>>> from shutil import umask_of
910-
>>> with umask_of(0o077):
909+
>>> from shutil import umask_context
910+
>>> with umask_context(0o077):
911911
... with open("my-secret-file", "w") as f:
912912
... f.write("I ate all the cake!\n")
913913
@@ -918,28 +918,28 @@ The file's permissions are empty for anyone but the user:
918918
$ ls -l my-secret-file
919919
-rw------- 1 guest guest 20 Jan 1 23:45 my-secret-file
920920
921-
Using :class:`umask_of` like this is better practice than first creating the file,
922-
and later changing its permissions with :func:`~os.chmod`, between which a
923-
period of time exists in which the file may have too lenient permissions.
921+
Using :class:`umask_context` like this is better practice than first creating
922+
the file, and later changing its permissions with :func:`~os.chmod`, between
923+
which a period of time exists in which the file may have too lenient permissions.
924924

925925
It also allows you to write code that creates files, in a way that is agnostic
926926
of permissions -- that is without the need to pass a custom ``mode`` keyword
927927
argument to :func:`open` every time.
928928

929929
In this example we create files with a function ``touch_file`` which uses the
930930
:func:`open` built-in without setting ``mode``. Permissions are managed by
931-
:class:`!umask_of`:
931+
:class:`umask_context`:
932932

933933
.. code-block:: pycon
934934
935-
>>> from shutil import umask_of
935+
>>> from shutil import umask_context
936936
>>>
937937
>>> def touch_file(path):
938938
... with open(path, "a"):
939939
... pass
940940
...
941941
>>> touch_file("normal-file")
942-
>>> with umask_of(0o077):
942+
>>> with umask_context(0o077):
943943
... touch_file("private-file")
944944
945945
.. code-block:: shell-session

Doc/whatsnew/3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ pydoc
591591
shutil
592592
------
593593

594-
* Add a new context manager :class:`~shutil.umask_of`, within which a
594+
* Add a new context manager :class:`~shutil.umask_context`, within which a
595595
process's umask is temporarily changed
596596

597597

Lib/shutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"get_unpack_formats", "register_unpack_format",
6363
"unregister_unpack_format", "unpack_archive",
6464
"ignore_patterns", "chown", "which", "get_terminal_size",
65-
"SameFileError", "umask_of"]
65+
"SameFileError", "umask_context"]
6666
# disk_usage is added later, if available on the platform
6767

6868
class Error(OSError):
@@ -1583,7 +1583,7 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
15831583
return None
15841584

15851585

1586-
class umask_of(AbstractContextManager):
1586+
class umask_context(AbstractContextManager):
15871587
"""Non thread-safe context manager to change the process's umask."""
15881588

15891589
def __init__(self, mask):

Lib/test/test_shutil.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
get_archive_formats, Error, unpack_archive,
2222
register_unpack_format, RegistryError,
2323
unregister_unpack_format, get_unpack_formats,
24-
SameFileError, _GiveupOnFastCopy, umask_of)
24+
SameFileError, _GiveupOnFastCopy, umask_context)
2525
import tarfile
2626
import zipfile
2727
try:
@@ -3458,7 +3458,7 @@ def test_module_all_attribute(self):
34583458
'unregister_archive_format', 'get_unpack_formats',
34593459
'register_unpack_format', 'unregister_unpack_format',
34603460
'unpack_archive', 'ignore_patterns', 'chown', 'which',
3461-
'get_terminal_size', 'SameFileError', 'umask_of']
3461+
'get_terminal_size', 'SameFileError', 'umask_context']
34623462
if hasattr(os, 'statvfs') or os.name == 'nt':
34633463
target_api.append('disk_usage')
34643464
self.assertEqual(set(shutil.__all__), set(target_api))
@@ -3483,7 +3483,7 @@ def test_simple(self):
34833483
target_mask = self.mask_private
34843484
self.assertNotEqual(old_mask, target_mask)
34853485

3486-
with umask_of(target_mask):
3486+
with umask_context(target_mask):
34873487
self.assertEqual(self.get_mask(), target_mask)
34883488
self.assertEqual(self.get_mask(), old_mask)
34893489

@@ -3492,7 +3492,7 @@ def test_reentrant(self):
34923492
target_mask_1 = self.mask_private
34933493
target_mask_2 = self.mask_public
34943494
self.assertNotIn(old_mask, (target_mask_1, target_mask_2))
3495-
umask1, umask2 = umask_of(target_mask_1), umask_of(target_mask_2)
3495+
umask1, umask2 = umask_context(target_mask_1), umask_context(target_mask_2)
34963496

34973497
with umask1:
34983498
self.assertEqual(self.get_mask(), target_mask_1)
@@ -3510,7 +3510,7 @@ def test_exception(self):
35103510
self.assertNotEqual(old_mask, target_mask)
35113511

35123512
try:
3513-
with umask_of(target_mask):
3513+
with umask_context(target_mask):
35143514
self.assertEqual(self.get_mask(), target_mask)
35153515
raise RuntimeError("boom")
35163516
except RuntimeError as re:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Add a :class:`~shutil.umask_of` context manager to :mod:`shutil`, to provide a
2-
stdlib context manager for changing a process's umask
1+
Add a :class:`~shutil.umask_context` context manager to :mod:`shutil`, to
2+
provide a stdlib context manager for changing a process's umask

0 commit comments

Comments
 (0)