From: Ben Darnell Date: Fri, 26 Mar 2010 22:55:04 +0000 (-0700) Subject: Make add_handlers (for multiple hostnames) usable with static_path (which X-Git-Tag: v1.0.0~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4ba918180ca292cc2f67a6793c8563cec0d1ac3;p=thirdparty%2Ftornado.git Make add_handlers (for multiple hostnames) usable with static_path (which forces the creation of a wildcard handler) by maintaining a sensible order for handler groups. --- diff --git a/tornado/web.py b/tornado/web.py index 4fa2aa301..072b261c4 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -934,7 +934,15 @@ class Application(object): if not host_pattern.endswith("$"): host_pattern += "$" handlers = [] - self.handlers.append((re.compile(host_pattern), handlers)) + # The handlers with the wildcard host_pattern are a special + # case - they're added in the constructor but should have lower + # precedence than the more-precise handlers added later. + # If a wildcard handler group exists, it should always be last + # in the list, so insert new groups just before it. + if self.handlers and self.handlers[-1][0].pattern == '.*$': + self.handlers.insert(-1, (re.compile(host_pattern), handlers)) + else: + self.handlers.append((re.compile(host_pattern), handlers)) for spec in host_handlers: if type(spec) is type(()):