<s> """<STR_LIT>""" <EOL> import warnings as _warnings <EOL> import os as _os <EOL> import sys as _sys <EOL> from tempfile import mkdtemp <EOL> from . . ext . six import print_ <EOL> class TemporaryDirectory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , suffix = "<STR_LIT>" , prefix = "<STR_LIT>" , dir = None ) : <EOL> self . _closed = False <EOL> self . name = None <EOL> self . name = mkdtemp ( suffix , prefix , dir ) <EOL> def __enter__ ( self ) : <EOL> return self . name <EOL> def cleanup ( self , _warn = False ) : <EOL> if self . name and not self . _closed : <EOL> try : <EOL> self . _rmtree ( self . name ) <EOL> except ( TypeError , AttributeError ) as ex : <EOL> if "<STR_LIT:None>" not in str ( ex ) : <EOL> raise <EOL> print_ ( "<STR_LIT>" . format ( ex , <EOL> self , ) , <EOL> file = _sys . stderr ) <EOL> return <EOL> self . _closed = True <EOL> if _warn : <EOL> self . _warn ( "<STR_LIT>" . format ( self ) , <EOL> Warning ) <EOL> def __exit__ ( self , exc , value , tb ) : <EOL> self . cleanup ( ) <EOL> def __del__ ( self ) : <EOL> self . cleanup ( _warn = True ) <EOL> _listdir = staticmethod ( _os . listdir ) <EOL> _path_join = staticmethod ( _os . path . join ) <EOL> _isdir = staticmethod ( _os . path . isdir ) <EOL> _islink = staticmethod ( _os . path . islink ) <EOL> _remove = staticmethod ( _os . remove ) <EOL> _rmdir = staticmethod ( _os . rmdir ) <EOL> _warn = _warnings . warn <EOL> def _rmtree ( self , path ) : <EOL> for name in self . _listdir ( path ) : <EOL> fullname = self . _path_join ( path , name ) <EOL> try : <EOL> isdir = self . _isdir ( fullname ) and not self . _islink ( fullname ) <EOL> except OSError : <EOL> isdir = False <EOL> if isdir : <EOL> self . _rmtree ( fullname ) <EOL> else : <EOL> try : <EOL> self . _remove ( fullname ) <EOL> except OSError : <EOL> pass <EOL> try : <EOL> self . _rmdir ( path ) <EOL> except OSError : <EOL> pass </s>
