'Adds a route between a URI path template and a resource.
Args:
uri_template (str): A URI template to use for the route
method_map (dict): A mapping of HTTP methods (e.g., \'GET\',
\'POST\') to methods of a resource object.
resource (object): The resource instance to associate with
the URI template.'

def add_route(self, uri_template, method_map, resource):

    if re.search('\\s', _FIELD_PATTERN.sub('{FIELD}', uri_template)):
        raise ValueError('URI    templates    may    not    include    whitespace.')
    path = uri_template.strip('/').split('/')
    used_names = set()
    for segment in path:
        self._validate_template_segment(segment, used_names)
    def insert(nodes, path_index=0):
        for node in nodes:
            segment = path[path_index]
            if node.matches(segment):
                path_index += 1
                if (path_index == len(path)):
                    node.method_map = method_map
                    node.resource = resource
                    node.uri_template = uri_template
                else:
                    insert(node.children, path_index)
                return
            if node.conflicts_with(segment):
                msg = textwrap.dedent("\n                                                                                                The    URI    template    for    this    route    is    inconsistent    or    conflicts    with    another\n                                                                                                route's    template.    This    is    usually    caused    by    configuring    a    field    converter\n                                                                                                differently    for    the    same    field    in    two    different    routes,    or    by    using\n                                                                                                different    field    names    at    the    same    level    in    the    path    (e.g.,\n                                                                                                '/parents/{id}'    and    '/parents/{parent_id}/children')\n                                                                                ").strip().replace('\n', '    ')
                raise ValueError(msg)
        new_node = CompiledRouterNode(path[path_index])
        nodes.append(new_node)
        if (path_index == (len(path) - 1)):
            new_node.method_map = method_map
            new_node.resource = resource
            new_node.uri_template = uri_template
        else:
            insert(new_node.children, (path_index + 1))
    insert(self._roots)
    self._find = self._compile()
