mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-08-21 05:44:02 -07:00
[compat] Add and use compat_open()
like Py3 open()
* resolves FIXME: ytdl-org/youtube-dl/commit/dfe5fa4
This commit is contained in:
parent
557dbac173
commit
78da22489b
2 changed files with 13 additions and 4 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue