def filter_url(url, method='get', remote='0.0.0.0',
               out=False, app=False, lang=None,
               domain=(None, None), env=False, scheme=None,
               host=None, port=None):
    """
    doctest/unittest interface to regex_filter_in() and regex_filter_out()
    """
    match = regex_full_url.match(url)
    urlscheme = match.group('scheme').lower()
    urlhost = match.group('host').lower()
    uri = match.group('uri')
    k = uri.find('?')
    if k < 0:
        k = len(uri)
    if isinstance(domain, str):
        domain = (domain, None)
    (path_info, query_string) = (uri[:k], uri[k + 1:])
    path_info = urllib.unquote(path_info)   # simulate server
    e = {
        'REMOTE_ADDR': remote,
        'REQUEST_METHOD': method,
        'wsgi.url_scheme': urlscheme,
        'HTTP_HOST': urlhost,
        'REQUEST_URI': uri,
        'PATH_INFO': path_info,
        'QUERY_STRING': query_string,
        #for filter_out request.env use lowercase
        'remote_addr': remote,
        'request_method': method,
        'wsgi_url_scheme': urlscheme,
        'http_host': urlhost
    }

    request = Storage()
    e["applications_parent"] = global_settings.applications_parent
    request.env = Storage(e)
    request.uri_language = lang

    #  determine application only
    #
    if app:
        if routers:
            return map_url_in(request, e, app=True)
        return regex_select(e)

    #  rewrite outbound URL
    #
    if out:
        (request.env.domain_application,
         request.env.domain_controller) = domain
        items = path_info.lstrip('/').split('/')
        if items[-1] == '':
            items.pop()  # adjust trailing empty args
        assert len(items) >= 3, "at least /a/c/f is required"
        a = items.pop(0)
        c = items.pop(0)
        f = items.pop(0)
        if not routers:
            return regex_filter_out(uri, e)
        acf = map_url_out(
            request, None, a, c, f, items, None, scheme, host, port)
        if items:
            url = '%s/%s' % (acf, '/'.join(items))
            if items[-1] == '':
                url += '/'
        else:
            url = acf
        if query_string:
            url += '?' + query_string
        return url

    #  rewrite inbound URL
    #
    (static, version, e) = url_in(request, e)
    if static:
        return static
    result = "/%s/%s/%s" % (
        request.application, request.controller, request.function)
    if request.extension and request.extension != 'html':
        result += ".%s" % request.extension
    if request.args:
        result += " %s" % request.args
    if e['QUERY_STRING']:
        result += " ?%s" % e['QUERY_STRING']
    if request.uri_language:
        result += " (%s)" % request.uri_language
    if env:
        return request.env
    return result
dataset/ETHPy150Open uwdata/termite-visualizations/web2py/gluon/rewrite.py/filter_url/original