<s> """<STR_LIT>""" <EOL> import os as _os <EOL> from tempfile import gettempdir , template <EOL> from tempfile import _text_openflags , _bin_openflags , _mkstemp_inner <EOL> class _TemporaryFileWrapper : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file , name , delete = True ) : <EOL> self . file = file <EOL> self . name = name <EOL> self . close_called = False <EOL> self . delete = delete <EOL> def __getattr__ ( self , name ) : <EOL> file = self . __dict__ [ '<STR_LIT:file>' ] <EOL> a = getattr ( file , name ) <EOL> if not issubclass ( type ( a ) , type ( <NUM_LIT:0> ) ) : <EOL> setattr ( self , name , a ) <EOL> return a <EOL> def __enter__ ( self ) : <EOL> self . file . __enter__ ( ) <EOL> return self <EOL> if _os . name != '<STR_LIT>' : <EOL> unlink = _os . unlink <EOL> def close ( self ) : <EOL> if not self . close_called : <EOL> self . close_called = True <EOL> self . file . close ( ) <EOL> if self . delete : <EOL> self . unlink ( self . name ) <EOL> def __del__ ( self ) : <EOL> self . close ( ) <EOL> def __exit__ ( self , exc , value , tb ) : <EOL> result = self . file . __exit__ ( exc , value , tb ) <EOL> self . close ( ) <EOL> return result <EOL> def NamedTemporaryFile ( mode = '<STR_LIT>' , bufsize = - <NUM_LIT:1> , suffix = "<STR_LIT>" , <EOL> prefix = template , dir = None , delete = True ) : <EOL> """<STR_LIT>""" <EOL> if dir is None : <EOL> dir = gettempdir ( ) <EOL> if '<STR_LIT:b>' in mode : <EOL> flags = _bin_openflags <EOL> else : <EOL> flags = _text_openflags <EOL> if _os . name == '<STR_LIT>' and delete : <EOL> flags |= _os . O_TEMPORARY <EOL> ( fd , name ) = _mkstemp_inner ( dir , prefix , suffix , flags ) <EOL> file = _os . fdopen ( fd , mode , bufsize ) <EOL> return _TemporaryFileWrapper ( file , name , delete ) </s>
