diff options
| author | Barry Warsaw | 2016-04-30 13:34:04 -0400 |
|---|---|---|
| committer | GitLab | 2016-04-30 19:54:54 +0000 |
| commit | c6eb7ee3e574b48ee016dd31af2014b0ed083268 (patch) | |
| tree | 14c1f1e7bb382898ee50909333365aab335aa4a1 /src/mailman/utilities | |
| parent | 465f24ff33e154385322ee894d32d8b7dd9b3941 (diff) | |
| download | mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.tar.gz mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.tar.zst mailman-c6eb7ee3e574b48ee016dd31af2014b0ed083268.zip | |
Diffstat (limited to 'src/mailman/utilities')
| -rw-r--r-- | src/mailman/utilities/filesystem.py | 18 | ||||
| -rw-r--r-- | src/mailman/utilities/interact.py | 5 | ||||
| -rw-r--r-- | src/mailman/utilities/uid.py | 6 |
3 files changed, 13 insertions, 16 deletions
diff --git a/src/mailman/utilities/filesystem.py b/src/mailman/utilities/filesystem.py index e8935b92c..e89f2abb8 100644 --- a/src/mailman/utilities/filesystem.py +++ b/src/mailman/utilities/filesystem.py @@ -18,8 +18,8 @@ """Filesystem utilities.""" import os -import errno +from contextlib import suppress from mailman import public @@ -54,18 +54,18 @@ def makedirs(path, mode=0o2775): :param mode: The numeric permission mode to use. :type mode: int """ - try: + with suppress(FileExistsError): with umask(0): os.makedirs(path, mode) - except OSError as error: - # Ignore the exceptions if the directory already exists. - if error.errno != errno.EEXIST: - raise # Some systems such as FreeBSD ignore mkdir's mode, so walk the just # created directories and try to set the mode, ignoring any OSErrors that # occur here. for dirpath, dirnames, filenames in os.walk(path): - try: + with suppress(OSError): os.chmod(dirpath, mode) - except OSError: - pass + + +@public +def safe_remove(path): + with suppress(FileNotFoundError): + os.remove(path) diff --git a/src/mailman/utilities/interact.py b/src/mailman/utilities/interact.py index 3cc5dddc6..904d1b579 100644 --- a/src/mailman/utilities/interact.py +++ b/src/mailman/utilities/interact.py @@ -21,6 +21,7 @@ import os import sys import code +from contextlib import suppress from mailman import public @@ -51,10 +52,8 @@ def interact(upframe=True, banner=DEFAULT_BANNER, overrides=None): namespace.update(overrides) interp = code.InteractiveConsole(namespace) # Try to import the readline module, but don't worry if it's unavailable. - try: + with suppress(ImportError): import readline # noqa - except ImportError: # pragma: no cover - pass # Mimic the real interactive interpreter's loading of any $PYTHONSTARTUP # file. Note that if the startup file is not prepared to be exec'd more # than once, this could cause a problem. diff --git a/src/mailman/utilities/uid.py b/src/mailman/utilities/uid.py index cef0ebc87..4389bcd92 100644 --- a/src/mailman/utilities/uid.py +++ b/src/mailman/utilities/uid.py @@ -27,6 +27,7 @@ import uuid import random import hashlib +from contextlib import suppress from flufl.lock import Lock from mailman import public from mailman.config import config @@ -125,11 +126,8 @@ class UIDFactory(_PredictableIDGenerator): """ while True: uid = uuid.uuid4() - try: + with suppress(ValueError): UID.record(uid) - except ValueError: - pass - else: return uid def _next_predictable_id(self): |
