def _recalculate_routes(self, processed=None, path=None, module=None,
                            nameprefix="", hooks=None):
        """
        This function does the heavy lifting of building the routing table, and
        it's called every time a route is updated. Fortunately, that generally
        only happens when the application is being created.
        """
        if path is None:
            # Initialize our storage variables.
            self._route_list = []
            self._route_table = {}
            self._name_table = {}

        # Get the unprocessed route table.
        routes = module._routes if module else self._routes
        modules = module._modules if module else self._modules
        mod_hooks = module.hooks if module else self.hooks

        # Update the name prefix.
        name = module.name if module else self.name
        if name:
            nameprefix = nameprefix + "." + name if nameprefix else name

        # Update the hooks system.
        if hooks:
            new_hooks = {}
            for k, v in hooks.iteritems():
                new_hooks[k] = v[:]
            hooks = new_hooks
        else:
            hooks = {}

        for k,v in mod_hooks.iteritems():
            if hooks in k:
                hooks[k].extend(v)
            else:
                hooks[k] = v[:]

        # Iterate through modules first, so our own rules are more important.
        for rule, mod in modules.iteritems():
            self._recalculate_routes(None, rule, mod, nameprefix, hooks)

        # Iterate through the unprocessed route table.
        for rule, table in routes.iteritems():
            # If path is set, and this isn't an absolute rule, merge the rule
            # with the path.
            if path and (rule[0] == "/" or not "/" in rule):
                if path[-1] == "/":
                    if rule[0] == "/":
                        rule = path + rule[1:]
                    else:
                        rule = path + rule
                else:
                    if rule[0] == "/":
                        rule = path + rule
                    else:
                        rule = path + "/" + rule

            # Parse the rule string.
            regex, converters, names, namegen, domain, rpath = \
                _rule_to_regex(rule)
            dkey, rkey = rule.split("/", 1)

            # Get the domain table.
            if not dkey in self._route_table:
                dt = self._route_table[dkey] = {}
                dl = dt[None] = [domain, dkey, []]
                self._route_list.append(dl)
            else:
                dt = self._route_table[dkey]
                dl = dt[None]

            # Determine if this is a new rule for the given domain.
            if not rkey in dt:
                rt = dt[rkey] = {}
                rl = rt[None] = [rpath, re.compile(regex), rkey, None, {},
                                 names, namegen, converters]
                dl[2].append(rl)
            else:
                rt = dt[rkey]
                rl = rt[None]

            # Get the method table
            method_table = rl[4]

            # Iterate through all the methods this rule provides.
            for method, (func, name, advanced, auto404, headers, content_type) \
                    in table.iteritems():
                method = method.upper()
                if method == 'GET' or rl[3] is None:
                    if nameprefix:
                        name = nameprefix + '.' + name
                    rl[3] = name
                if advanced:
                    for mthd in method_table:
                        if getattr(method_table[mthd], "wrapped_func", None) \
                                is func:
                            method_table[method] = method_table[mthd], \
                                                   headers, content_type
                            break
                    else:
                        method_table[method] = _get_runner(func, converters,
                                                            auto404), headers, \
                                                            content_type, hooks
                else:
                    method_table[method] = func, headers, content_type, hooks

            # Update the name table.
            self._name_table[rl[3]] = rl

        if path is None:
            # Sort everything.

            # Sort the domains first by the length of the domain key, in reverse
            # order; followed by the number of colons in the domain key, in
            # reverse order; and finally by the domain key alphabetically.
            self._route_list.sort(key=lambda x: (-len(x[1]), -(x[1].count(':')),
                                                 x[1]))

            # Sort the same way for each rule in each domain, but using the rule
            # key rather than the domain key.
            for domain, dkey, rl in self._route_list:
                rl.sort(key=lambda x: (-len(x[2]), -(x[2].count(':')), x[2]))

    ##### The Request Handler #################################################
dataset/ETHPy150Open ecdavis/pants/pants/web/application.py/Application._recalculate_routes/swapped operands of `in`