def add(self, rule, method, target, name=None):
anons = <NUM_LIT:0>  <EOL>keys = []  <EOL>pattern = '<STR_LIT>'  <EOL>filters = []  <EOL>builder = []  <EOL>is_static = True<EOL>for key, mode, conf in self._itertokens(rule):<EOL><INDENT>if mode:<EOL><INDENT>is_static = False<EOL>if mode == '<STR_LIT:default>': mode = self.default_filter<EOL>mask, in_filter, out_filter = self.filters[mode](conf)<EOL>if not key:<EOL><INDENT>pattern += '<STR_LIT>' % mask<EOL>key = '<STR_LIT>' % anons<EOL>anons += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>pattern += '<STR_LIT>' % (key, mask)<EOL>keys.append(key)<EOL><DEDENT>if in_filter: filters.append((key, in_filter))<EOL>builder.append((key, out_filter or str))<EOL><DEDENT>elif key:<EOL><INDENT>pattern += re.escape(key)<EOL>builder.append((None, key))<EOL><DEDENT><DEDENT>self.builder[rule] = builder<EOL>if name: self.builder[name] = builder<EOL>if is_static and not self.strict_order:<EOL><INDENT>self.static.setdefault(method, {})<EOL>self.static[method][self.build(rule)] = (target, None)<EOL>return<EOL><DEDENT>try:<EOL><INDENT>re_pattern = re.compile('<STR_LIT>' % pattern)<EOL>re_match = re_pattern.match<EOL><DEDENT>except re.error:<EOL><INDENT>raise RouteSyntaxError("<STR_LIT>" %<EOL>(rule, _e()))<EOL><DEDENT>if filters:<EOL><INDENT>def getargs(path):<EOL><INDENT>url_args = re_match(path).groupdict()<EOL>for name, wildcard_filter in filters:<EOL><INDENT>try:<EOL><INDENT>url_args[name] = wildcard_filter(url_args[name])<EOL><DEDENT>except ValueError:<EOL><INDENT>raise HTTPError(<NUM_LIT>, '<STR_LIT>')<EOL><DEDENT><DEDENT>return url_args<EOL><DEDENT><DEDENT>elif re_pattern.groupindex:<EOL><INDENT>def getargs(path):<EOL><INDENT>return re_match(path).groupdict()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>getargs = None<EOL><DEDENT>flatpat = _re_flatten(pattern)<EOL>whole_rule = (rule, flatpat, target, getargs)<EOL>if (flatpat, method) in self._groups:<EOL><INDENT>if DEBUG:<EOL><INDENT>msg = '<STR_LIT>'<EOL>warnings.warn(msg % (method, rule), RuntimeWarning)<EOL><DEDENT>self.dyna_routes[method][<EOL>self._groups[flatpat, method]] = whole_rule<EOL><DEDENT>else:<EOL><INDENT>self.dyna_routes.setdefault(method, []).append(whole_rule)<EOL>self._groups[flatpat, method] = len(self.dyna_routes[method]) - <NUM_LIT:1><EOL><DEDENT>self._compile(method)<EOL>
Add a new rule or replace the target for an existing rule.