<s> '''<STR_LIT>''' <EOL> import sys <EOL> try : <EOL> import pathlib <EOL> except : <EOL> from combi . _python_toolbox . third_party import pathlib <EOL> import io <EOL> from combi . _python_toolbox . context_management import ( ContextManager , <EOL> BlankContextManager ) <EOL> from combi . _python_toolbox . temp_value_setting import TempValueSetter <EOL> from combi . _python_toolbox . reasoned_bool import ReasonedBool <EOL> from combi . _python_toolbox import sequence_tools <EOL> class OutputCapturer ( ContextManager ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , stdout = True , stderr = True ) : <EOL> self . string_io = io . StringIO ( ) <EOL> if stdout : <EOL> self . _stdout_temp_setter = TempValueSetter ( ( sys , '<STR_LIT>' ) , self . string_io ) <EOL> else : <EOL> self . _stdout_temp_setter = BlankContextManager ( ) <EOL> if stderr : <EOL> self . _stderr_temp_setter = TempValueSetter ( ( sys , '<STR_LIT>' ) , self . string_io ) <EOL> else : <EOL> self . _stderr_temp_setter = BlankContextManager ( ) <EOL> def manage_context ( self ) : <EOL> '''<STR_LIT>''' <EOL> with self . _stdout_temp_setter , self . _stderr_temp_setter : <EOL> yield self <EOL> output = property ( lambda self : self . string_io . getvalue ( ) , <EOL> doc = '''<STR_LIT>''' ) <EOL> class TempSysPathAdder ( ContextManager ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , addition ) : <EOL> '''<STR_LIT>''' <EOL> self . addition = map ( <EOL> str , <EOL> sequence_tools . to_tuple ( addition , <EOL> item_type = ( str , pathlib . PurePath ) ) <EOL> ) <EOL> def __enter__ ( self ) : <EOL> self . entries_not_in_sys_path = [ entry for entry in self . addition if <EOL> entry not in sys . path ] <EOL> sys . path += self . entries_not_in_sys_path <EOL> return self <EOL> def __exit__ ( self , * args , ** kwargs ) : <EOL> for entry in self . entries_not_in_sys_path : <EOL> assert entry in sys . path <EOL> sys . path . remove ( entry ) <EOL> frozen = getattr ( sys , '<STR_LIT>' , None ) <EOL> '''<STR_LIT>''' <EOL> is_pypy = ( '<STR_LIT>' in sys . builtin_module_names ) <EOL> can_import_compiled_modules = ReasonedBool ( False , "<STR_LIT>" <EOL> "<STR_LIT>" ) if is_pypy else True </s>
