aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2023-04-05 18:39:54 +0100
committerdirkf <fieldhouse@gmx.net>2023-04-05 18:57:37 +0100
commit78da22489b483988e198a8352893df9c6cf34032 (patch)
tree9711bb65e3b6f960ce077ba77c00cb5d914be372 /youtube_dl/compat.py
parent557dbac173c30a51acd284b46f2d5460e539f51a (diff)
downloadyoutube-dl-78da22489b483988e198a8352893df9c6cf34032.tar.xz
[compat] Add and use `compat_open()` like Py3 `open()`
* resolves FIXME: ytdl-org/youtube-dl/commit/dfe5fa4
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 39551f810..fe62caf80 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -3127,6 +3127,16 @@ else:
return ctypes.WINFUNCTYPE(*args, **kwargs)
+if sys.version_info < (3, 0):
+ # open(file, mode='r', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True) not: opener=None
+ def compat_open(file_, *args, **kwargs):
+ if len(args) > 6 or 'opener' in kwargs:
+ raise ValueError('open: unsupported argument "opener"')
+ return io.open(file_, *args, **kwargs)
+else:
+ compat_open = open
+
+
legacy = [
'compat_HTMLParseError',
'compat_HTMLParser',
@@ -3185,6 +3195,7 @@ __all__ = [
'compat_kwargs',
'compat_map',
'compat_numeric_types',
+ 'compat_open',
'compat_ord',
'compat_os_name',
'compat_os_path_expanduser',