Lines Matching defs:file
135 into file names. Each string is eight characters long. Multiple
188 trying to create and write to a file in that directory. If this
189 is successful, the test file is deleted. To prevent denial of
190 service, the name of the test file must be randomized."""
253 file = _os.path.join(dir, pre + name + suf)
254 _sys.audit("tempfile.mkstemp", file)
256 fd = _os.open(file, flags, 0o600)
267 return fd, file
270 "No usable temporary file name found")
323 file. The return value is a pair (fd, name) where fd is the
324 file descriptor returned by os.open, and name is the filename.
326 If 'suffix' is not None, the file name will end with that suffix,
329 If 'prefix' is not None, the file name will begin with that prefix,
332 If 'dir' is not None, the file will be created in that directory,
335 If 'text' is specified and true, the file is opened in text
336 mode. Else (the default) the file is opened in binary mode.
342 The file is readable and writable only by the creating user ID.
344 file is executable, the file is executable by no one. The file
347 Caller is responsible for deleting the file when done with it.
381 file = _os.path.join(dir, prefix + name + suffix)
382 _sys.audit("tempfile.mkdtemp", file)
384 _os.mkdir(file, 0o700)
395 return file
401 """User-callable function to return a unique temporary file name. The
402 file is not created.
405 not accepted, and suffix=None, prefix=None and bytes file names are not
408 THIS FUNCTION IS UNSAFE AND SHOULD NOT BE USED. The file name may
409 refer to a file that did not exist at some point, but by the time
424 file = _os.path.join(dir, prefix + name + suffix)
425 if not _exists(file):
426 return file
433 """A separate object allowing proper closing of a temporary file's
434 underlying file object, without adding a __del__ method to the
435 temporary file."""
437 file = None # Set here since __del__ checks it
440 def __init__(self, file, name, delete=True):
441 self.file = file
447 # file.name is useful (i.e. not "(fdopen)") with NamedTemporaryFile.
456 if not self.close_called and self.file is not None:
459 self.file.close()
464 # Need to ensure the file is deleted on __del__
472 self.file.close()
476 """Temporary file wrapper
480 remove the file when it is no longer needed.
483 def __init__(self, file, name, delete=True):
484 self.file = file
487 self._closer = _TemporaryFileCloser(file, name, delete)
490 # Attribute lookups are delegated to the underlying file
493 file = self.__dict__['file']
494 a = getattr(file, name)
500 # Avoid closing the file as long as the wrapper is alive,
509 # (self.file) so override it to return the wrapper
511 self.file.__enter__()
514 # Need to trap __exit__ as well to ensure the file gets
517 result = self.file.__exit__(exc, value, tb)
523 Close the temporary file, possibly deleting it.
529 # Don't return iter(self.file), but yield from it to avoid closing
530 # file as long as it's being used as iterator (see issue #23700). We
531 # can't use 'yield from' here because iter(file) returns the file
532 # object itself, which has a close method, and thus the file would get
534 for line in self.file:
541 """Create and return a temporary file.
548 'delete' -- whether the file is deleted on close (default True).
550 The file is created as mkstemp() would do it.
552 Returns an object with a file-like interface; the name of the file
553 is accessible as its 'name' attribute. The file will be automatically
558 Windows can delete the file even in this case.
566 # the file when it is closed. This is only supported by Windows.
579 file = _io.open(dir, mode, buffering=buffering,
583 raw = getattr(file, 'buffer', file)
586 return _TemporaryFileWrapper(file, name, delete)
588 file.close()
596 # On non-POSIX and Cygwin systems, assume that we cannot unlink a file
609 """Create and return a temporary file.
617 The file is created as mkstemp() would do it.
619 Returns an object with a file-like interface. The file has no
638 file = _io.open(dir, mode, buffering=buffering,
641 raw = getattr(file, 'buffer', file)
644 return file
657 # file (or a symbolic link to a regular file) with O_TMPFILE
673 file = _io.open(dir, mode, buffering=buffering,
676 raw = getattr(file, 'buffer', file)
679 return file
682 """Temporary file wrapper, specialized to switch from BytesIO
683 or StringIO to a real file when it exceeds a certain size or
707 def _check(self, file):
710 if max_size and file.tell() > max_size:
715 file = self._file
719 pos = file.tell()
721 newfile.buffer.write(file.detach().getvalue())
723 newfile.write(file.getvalue())
730 # BytesIO/StringIO instance to a real file. So we list
736 raise ValueError("Cannot enter context with closed file")
742 # file protocol
749 "Unclosed file {!r}".format(self),
841 file = self._file
842 rv = file.write(s)
843 self._check(file)
847 file = self._file
848 rv = file.writelines(iterable)
849 self._check(file)