mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-01-11 21:15:53 +01:00
[utils] Fix bug in 0b9c08b47b
* Cache of `supports_terminal_sequences` must be reset after enabling VT mode * and move `windows_enable_vt_mode` to utils to avoid cyclic imports
This commit is contained in:
parent
b801cd7179
commit
53973b4d2c
@ -33,7 +33,6 @@
|
|||||||
compat_str,
|
compat_str,
|
||||||
compat_urllib_error,
|
compat_urllib_error,
|
||||||
compat_urllib_request,
|
compat_urllib_request,
|
||||||
windows_enable_vt_mode,
|
|
||||||
)
|
)
|
||||||
from .cookies import load_cookies
|
from .cookies import load_cookies
|
||||||
from .downloader import FFmpegFD, get_suitable_downloader, shorten_protocol_name
|
from .downloader import FFmpegFD, get_suitable_downloader, shorten_protocol_name
|
||||||
@ -142,6 +141,7 @@
|
|||||||
url_basename,
|
url_basename,
|
||||||
variadic,
|
variadic,
|
||||||
version_tuple,
|
version_tuple,
|
||||||
|
windows_enable_vt_mode,
|
||||||
write_json_file,
|
write_json_file,
|
||||||
write_string,
|
write_string,
|
||||||
)
|
)
|
||||||
@ -3605,7 +3605,7 @@ def print_debug_header(self):
|
|||||||
def get_encoding(stream):
|
def get_encoding(stream):
|
||||||
ret = str(getattr(stream, 'encoding', 'missing (%s)' % type(stream).__name__))
|
ret = str(getattr(stream, 'encoding', 'missing (%s)' % type(stream).__name__))
|
||||||
if not supports_terminal_sequences(stream):
|
if not supports_terminal_sequences(stream):
|
||||||
from .compat import WINDOWS_VT_MODE # Must be imported locally
|
from .utils import WINDOWS_VT_MODE # Must be imported locally
|
||||||
ret += ' (No VT)' if WINDOWS_VT_MODE is False else ' (No ANSI)'
|
ret += ' (No VT)' if WINDOWS_VT_MODE is False else ' (No ANSI)'
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import contextlib
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
import xml.etree.ElementTree as etree
|
import xml.etree.ElementTree as etree
|
||||||
@ -74,17 +72,3 @@ def compat_expanduser(path):
|
|||||||
return userhome + path[i:]
|
return userhome + path[i:]
|
||||||
else:
|
else:
|
||||||
compat_expanduser = os.path.expanduser
|
compat_expanduser = os.path.expanduser
|
||||||
|
|
||||||
|
|
||||||
WINDOWS_VT_MODE = False if compat_os_name == 'nt' else None
|
|
||||||
|
|
||||||
|
|
||||||
def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.python.org/issue30075
|
|
||||||
if compat_os_name != 'nt':
|
|
||||||
return
|
|
||||||
global WINDOWS_VT_MODE
|
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
||||||
with contextlib.suppress(Exception):
|
|
||||||
subprocess.Popen('', shell=True, startupinfo=startupinfo).wait()
|
|
||||||
WINDOWS_VT_MODE = True
|
|
||||||
|
@ -55,3 +55,10 @@ def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
|
|||||||
compat_xpath = lambda xpath: xpath
|
compat_xpath = lambda xpath: xpath
|
||||||
compat_zip = zip
|
compat_zip = zip
|
||||||
workaround_optparse_bug9161 = lambda: None
|
workaround_optparse_bug9161 = lambda: None
|
||||||
|
|
||||||
|
|
||||||
|
def __getattr__(name):
|
||||||
|
if name in ('WINDOWS_VT_MODE', 'windows_enable_vt_mode'):
|
||||||
|
from .. import utils
|
||||||
|
return getattr(utils, name)
|
||||||
|
raise AttributeError(name)
|
||||||
|
@ -5094,10 +5094,12 @@ def jwt_decode_hs256(jwt):
|
|||||||
return payload_data
|
return payload_data
|
||||||
|
|
||||||
|
|
||||||
|
WINDOWS_VT_MODE = False if compat_os_name == 'nt' else None
|
||||||
|
|
||||||
|
|
||||||
@functools.cache
|
@functools.cache
|
||||||
def supports_terminal_sequences(stream):
|
def supports_terminal_sequences(stream):
|
||||||
if compat_os_name == 'nt':
|
if compat_os_name == 'nt':
|
||||||
from .compat import WINDOWS_VT_MODE # Must be imported locally
|
|
||||||
if not WINDOWS_VT_MODE or get_windows_version() < (10, 0, 10586):
|
if not WINDOWS_VT_MODE or get_windows_version() < (10, 0, 10586):
|
||||||
return False
|
return False
|
||||||
elif not os.getenv('TERM'):
|
elif not os.getenv('TERM'):
|
||||||
@ -5108,6 +5110,21 @@ def supports_terminal_sequences(stream):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.python.org/issue30075
|
||||||
|
if compat_os_name != 'nt':
|
||||||
|
return
|
||||||
|
global WINDOWS_VT_MODE
|
||||||
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
|
try:
|
||||||
|
subprocess.Popen('', shell=True, startupinfo=startupinfo).wait()
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
|
WINDOWS_VT_MODE = True
|
||||||
|
supports_terminal_sequences.cache_clear()
|
||||||
|
|
||||||
|
|
||||||
_terminal_sequences_re = re.compile('\033\\[[^m]+m')
|
_terminal_sequences_re = re.compile('\033\\[[^m]+m')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user