import asyncio
import base64
+import collections
import ctypes
import getpass
import html
import shutil
import socket
import struct
+import subprocess
import sys
import tokenize
import urllib
asyncio.run = compat_asyncio_run
+try: # >= 3.7
+ asyncio.tasks.all_tasks
+except AttributeError:
+ asyncio.tasks.all_tasks = asyncio.tasks.Task.all_tasks
+
+try:
+ import websockets as compat_websockets
+except ImportError:
+ compat_websockets = None
+
# Python 3.8+ does not honor %HOME% on windows, but this breaks compatibility with youtube-dl
# See https://github.com/yt-dlp/yt-dlp/issues/792
# https://docs.python.org/3/library/os.path.html#os.path.expanduser
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
+ 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)
+ WINDOWS_VT_MODE = True
+ except Exception:
+ pass
+
+
# Deprecated
compat_basestring = str
compat_chr = chr
+compat_filter = filter
compat_input = input
compat_integer_types = (int, )
compat_kwargs = lambda kwargs: kwargs
+compat_map = map
compat_numeric_types = (int, float, complex)
compat_str = str
compat_xpath = lambda xpath: xpath
compat_zip = zip
+compat_collections_abc = collections.abc
compat_HTMLParser = html.parser.HTMLParser
compat_HTTPError = urllib.error.HTTPError
compat_Struct = struct.Struct
# Set public objects
__all__ = [
+ 'WINDOWS_VT_MODE',
'compat_HTMLParseError',
'compat_HTMLParser',
'compat_HTTPError',
'compat_b64decode',
'compat_basestring',
'compat_chr',
+ 'compat_collections_abc',
'compat_cookiejar',
'compat_cookiejar_Cookie',
'compat_cookies',
'compat_etree_fromstring',
'compat_etree_register_namespace',
'compat_expanduser',
+ 'compat_filter',
'compat_get_terminal_size',
'compat_getenv',
'compat_getpass',
'compat_integer_types',
'compat_itertools_count',
'compat_kwargs',
+ 'compat_map',
'compat_numeric_types',
'compat_ord',
'compat_os_name',
'compat_urllib_response',
'compat_urlparse',
'compat_urlretrieve',
+ 'compat_websockets',
'compat_xml_parse_error',
'compat_xpath',
'compat_zip',
+ 'windows_enable_vt_mode',
'workaround_optparse_bug9161',
]