MCPcopy Index your code
hub / github.com/python/cpython / createNewTempFile

Method createNewTempFile

Lib/test/test_urllib.py:639–653  ·  view source on GitHub ↗

Creates a new temporary file containing the specified data, registers the file for deletion during the test fixture tear down, and returns the absolute path of the file.

(self, data=b"")

Source from the content-addressed store, hash-verified

637 return urllib.request.pathname2url(filePath, add_scheme=True)
638
639 def createNewTempFile(self, data=b""):
640 """Creates a new temporary file containing the specified data,
641 registers the file for deletion during the test fixture tear down, and
642 returns the absolute path of the file."""
643
644 newFd, newFilePath = tempfile.mkstemp()
645 try:
646 self.registerFileForCleanUp(newFilePath)
647 newFile = os.fdopen(newFd, "wb")
648 newFile.write(data)
649 newFile.close()
650 finally:
651 try: newFile.close()
652 except: pass
653 return newFilePath
654
655 def registerFileForCleanUp(self, fileName):
656 self.tempFiles.append(fileName)

Callers 3

Calls 3

writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected