def open( mode="w+b", suffix="", prefix=tempfile.template, dir="/tmp" ) -> AiofilesContextManager: """ Create and return a temporary file. Args: mode: The mode argument to io.open (default "w+b"). suffix: If 'suffix' is not None, the file name will end with that suffix, otherwise there will be no suffix. prefix:If 'prefix' is not None, the file name will begin with that prefix, otherwise a default prefix is used. dir: If 'dir' is not None, the file will be created in that directory, otherwise a default directory is used. Returns: The corresponding temporary file. """ # pylint: disable=protected-access name = next(tempfile._RandomNameSequence()) path = Path(dir).joinpath(f"{prefix}{name}{suffix}") # aiofiles_context_manager = aiofiles.open(path, mode=mode) aiofiles_context_manager = AiofilesContextManager(_open(path, mode=mode)) aiofiles_context_manager.__setattr__("name", str(path)) return aiofiles_context_manager
def TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, loop=None, executor=None): """Async open an unnamed temporary file""" return AiofilesContextManager( _temporary_file(named=False, mode=mode, buffering=buffering, encoding=encoding, newline=newline, suffix=suffix, prefix=prefix, dir=dir, loop=loop, executor=executor))
def SpooledTemporaryFile(max_size=0, mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, loop=None, executor=None): """Async open a spooled temporary file""" return AiofilesContextManager( _spooled_temporary_file(max_size=max_size, mode=mode, buffering=buffering, encoding=encoding, newline=newline, suffix=suffix, prefix=prefix, dir=dir, loop=loop, executor=executor))
def TemporaryDirectory(loop=None, executor=None): """Async open a temporary directory""" return AiofilesContextManager( _temporary_directory(loop=loop, executor=executor))