def findResource(resource, request):
    """Traverse resource tree to find who will handle the request."""
    while request.postpath and not resource.isLeaf:
        #print 'findResource:', resource, request.postpath
        pathElement = request.postpath.pop(0)
        request.prepath.append(pathElement)
        next = resource.getPathResource(pathElement, request)
        if not next: break
        resource = next
    return resource