<s> import abc <EOL> from . context_manager_type_type import ContextManagerTypeType <EOL> class ContextManagerType ( abc . ABCMeta ) : <EOL> '''<STR_LIT>''' <EOL> __metaclass__ = ContextManagerTypeType <EOL> def __new__ ( mcls , name , bases , namespace ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in namespace : <EOL> from . context_manager import ContextManager <EOL> manage_context = namespace [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in namespace : <EOL> raise Exception ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> if '<STR_LIT>' in namespace : <EOL> raise Exception ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> namespace [ '<STR_LIT>' ] = ContextManager . _ContextManager__enter_using_manage_context <EOL> namespace [ '<STR_LIT>' ] = ContextManager . _ContextManager__exit_using_manage_context <EOL> result_class = super ( ContextManagerType , mcls ) . __new__ ( <EOL> mcls , <EOL> name , <EOL> bases , <EOL> namespace <EOL> ) <EOL> if ( not result_class . __is_the_base_context_manager_class ( ) ) and ( '<STR_LIT>' not in namespace ) and hasattr ( result_class , '<STR_LIT>' ) : <EOL> from . context_manager import ContextManager <EOL> our_enter_uses_manage_context = ( <EOL> getattr ( result_class . __enter__ , '<STR_LIT>' , <EOL> result_class . __enter__ ) == ContextManager . _ContextManager__enter_using_manage_context . im_func <EOL> ) <EOL> our_exit_uses_manage_context = ( <EOL> getattr ( result_class . __exit__ , '<STR_LIT>' , <EOL> result_class . __exit__ ) == ContextManager . _ContextManager__exit_using_manage_context . im_func <EOL> ) <EOL> if our_exit_uses_manage_context and not our_enter_uses_manage_context : <EOL> assert '<STR_LIT>' in namespace <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> result_class ) <EOL> if our_enter_uses_manage_context and not our_exit_uses_manage_context : <EOL> assert '<STR_LIT>' in namespace <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> result_class ) <EOL> return result_class <EOL> def __is_the_base_context_manager_class ( cls ) : <EOL> '''<STR_LIT>''' <EOL> return ( <EOL> ( cls . __name__ == '<STR_LIT>' ) and <EOL> ( cls . __module__ == '<STR_LIT>' <EOL> '<STR_LIT>' ) and <EOL> ( cls . mro ( ) == [ cls , object ] ) <EOL> ) </s>
