コード例 #1
0
ファイル: publish.py プロジェクト: webmaven/morepath
def resolve_model(request, mount):
    """Resolve path to a model using consumers.
    """
    lookup = request.lookup  # XXX can get this from argument too
    # consume steps toward model
    mounts = request.mounts
    model = mount
    mounts.append(model)
    while request.unconsumed:
        next_model = generic.consume(request, model, lookup=lookup)
        if next_model is None:
            return model
        model = next_model
        if isinstance(model, Mount):
            mounts.append(model)
        # get new lookup for whatever we found if it exists
        lookup = generic.lookup(model, lookup=lookup, default=lookup)
        request.lookup = lookup
    # if there is nothing (left), we consume toward a root model
    if not request.unconsumed:
        root_model = generic.consume(request, model, lookup=lookup)
        if root_model is not None:
            model = root_model
        # XXX handling mounting? lookups? write test cases
    request.lookup = lookup
    return model