aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2025-04-04 04:09:56 +0100
committerdirkf <fieldhouse@gmx.net>2025-04-08 01:59:00 +0100
commitadd46228701d78444e20afdde4beafa3268344f2 (patch)
tree96097f7bfa057ec5afacb732dca5ed01bcb7e8f4
parent9a6ddece4dca4d5b7a8374a82f72d778750d6b88 (diff)
[compat] Add compat_os_makedirs
* support exists_ok parameter in Py < 3.2
-rw-r--r--youtube_dl/compat.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 8910a4dac..72b2f8f78 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -3120,6 +3120,21 @@ else:
compat_os_path_expanduser = compat_expanduser
+# compat_os_makedirs
+try:
+ os.makedirs('.', exist_ok=True)
+ compat_os_makedirs = os.makedirs
+except TypeError: # < Py3.2
+ from errno import EEXIST as _errno_EEXIST
+
+ def compat_os_makedirs(name, mode=0o777, exist_ok=False):
+ try:
+ return os.makedirs(name, mode=mode)
+ except OSError as ose:
+ if not (exist_ok and ose.errno == _errno_EEXIST):
+ raise
+
+
# compat_os_path_realpath
if compat_os_name == 'nt' and sys.version_info < (3, 8):
# os.path.realpath on Windows does not follow symbolic links
@@ -3637,6 +3652,7 @@ __all__ = [
'compat_numeric_types',
'compat_open',
'compat_ord',
+ 'compat_os_makedirs',
'compat_os_name',
'compat_os_path_expanduser',
'compat_os_path_realpath',