def route_request(self, request):
        """
        Determine which request handler to use for the given request, execute
        that handler, and return its output.
        """
        domain = request.hostname
        path = urllib.unquote_plus(request.path)
        matcher = domain + path
        method = request.method.upper()
        available_methods = set()

        request._rule_headers = None
        request._rule_content_type = None

        for dmn, dkey, rules in self._route_list:
            # Do basic domain matching.
            if ':' in dmn:
                if not request.host.lower().endswith(dmn):
                    continue
            elif not domain.endswith(dmn):
                continue

            # Iterate through the available rules, trying for a match.
            for rule, regex, rkey, name, method_table, names, namegen, \
                    converters in rules:
                if not path.startswith(rule):
                    continue
                match = regex.match(matcher)
                if match is None:
                    continue

                # We have a match. Check for a valid method.
                if not method in method_table:
                    available_methods.update(method_table.keys())
                    continue

                # It's a match. Run the method and return the result.
                request.route_name = name
                request.match = match

                try:
                    func, headers, content_type, hooks = method_table[method]
                    request._rule_headers = headers
                    request._rule_content_type = content_type
                    request._hooks = hooks

                    hks = hooks.get('request_started')
                    if hks:
                        for hf in hks:
                            hf(request)

                    output = func(request)

                    if request.auto_finish:
                        hks = hooks.get('request_finished')
                        if hks:
                            # Make sure the request_finished handler always gets
                            # an instance of Response. This way, it's always
                            # possible for it to be changed without taking
                            # return values.
                            if not isinstance(output, Response):
                                if isinstance(output, tuple):
                                    out = Response(*output)
                                else:
                                    out = Response(output)

                            for hf in hks:
                                hf(request, output)

                    return output

                except HTTPException as err:
                    request._rule_headers = None
                    request._rule_content_type = None

                    err_handler = getattr(self, "handle_%d" % err.status, None)
                    if err_handler:
                        return err_handler(request, err)
                    else:
                        return error(err.message, err.status, err.headers,
                                     request=request)
                except HTTPTransparentRedirect as err:
                    request._rule_headers = None
                    request._rule_content_type = None

                    request.url = err.url
                    request._parse_url()
                    return self.route_request(request)
                except Exception as err:
                    request._rule_headers = None
                    request._rule_content_type = None

                    return self.handle_500(request, err)

        if available_methods:
            if request.method == 'OPTIONS':
                return '', 200, {'Allow': ', '.join(available_methods)}
            else:
                return error(
                    "The method %s is not allowed for %r." % (method, path),
                    405, {'Allow': ', '.join(available_methods)}
                )

        elif self.fix_end_slash:
            # If there are no matching routes, and the path doesn't end with a
            # slash, try adding the slash.
            if not path[-1] == "/":
                path += "/"
                matcher += "/"
                for dmn, dkey, rules in self._route_list:
                    if dmn in ':':
                        if not request.host.lower().endswith(dmn):
                            continue
                    elif not domain.endswith(dmn):
                        continue

                    for rule, regex, rkey, name, method_table, names, namegen, \
                            converters in rules:
                        if not path.startswith(rule):
                            continue
                        if regex.match(matcher):
                            if request.query:
                                return redirect("%s?%s" %
                                                (path, request.query))
                            else:
                                return redirect(path)

        return self.handle_404(request, None)
dataset/ETHPy150Open ecdavis/pants/pants/web/application.py/Application.route_request/swapped operands of `in`