python - Tornado request handler mapping to international characters -
i want able match url requests internationalized characters, /comisión
. setup:
class application(tornado.web.application): def __init__(self): handlers = [ '''some handlers, , this: ''' (r"/([\w\:\,]+)", internationalizedhandler) ] tornado.web.application.__init__(self, handlers, **settings)
but setting locales in tornado doesn't seem right solution. how possible set regex catch characters such é,å,µ etc.? changing re
mode in python do?
tl;dr: it's impossible tornado's built-in router.
tornado buries regexp compiling handler patterns pretty deep, @stema's suggestion use re.unicode
flag difficult, because it's not clear pass in flag. there 2 ways tackle particular problem: subclass urlspec
, override __init__
function, or put flag prefix in pattern.
the first option lot of work. second option takes advantage of feature in python's re
module in patterns may specify (?u)
@ beginning of pattern instead of passing in re.unicode
flag parameter.
unfortunately, neither option work since tornado matches patterns against request url before percent-decoding unicode string. therefore, compiling pattern unicode flag has no effect since you're matching against percent-encoded ascii urls, not unicode strings.
Comments
Post a Comment