def regex_filter_out(url, e=None):
    "regex rewrite outgoing URL"
    if not hasattr(THREAD_LOCAL, 'routes'):
        regex_select()    # ensure routes is set (for application threads)
    routes = THREAD_LOCAL.routes
    if routers:
        return url  # already filtered
    if routes.routes_out:
        items = url.split('?', 1)
        if e:
            host = e.get('http_host', 'localhost').lower()
            i = host.find(':')
            if i > 0:
                host = host[:i]
            items[0] = '%s:%s://%s:%s %s' % \
                (e.get('remote_addr', ''),
                 e.get('wsgi_url_scheme', 'http').lower(), host,
                 e.get('request_method', 'get').lower(), items[0])
        else:
            items[0] = ':http://localhost:get %s' % items[0]
        for (regex, value, tmp) in routes.routes_out:
            if regex.match(items[0]):
                rewritten = '?'.join([regex.sub(value, items[0])] + items[1:])
                log_rewrite('routes_out: [%s] -> %s' % (url, rewritten))
                return rewritten
    log_rewrite('routes_out: [%s] not rewritten' % url)
    return url
dataset/ETHPy150Open uwdata/termite-visualizations/web2py/gluon/rewrite.py/regex_filter_out/original