#NEWLINE# def match_level( self , overlay ) : #NEWLINE# #INDENT# '\n        Given an overlay, return the match level and applicable slice\n        of the overall overlay. The level an integer if there is a\n        match or None if there is no match.\n\n        The level integer is the number of matching components. Higher\n        values indicate a stronger match.\n        ' #NEWLINE# slice_width = len ( self . _pattern_spec ) #NEWLINE# if ( slice_width > len ( overlay ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# ( best_lvl , match_slice ) = ( 0 , None ) #NEWLINE# for i in range ( ( ( len ( overlay ) - slice_width ) + 1 ) ) : #NEWLINE# #INDENT# overlay_slice = overlay . values ( ) [ i : ( i + slice_width ) ] #NEWLINE# lvl = self . _slice_match_level ( overlay_slice ) #NEWLINE# if ( lvl is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( lvl > lvl ) : #NEWLINE# #INDENT# best_lvl = lvl #NEWLINE# match_slice = ( i , ( i + slice_width ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( ( best_lvl , match_slice ) if ( best_lvl != 0 ) else None )