'Find the best match for request within the subtree, recursive
helper method for branch().
@param request: the request object'

def __branch(self, request):

    items = self.get_all(enabled=True)
    l = self.match(request)
    if (not items):
        return (self, l)
    else:
        (match, maxlevel) = (None, (l - 1))
        for i in items:
            (item, level) = i.__branch(request)
            if ((item is not None) and (level > maxlevel)):
                match = item
                maxlevel = level
        if (match is not None):
            return (match, maxlevel)
        else:
            return (self, l)
