#NEWLINE# def name_from_value( self , value , default = core . UNSET , patterns = [ '*' ] ) : #NEWLINE# #INDENT# 'Find the longest name in the set of constants (optionally qualified by pattern)\n        which matches value.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# return max ( ( name for name in self . names ( patterns ) if ( self [ name ] == value ) ) , key = len ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# if ( default is core . UNSET ) : #NEWLINE# #INDENT# raise KeyError ( ( 'No constant matching name %s and value %s' % ( patterns , value ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return default