def getChildForRequest(resource, request):
 while (request.postpath and (not resource.isLeaf)):
  pathElement = request.postpath.pop(0)
  request.prepath.append(pathElement)
  resource = resource.getChildWithDefault(pathElement, request)
 return resource

def getChildForRequest ( resource , 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 .