@@ -382,7 +382,7 @@ def _wrap_text(binary_handle):
382382
383383 # Fallback: pure-Python in-memory objects
384384 if isbytes :
385- f = io .BytesIO (init if init is not None else b"" )
385+ f = io .MkTempFile (init if init is not None else b"" )
386386 if reset_to_start :
387387 f .seek (0 )
388388 _created (f , "bytesio" )
@@ -589,7 +589,7 @@ def download_file_from_ftp_file(url):
589589 use_cwd = detect_cwd (ftp , file_dir )
590590 retr_path = os .path .basename (path ) if use_cwd else path
591591
592- bio = BytesIO ()
592+ bio = MkTempFile ()
593593 ftp .retrbinary ("RETR " + retr_path , bio .write )
594594 ftp .quit ()
595595 bio .seek (0 , 0 )
@@ -652,7 +652,7 @@ def upload_file_to_ftp_file(fileobj, url):
652652 return False
653653
654654def upload_file_to_ftp_string (data , url ):
655- bio = BytesIO (_to_bytes (data ))
655+ bio = MkTempFile (_to_bytes (data ))
656656 out = upload_file_to_ftp_file (bio , url )
657657 try :
658658 bio .close ()
@@ -681,7 +681,7 @@ def download_file_from_sftp_file(url):
681681 try :
682682 ssh .connect (host , port = port , username = user , password = pw , timeout = 10 )
683683 sftp = ssh .open_sftp ()
684- bio = BytesIO ()
684+ bio = MkTempFile ()
685685 sftp .getfo (path , bio )
686686 sftp .close ()
687687 ssh .close ()
@@ -735,7 +735,7 @@ def upload_file_to_sftp_file(fileobj, url):
735735 return False
736736
737737def upload_file_to_sftp_string (data , url ):
738- bio = BytesIO (_to_bytes (data ))
738+ bio = MkTempFile (_to_bytes (data ))
739739 out = upload_file_to_sftp_file (bio , url )
740740 try :
741741 bio .close ()
@@ -2550,7 +2550,7 @@ def _open_reader():
25502550 return fileobj
25512551 if can_reopen :
25522552 return open (file_path , "rb" )
2553- return BytesIO (data_bytes )
2553+ return MkTempFile (data_bytes )
25542554
25552555 class _Handler (BaseHTTPRequestHandler ):
25562556 server_version = "PyWWWGetCleanHTTP/1.0"
@@ -3023,7 +3023,7 @@ def _handle_upload(self):
30233023 outname = tf .name
30243024 outfp = tf
30253025 else :
3026- out = BytesIO ()
3026+ out = MkTempFile ()
30273027
30283028 total = 0
30293029 if length is not None :
@@ -3184,7 +3184,7 @@ def upload_file_to_internet_file(fileobj, url):
31843184 return False
31853185
31863186def upload_file_to_internet_string (data , url ):
3187- bio = BytesIO (_to_bytes (data ))
3187+ bio = MkTempFile (_to_bytes (data ))
31883188 out = upload_file_to_internet_file (bio , url )
31893189 try :
31903190 bio .close ()
0 commit comments