#NEWLINE# def __new__( cls , module_name , bases , attributes ) : #NEWLINE# #INDENT# special_attributes = ( 'providers' , 'instances' , 'factories' , 'functions' ) #NEWLINE# module = super ( ModuleMetaclass , cls ) . __new__ ( providers , module_name , bases , { key : value for ( key , value ) in six . iteritems ( attributes ) if ( key not in special_attributes ) } ) #NEWLINE# providers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ancestor in reversed ( inspect . getmro ( module ) ) : #NEWLINE# #INDENT# if cls . _is_module_class ( ancestor ) : #NEWLINE# #INDENT# providers . update ( ancestor . providers ) #NEWLINE# #UNINDENT# #UNINDENT# already_provided = set ( ) #NEWLINE# providers_attribute = attributes . get ( 'providers' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# providers . update ( providers_attribute ) #NEWLINE# already_provided . update ( six . iterkeys ( providers_attribute ) ) #NEWLINE# def check_specification( key ) : #NEWLINE# #INDENT# if ( key in already_provided ) : #NEWLINE# #INDENT# raise InvalidConfigurationError ( module , 'Multiple sources defined for specification {spec}' . format ( spec = repr ( key ) ) ) #NEWLINE# #UNINDENT# already_provided . add ( key ) #NEWLINE# #UNINDENT# for ( key , value ) in six . iteritems ( attributes . get ( 'instances' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) : #NEWLINE# #INDENT# check_specification ( key ) #NEWLINE# providers [ key ] = InstanceProvider ( value ) #NEWLINE# #UNINDENT# for ( key , value ) in six . iteritems ( attributes . get ( 'factories' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) : #NEWLINE# #INDENT# check_specification ( key ) #NEWLINE# if ( not isinstance ( value , collections . Iterable ) ) : #NEWLINE# #INDENT# value = [ value ] #NEWLINE# #UNINDENT# if ( ( len ( value ) < 1 ) or ( len ( value ) > 2 ) ) : #NEWLINE# #INDENT# raise InvalidConfigurationError ( module , 'Wrong number of arguments for {spec} in `factories`.' . format ( spec = repr ( key ) ) ) #NEWLINE# #UNINDENT# providers [ key ] = FactoryProvider ( value [ 0 ] , scope = ( value [ 1 ] if ( len ( value ) > 1 ) else None ) ) #NEWLINE# #UNINDENT# for ( key , value ) in six . iteritems ( attributes . get ( 'functions' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) ) : #NEWLINE# #INDENT# check_specification ( key ) #NEWLINE# providers [ key ] = FunctionProvider ( value ) #NEWLINE# #UNINDENT# for ( key , value ) in six . iteritems ( attributes ) : #NEWLINE# #INDENT# if hasattr ( value , '__provides__' ) : #NEWLINE# #INDENT# check_specification ( value . __provides__ ) #NEWLINE# #UNINDENT# #UNINDENT# module . providers = providers #NEWLINE# return module