def score_match(pattern, mimetype):
 EXACT_TYPE = 1
 ANY_TYPE = 0.7
 EXACT_SUBTYPE = 1
 VND_SUBTYPE = 0.9
 ANY_SUBTYPE = 0.8
 score = 0
 if (pattern[0] == mimetype[0]):
  score += EXACT_TYPE
 elif (pattern[0] == u'*'):
  score += ANY_TYPE
 else:
  return 0
 if (pattern[1] == mimetype[1]):
  score += EXACT_SUBTYPE
 elif ((pattern[1] == u'*') or (mimetype[1] == u'*')):
  score += ANY_SUBTYPE
 else:
  pattern_subtype = pattern[1].split(u'+')
  mimetype_subtype = mimetype[1].split(u'+')
  if (len(mimetype_subtype) > 1):
   if (len(pattern_subtype) > 1):
    if (pattern_subtype[1] == mimetype_subtype[1]):
     score += VND_SUBTYPE
   elif (pattern_subtype[0] == mimetype_subtype[1]):
    score += VND_SUBTYPE
  elif (len(pattern_subtype) > 1):
   if (pattern_subtype[1] == mimetype_subtype[0]):
    score += VND_SUBTYPE
 return score

def score_match ( pattern , mimetype ) : EXACT_TYPE = 1 ANY_TYPE = 0.7 EXACT_SUBTYPE = 1 VND_SUBTYPE = 0.9 ANY_SUBTYPE = 0.8 score = 0 if ( pattern [ 0 ] == mimetype [ 0 ] ) : score += EXACT_TYPE elif ( pattern [ 0 ] == u'*' ) : score += ANY_TYPE else : return 0 if ( pattern [ 1 ] == mimetype [ 1 ] ) : score += EXACT_SUBTYPE elif ( ( pattern [ 1 ] == u'*' ) or ( mimetype [ 1 ] == u'*' ) ) : score += ANY_SUBTYPE else : pattern_subtype = pattern [ 1 ] . split ( u'+' ) mimetype_subtype = mimetype [ 1 ] . split ( u'+' ) if ( len ( mimetype_subtype ) > 1 ) : if ( len ( pattern_subtype ) > 1 ) : if ( pattern_subtype [ 1 ] == mimetype_subtype [ 1 ] ) : score += VND_SUBTYPE elif ( pattern_subtype [ 0 ] == mimetype_subtype [ 1 ] ) : score += VND_SUBTYPE elif ( len ( pattern_subtype ) > 1 ) : if ( pattern_subtype [ 1 ] == mimetype_subtype [ 0 ] ) : score += VND_SUBTYPE return score
return a score for how well the pattern matches the mimetype .