<s> """<STR_LIT>""" <EOL> from . import errors <EOL> from . import locations <EOL> from . import scoping <EOL> class InjectionContextFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , is_scope_usable_from_scope_fn ) : <EOL> """<STR_LIT>""" <EOL> self . _is_scope_usable_from_scope_fn = is_scope_usable_from_scope_fn <EOL> def new ( self , injection_site_fn ) : <EOL> """<STR_LIT>""" <EOL> return _InjectionContext ( <EOL> injection_site_fn , binding_stack = [ ] , scope_id = scoping . UNSCOPED , <EOL> is_scope_usable_from_scope_fn = self . _is_scope_usable_from_scope_fn ) <EOL> class _InjectionContext ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , injection_site_fn , binding_stack , scope_id , <EOL> is_scope_usable_from_scope_fn ) : <EOL> """<STR_LIT>""" <EOL> self . _injection_site_fn = injection_site_fn <EOL> self . _binding_stack = binding_stack <EOL> self . _scope_id = scope_id <EOL> self . _is_scope_usable_from_scope_fn = is_scope_usable_from_scope_fn <EOL> def get_child ( self , injection_site_fn , binding ) : <EOL> """<STR_LIT>""" <EOL> child_scope_id = binding . scope_id <EOL> new_binding_stack = self . _binding_stack + [ binding ] <EOL> if binding in self . _binding_stack : <EOL> raise errors . CyclicInjectionError ( new_binding_stack ) <EOL> if not self . _is_scope_usable_from_scope_fn ( <EOL> child_scope_id , self . _scope_id ) : <EOL> raise errors . BadDependencyScopeError ( <EOL> self . get_injection_site_desc ( ) , <EOL> self . _scope_id , child_scope_id , binding . binding_key ) <EOL> return _InjectionContext ( <EOL> injection_site_fn , new_binding_stack , child_scope_id , <EOL> self . _is_scope_usable_from_scope_fn ) <EOL> def get_injection_site_desc ( self ) : <EOL> """<STR_LIT>""" <EOL> return locations . get_name_and_loc ( self . _injection_site_fn ) </s>
