1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-07-10 07:18:33 +00:00
This commit is contained in:
c-basalt 2024-08-11 10:43:15 -04:00
parent 37a3bc2a4a
commit 8e39820adc

View File

@ -49,7 +49,7 @@ def cookie_jar_to_list(cookie_jar):
@contextlib.contextmanager
def _temp_file(content, *, mode='wt', encoding='utf-8', suffix=None, close=True):
if 'r' in mode:
if 'b' in mode:
encoding = None
temp_file_handle = tempfile.NamedTemporaryFile(mode, encoding=encoding, suffix=suffix, delete=False)
try:
@ -62,6 +62,26 @@ def _temp_file(content, *, mode='wt', encoding='utf-8', suffix=None, close=True)
os.remove(temp_file_handle.name)
@contextlib.contextmanager
def _tempfile_context():
handles = []
def _creater(content, *, mode='wt', encoding='utf-8', suffix=None, close=True):
encoding = None if 'b' in mode else encoding
handle = tempfile.NamedTemporaryFile(mode, encoding=encoding, suffix=suffix, delete=False)
handles.append(handle)
handle.write(content)
if close:
handle.close()
return handle
try:
yield _creater
finally:
for handle in handles:
with contextlib.suppress(OSError):
os.remove(handle.name)
class ExternalJSI:
@classproperty(cache=True)
def version(cls):