#NEWLINE# def add_or_get( self , name , klass ) : #NEWLINE# #INDENT# with self . lock : #NEWLINE# #INDENT# metric = self . metrics . get ( name ) #NEWLINE# if ( metric is not None ) : #NEWLINE# #INDENT# if ( not isinstance ( metric , klass ) ) : #NEWLINE# #INDENT# raise RegistryException ( '{0} is not of type {1}.' . format ( name , klass ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if inspect . isclass ( klass ) : #NEWLINE# #INDENT# metric = klass ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# metric = klass #NEWLINE# #UNINDENT# self . metrics [ name ] = metric #NEWLINE# #UNINDENT# return metric