def getChildForRequest(resource, request):
    """
    Traverse resource tree to find who will handle the request.
    """
    while request.postpath and not resource.isLeaf:
        pathElement = request.postpath.pop(0)
        request.prepath.append(pathElement)
        resource = resource.getChildWithDefault(pathElement, request)
    return resource

    Traverse resource tree to find who will handle the request.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/resource.py