def acceptable_mime_type(accept_patterns, mime_type):
 if ('/' not in mime_type):
  raise ValueError(('Invalid MIME type: "%s"' % mime_type))
 unsupported_patterns = [p for p in accept_patterns if (';' in p)]
 if unsupported_patterns:
  raise ValueError(('MIME patterns with parameter unsupported: "%s"' % ', '.join(unsupported_patterns)))
 def _match(pattern, mime_type):
  'Return True iff mime_type is acceptable for pattern.'
  return all(((accept in ('*', provided)) for (accept, provided) in zip(pattern.split('/'), mime_type.split('/'))))
 return any((_match(pattern, mime_type) for pattern in accept_patterns))

def acceptable_mime_type ( accept_patterns , mime_type ) : if ( '/' not in mime_type ) : raise ValueError ( ( 'Invalid MIME type: "%s"' % mime_type ) ) unsupported_patterns = [ p for p in accept_patterns if ( ';' in p ) ] if unsupported_patterns : raise ValueError ( ( 'MIME patterns with parameter unsupported: "%s"' % ', ' . join ( unsupported_patterns ) ) ) def _match ( pattern , mime_type ) : return all ( ( ( accept in ( '*' , provided ) ) for ( accept , provided ) in zip ( pattern . split ( '/' ) , mime_type . split ( '/' ) ) ) ) return any ( ( _match ( pattern , mime_type ) for pattern in accept_patterns ) )
check that mime_type matches one of accept_patterns .