def traverse(path, request, resource):
    """
    Traverse a root resource, retrieving the appropriate child for the request.

    """
    path = path.lstrip(b'/')
    for component in (path and path.split(b'/')):
        if getattr(resource, 'is_leaf', False):
            break
        resource = resource.get_child(name=component, request=request)
    return resource
