Here is a patch [1] that makes best_match in mimeparse.py respect the
order of the list of supplied supported mime types. I have a situation
where multiple representations are available for a resource. When
clients request both mime types with equal preference, best_match
returns the one that sorted alphabetically last...and I actually want
to prefer the one that sorts alphabetically earlier.
For example, I have application/json and text/html representations
available for a resource. If the cilent doesn't prefer one over the
other I want to return the application/json. Here's what I saw before
the patch:
>>> best_match(['text/html', 'application/json'], '*/*')
'text/html'
With this patch the supported mime types are in order from least
desirable to most desirable, so you'll see:
>>> best_match(['text/html', 'application/json'], '*/*')
'application/json'
Not sure if it's worth patching mimeparse.py since I guess this will
be divergent behavior with the other language libraries. But I figured
it was at least worth sharing with y'all to see if I was doing
something wrong.
//Ed
[1]
http://groups.google.com/group/mimeparse-dev/web/best_match_order.patch