[compat] Suppress errors in enabling VT mode

Closes #1932
This commit is contained in:
pukkandan 2021-12-08 19:41:54 +05:30
parent ddd24c9949
commit e3c7d49571
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698
3 changed files with 14 additions and 3 deletions

View File

@ -3394,7 +3394,8 @@ class YoutubeDL(object):
def get_encoding(stream): def get_encoding(stream):
ret = getattr(stream, 'encoding', 'missing (%s)' % type(stream).__name__) ret = getattr(stream, 'encoding', 'missing (%s)' % type(stream).__name__)
if not supports_terminal_sequences(stream): if not supports_terminal_sequences(stream):
ret += ' (No ANSI)' from .compat import WINDOWS_VT_MODE
ret += ' (No VT)' if WINDOWS_VT_MODE is False else ' (No ANSI)'
return ret return ret
encoding_str = 'Encodings: locale %s, fs %s, out %s, err %s, pref %s' % ( encoding_str = 'Encodings: locale %s, fs %s, out %s, err %s, pref %s' % (

View File

@ -160,12 +160,20 @@ except ImportError:
compat_pycrypto_AES = None compat_pycrypto_AES = None
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 def windows_enable_vt_mode(): # TODO: Do this the proper way https://bugs.python.org/issue30075
if compat_os_name != 'nt': if compat_os_name != 'nt':
return return
global WINDOWS_VT_MODE
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
try:
subprocess.Popen('', shell=True, startupinfo=startupinfo) subprocess.Popen('', shell=True, startupinfo=startupinfo)
WINDOWS_VT_MODE = True
except Exception:
pass
# Deprecated # Deprecated
@ -226,6 +234,7 @@ compat_xml_parse_error = etree.ParseError
# Set public objects # Set public objects
__all__ = [ __all__ = [
'WINDOWS_VT_MODE',
'compat_HTMLParseError', 'compat_HTMLParseError',
'compat_HTMLParser', 'compat_HTMLParser',
'compat_HTTPError', 'compat_HTTPError',

View File

@ -6592,7 +6592,8 @@ def jwt_decode_hs256(jwt):
def supports_terminal_sequences(stream): def supports_terminal_sequences(stream):
if compat_os_name == 'nt': if compat_os_name == 'nt':
if get_windows_version() < (10, 0, 10586): from .compat import WINDOWS_VT_MODE # Must be imported locally
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'):
return False return False