def regex_url_in(request, environ):
    "rewrite and parse incoming URL"

    # ##################################################
    # select application
    # rewrite URL if routes_in is defined
    # update request.env
    # ##################################################

    regex_select(env=environ, request=request)
    routes = THREAD_LOCAL.routes
    if routes.routes_in:
        environ = regex_filter_in(environ)
    request.env.update(
        (k.lower().replace('.', '_'), v) for k, v in environ.iteritems())

    # ##################################################
    # serve if a static file
    # ##################################################

    path = urllib.unquote(request.env.path_info) or '/'
    path = path.replace('\\', '/')
    if path.endswith('/') and len(path) > 1:
        path = path[:-1]
    match = regex_url.match(path)
    if not match:
        invalid_url(routes)
    request.raw_args = (match.group('s') or '')
    if request.raw_args.startswith('/'):
        request.raw_args = request.raw_args[1:]
    if match.group('c') == 'static':
        application = match.group('a')
        version, filename = None, match.group('z').replace(' ','_')
        if not filename:
            raise HTTP(404)
        items = filename.split('/', 1)
        if regex_version.match(items[0]):
            version, filename = items
        static_folder = pjoin(request.env.applications_parent,
                              'applications', application,'static')
        static_file = os.path.abspath(pjoin(static_folder,filename))
        if not static_file.startswith(static_folder):
            invalid_url(routes)
        return (static_file, version, environ)
    else:
        # ##################################################
        # parse application, controller and function
        # ##################################################
        request.application = match.group('a') or routes.default_application
        request.controller = match.group('c') or routes.default_controller
        request.function = match.group('f') or routes.default_function
        request.raw_extension = match.group('e')
        request.extension = request.raw_extension or 'html'
        if request.application in routes.routes_apps_raw:
            # application is responsible for parsing args
            request.args = None
        elif request.raw_args:
            args = regex_args.sub('_',request.raw_args)
            request.args = List(args.split('/'))
        else:
            request.args = List([])
    return (None, None, environ)
dataset/ETHPy150Open uwdata/termite-visualizations/web2py/gluon/rewrite.py/regex_url_in/original