<s> import os <EOL> import sys <EOL> def get_console_type ( use_colors = True ) : <EOL> if use_colors and sys . stdout . isatty ( ) and sys . stderr . isatty ( ) : <EOL> import platform <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> import lixian_colors_win32 <EOL> return lixian_colors_win32 . WinConsole <EOL> else : <EOL> import lixian_colors_linux <EOL> return lixian_colors_linux . AnsiConsole <EOL> else : <EOL> import lixian_colors_console <EOL> return lixian_colors_console . Console <EOL> console_type = get_console_type ( ) <EOL> raw_console_type = get_console_type ( False ) <EOL> def Console ( use_colors = True ) : <EOL> return get_console_type ( use_colors ) ( ) <EOL> def get_softspace ( output ) : <EOL> if hasattr ( output , '<STR_LIT>' ) : <EOL> return output . softspace <EOL> import lixian_colors_console <EOL> if isinstance ( output , lixian_colors_console . Console ) : <EOL> return get_softspace ( output . output ) <EOL> return <NUM_LIT:0> <EOL> class ScopedColors ( console_type ) : <EOL> def __init__ ( self , * args ) : <EOL> console_type . __init__ ( self , * args ) <EOL> def __call__ ( self ) : <EOL> console = self <EOL> class Scoped : <EOL> def __enter__ ( self ) : <EOL> self . stdout = sys . stdout <EOL> softspace = get_softspace ( sys . stdout ) <EOL> sys . stdout = console <EOL> sys . stdout . softspace = softspace <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> softspace = get_softspace ( sys . stdout ) <EOL> sys . stdout = self . stdout <EOL> sys . stdout . softspace = softspace <EOL> return Scoped ( ) <EOL> class RawScopedColors ( raw_console_type ) : <EOL> def __init__ ( self , * args ) : <EOL> raw_console_type . __init__ ( self , * args ) <EOL> def __call__ ( self ) : <EOL> class Scoped : <EOL> def __enter__ ( self ) : <EOL> pass <EOL> def __exit__ ( self , type , value , traceback ) : <EOL> pass <EOL> return Scoped ( ) <EOL> class RootColors : <EOL> def __init__ ( self , use_colors = True ) : <EOL> self . use_colors = use_colors <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( ScopedColors ( ) if self . use_colors else RawScopedColors ( ) , name ) <EOL> def __call__ ( self , use_colors ) : <EOL> assert use_colors in ( True , False , None ) , use_colors <EOL> return RootColors ( use_colors ) <EOL> colors = RootColors ( ) </s>
