As RFC 2616 media range in HTTP_ACCEPT should be specified as
media-range = ( "*/*"
| ( type "/" "*" )
| ( type "/" subtype )
) *( ";" parameter )
so when "all" is meant "*/*" should be passed, but some user agents, like the
facebook external link retriever pass '*' instead of '*/*' this makes
paste.util.mimeparse.best_match crash on paste.util.mimeparse.parse_mime_type
paste.util.mimeprase.best_match is used by Turbogears to detect which template
to render, and so each TG2 application crashes when contacted by facebook.
A solution is to change paste.util.mimeparse.parse_mime_type to support the
'*' syntax by adding
if parts[0].strip() == '*':
parts[0] = '*/*'
just before
(type, subtype) = parts[0].split("/")
this fixes the problem and I have already patched all my deployed TG2 apps,
but I think that a more general fix might be good and also people at paste and
mimeparse might be interested in having the patch. (This happens with
Paste-1.7.2 at least)
The working version of the parse_mime_type method is the following one:
def parse_mime_type(mime_type):
"""Carves up a mime_type and returns a tuple of the
(type, subtype, params) where 'params' is a dictionary
of all the parameters for the media range.
For example, the media range 'application/xhtml;q=0.5' would
get parsed into:
('application', 'xhtml', {'q', '0.5'})
"""
parts = mime_type.split(";")
params = dict([tuple([s.strip() for s in param.split("=")])\
for param in parts[1:] ])
if parts[0].strip() == '*':
parts[0] = '*/*'
(type, subtype) = parts[0].split("/")
return (type.strip(), subtype.strip(), params)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---