##// END OF EJS Templates
Chaged tempfiles and tempdire to be Path from Pathlib
bar-hen -
Show More
@@ -757,6 +757,7 b' class InteractiveShell(SingletonConfigurable):'
757 757 self.meta = Struct()
758 758
759 759 # Temporary files used for various purposes. Deleted at exit.
760 # The files here are stored with Path from Pathlib
760 761 self.tempfiles = []
761 762 self.tempdirs = []
762 763
@@ -3595,16 +3596,17 b' class InteractiveShell(SingletonConfigurable):'
3595 3596 - data(None): if data is given, it gets written out to the temp file
3596 3597 immediately, and the file is closed again."""
3597 3598
3598 dirname = tempfile.mkdtemp(prefix=prefix)
3599 self.tempdirs.append(dirname)
3599 dir_path = Path(tempfile.mkdtemp(prefix=prefix))
3600 self.tempdirs.append(dir_path)
3600 3601
3601 handle, filename = tempfile.mkstemp('.py', prefix, dir=dirname)
3602 handle, filename = tempfile.mkstemp('.py', prefix, dir=str(dir_path))
3602 3603 os.close(handle) # On Windows, there can only be one open handle on a file
3603 self.tempfiles.append(filename)
3604
3605 file_path = Path(filename)
3606 self.tempfiles.append(file_path)
3604 3607
3605 3608 if data:
3606 with open(filename, 'w') as tmp_file:
3607 tmp_file.write(data)
3609 file_path.write_text(data)
3608 3610 return filename
3609 3611
3610 3612 @undoc
@@ -3761,14 +3763,14 b' class InteractiveShell(SingletonConfigurable):'
3761 3763 # Cleanup all tempfiles and folders left around
3762 3764 for tfile in self.tempfiles:
3763 3765 try:
3764 os.unlink(tfile)
3765 except OSError:
3766 tfile.unlink()
3767 except FileNotFoundError:
3766 3768 pass
3767 3769
3768 3770 for tdir in self.tempdirs:
3769 3771 try:
3770 os.rmdir(tdir)
3771 except OSError:
3772 tdir.rmdir()
3773 except FileNotFoundError:
3772 3774 pass
3773 3775
3774 3776 # Clear all user namespaces to release all references cleanly.
General Comments 0
You need to be logged in to leave comments. Login now