#NEWLINE# @ classmethod #NEWLINE# def _preprocess_tags( cls , tags ) : #NEWLINE# #INDENT# "Preprocess tags slightly to reduce the amount and don't\n        pollute the cache with tags that obviously don't get used\n        anyway.\n        " #NEWLINE# if ( not tags ) : #NEWLINE# #INDENT# return tags #NEWLINE# #UNINDENT# tags = { k . strip ( ) . lower ( ) : v for ( k , v ) in tags . iteritems ( ) } #NEWLINE# tags = { k : v for ( k , v ) in tags . iteritems ( ) if ( ( len ( k ) in range ( 2 , 64 ) ) and ( v >= 0 ) ) } #NEWLINE# limit = 42 #NEWLINE# if ( len ( tags ) > limit ) : #NEWLINE# #INDENT# if any ( tags . itervalues ( ) ) : #NEWLINE# #INDENT# min_val = ( max ( tags . itervalues ( ) ) / 3 ) #NEWLINE# tags = { k : v for ( k , v ) in tags . iteritems ( ) if ( v >= min_val ) } #NEWLINE# tags = sorted ( tags . iteritems ( ) , key = operator . itemgetter ( 1 ) , reverse = 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tags = sorted ( tags . iteritems ( ) , key = len ) #NEWLINE# #UNINDENT# tags = { k : v for ( k , v ) in tags [ : limit ] } #NEWLINE# #UNINDENT# return tags