def url_for(self, view_name: str, **kwargs):
<EOL>uri, route = self.router.find_route_by_view_name(view_name)<EOL>if not uri or not route:<EOL><INDENT>raise URLBuildError(<EOL>'<STR_LIT>'.format(<EOL>view_name))<EOL><DEDENT>if uri != '<STR_LIT:/>' and uri.endswith('<STR_LIT:/>'):<EOL><INDENT>uri = uri[:-<NUM_LIT:1>]<EOL><DEDENT>out = uri<EOL>matched_params = re.findall(<EOL>self.router.parameter_pattern, uri)<EOL>kwargs.pop('<STR_LIT>', None)<EOL>anchor = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>external = kwargs.pop('<STR_LIT>', False)<EOL>scheme = kwargs.pop('<STR_LIT>', '<STR_LIT>')<EOL>if scheme and not external:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>netloc = kwargs.pop('<STR_LIT>', None)<EOL>if netloc is None and external:<EOL><INDENT>netloc = self.config.get('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>for match in matched_params:<EOL><INDENT>name, _type, pattern = self.router.parse_parameter_string(<EOL>match)<EOL>specific_pattern = '<STR_LIT>'.format(pattern)<EOL>supplied_param = None<EOL>if kwargs.get(name):<EOL><INDENT>supplied_param = kwargs.get(name)<EOL>del kwargs[name]<EOL><DEDENT>else:<EOL><INDENT>raise URLBuildError(<EOL>'<STR_LIT>'.format(<EOL>name))<EOL><DEDENT>supplied_param = str(supplied_param)<EOL>passes_pattern = re.match(specific_pattern, supplied_param)<EOL>if not passes_pattern:<EOL><INDENT>if _type != str:<EOL><INDENT>msg = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(<EOL>supplied_param, name, _type.__name__, pattern))<EOL><DEDENT>else:<EOL><INDENT>msg = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(<EOL>supplied_param, name, pattern))<EOL><DEDENT>raise URLBuildError(msg)<EOL><DEDENT>replacement_regex = '<STR_LIT>'.format(name)<EOL>out = re.sub(<EOL>replacement_regex, supplied_param, out)<EOL><DEDENT>query_string = urlencode(kwargs, doseq=True) if kwargs else '<STR_LIT>'<EOL>out = urlunparse((scheme, netloc, out, '<STR_LIT>', query_string, anchor))<EOL>return out<EOL>
Build a URL based on a view name and the values provided.

        In order to build a URL, all request parameters must be supplied as
        keyword arguments, and each parameter must pass the test for the
        specified parameter type. If these conditions are not met, a
        `URLBuildError` will be thrown.

        Keyword arguments that are not request parameters will be included in
        the output URL's query string.

        :param view_name: string referencing the view name
        :param \*\*kwargs: keys and values that are used to build request
            parameters and query string arguments.

        :return: the built URL

        Raises:
            URLBuildError