def compile_regex(k, v, env=None):
    """
    Preprocess and compile the regular expressions in routes_app/in/out
    The resulting regex will match a pattern of the form:

        [remote address]:[protocol]://[host]:[method] [path]

    We allow abbreviated regexes on input; here we try to complete them.
    """
    k0 = k  # original k for error reporting
    # bracket regex in ^...$ if not already done
    if not k[0] == '^':
        k = '^%s' % k
    if not k[-1] == '$':
        k = '%s$' % k
    # if there are no :-separated parts, prepend a catch-all for the IP address
    if k.find(':') < 0:
        # k = '^.*?:%s' % k[1:]
        k = '^.*?:https?://[^:/]+:[a-z]+ %s' % k[1:]
    # if there's no ://, provide a catch-all for the protocol, host & method
    if 0 < k.find('://'):
        i = k.find(':/')
        if i < 0:
            raise SyntaxError("routes pattern syntax error: path needs leading '/' [%s]" % k0)
        k = r'%s:https?://[^:/]+:[a-z]+ %s' % (k[:i], k[i + 1:])
    # $anything -> ?P<anything>.*
    for item in regex_anything.findall(k):
        k = k.replace(item, '(?P<anything>.*)')
    # $a (etc) -> ?P<a>\w+
    for item in regex_at.findall(k):
        k = k.replace(item, r'(?P<%s>\w+)' % item[1:])
    # same for replacement pattern, but with \g
    for item in regex_at.findall(v):
        v = v.replace(item, r'\g<%s>' % item[1:])
    return (re.compile(k, re.DOTALL), v, env or {})
dataset/ETHPy150Open uwdata/termite-visualizations/web2py/gluon/rewrite.py/compile_regex/swapped operands of `<`