'Find the right page handler, and set request.config.'

def find_handler(self, path_info):

    import routes
    request = cherrypy.serving.request
    config = routes.request_config()
    config.mapper = self.mapper
    if hasattr(request, 'wsgi_environ'):
        config.environ = request.wsgi_environ
    config.host = request.headers.get('Host', None)
    config.protocol = request.scheme
    config.redirect = self.redirect
    result = self.mapper.match(path_info)
    config.mapper_dict = result
    params = {}
    if result:
        params = result.copy()
    if (not self.full_result):
        params.pop('controller', None)
        params.pop('action', None)
    request.params.update(params)
    request.config = base = cherrypy.config.copy()
    curpath = ''
    def merge(nodeconf):
        if ('tools.staticdir.dir' in nodeconf):
            nodeconf['tools.staticdir.section'] = (curpath or '/')
        base.update(nodeconf)
    app = request.app
    root = app.root
    if hasattr(root, '_cp_config'):
        merge(root._cp_config)
    if ('/' in app.config):
        merge(app.config['/'])
    atoms = [x for x in path_info.split('/') if x]
    if atoms:
        last = atoms.pop()
    else:
        last = None
    for atom in atoms:
        curpath = '/'.join((curpath, atom))
        if (curpath in app.config):
            merge(app.config[curpath])
    handler = None
    if result:
        controller = result.get('controller')
        controller = self.controllers.get(controller, controller)
        if controller:
            if isinstance(controller, classtype):
                controller = controller()
            if hasattr(controller, '_cp_config'):
                merge(controller._cp_config)
        action = result.get('action')
        if (action is not None):
            handler = getattr(controller, action, None)
            if hasattr(handler, '_cp_config'):
                merge(handler._cp_config)
        else:
            handler = controller
    if last:
        curpath = '/'.join((curpath, last))
        if (curpath in app.config):
            merge(app.config[curpath])
    return handler
