<s> from contextlib import contextmanager <EOL> import io <EOL> import logging <EOL> import os <EOL> import threading <EOL> import sys <EOL> from . exceptions import ExceptionWrapper <EOL> LOG_FORMAT = "<STR_LIT>" <EOL> def enable_logging ( ) : <EOL> logging . basicConfig ( <EOL> level = logging . DEBUG , <EOL> format = LOG_FORMAT , <EOL> ) <EOL> if os . environ . get ( '<STR_LIT>' ) : <EOL> enable_logging ( ) <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> for x in ( '<STR_LIT>' , ) : <EOL> globals ( ) [ x ] = getattr ( log , x ) <EOL> def sort_names ( names ) : <EOL> """<STR_LIT>""" <EOL> return sorted ( names , key = lambda x : ( x . count ( '<STR_LIT:.>' ) , x ) ) <EOL> @ contextmanager <EOL> def cd ( where ) : <EOL> cwd = os . getcwd ( ) <EOL> os . chdir ( where ) <EOL> try : <EOL> yield <EOL> finally : <EOL> os . chdir ( cwd ) <EOL> def has_fileno ( stream ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return isinstance ( stream . fileno ( ) , int ) <EOL> except ( AttributeError , io . UnsupportedOperation ) : <EOL> return False <EOL> def isatty ( stream ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( stream , '<STR_LIT>' ) and callable ( stream . isatty ) : <EOL> return stream . isatty ( ) <EOL> elif has_fileno ( stream ) : <EOL> return os . isatty ( stream . fileno ( ) ) <EOL> return False <EOL> class ExceptionHandlingThread ( threading . Thread ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( ExceptionHandlingThread , self ) . __init__ ( ** kwargs ) <EOL> self . daemon = True <EOL> self . kwargs = kwargs <EOL> self . exc_info = None <EOL> def run ( self ) : <EOL> try : <EOL> super ( ExceptionHandlingThread , self ) . run ( ) <EOL> except BaseException : <EOL> self . exc_info = sys . exc_info ( ) <EOL> msg = "<STR_LIT>" <EOL> debug ( msg . format ( self . exc_info [ <NUM_LIT:1> ] , self . kwargs [ '<STR_LIT:target>' ] . __name__ ) ) <EOL> def exception ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . exc_info is None : <EOL> return None <EOL> return ExceptionWrapper ( self . kwargs , * self . exc_info ) </s>
