def _deferred_url_for(klass, context, fmt='schema', fragment=None):
    from sondra.document import Document
    from sondra.suite import Suite
    from sondra.application import Application
    from sondra.collection import Collection

    if isinstance(klass, str):
        if "/" in klass or ('.' not in klass):
            slug = klass
        else:
            modulename, classname = klass.rsplit('.', 1)
            klass = getattr(importlib.import_module(modulename), classname)
            slug = klass.slug
    else:
        slug = klass.slug

    if isinstance(context, Suite):
        suite = context
    elif isinstance(context, Application):
        suite = context.suite
    elif isinstance(context, Collection):
        suite = context.application.suite
    elif isinstance(context, Document):
        suite = context.collection.application.suite
    elif context is None:
        suite = context
    else:
        raise ValueError("Context must be an instance of Application, Document, Collection, Suite, or None")

    ret = ""
    if issubclass(klass, Document):
        for app in suite.values():
            for coll in app.values():
                if coll.document_class is klass:
                    ret = coll.url + ';' + fmt
                    if fragment:
                        return ret + ';schema' + fragment
                    else:
                        return ret + ';schema'
        else:
            raise KeyError("Cannot find document in a registered collection {0}".format(klass))
    elif issubclass(klass, Collection):
        for app in suite.applications.values():
            if app in slug:
                ret = app[slug].url
                break
        else:
            raise KeyError("Cannot find collection in a registered application {0}".format(klass))
    elif issubclass(klass, Application):
        ret = suite[slug].url + ';' + fmt
    elif issubclass(klass, Suite):
        ret = suite.url
    else:
        raise ValueError("Target class must be an Application, Document, Collection, or Suite")

    if fragment:
        return ret + ";schema" + fragment
    else:
        return ret + ';schema'
dataset/ETHPy150Open JeffHeard/sondra/sondra/lazy.py/_deferred_url_for/swapped operands of `in`