def wrap(value):
    """
    Wraps the given value in a Document or DocumentList as applicable.
    """
    if isinstance(value, Document) or isinstance(value, DocumentList):
        return value
    elif isinstance(value, dict):
        return Document(value)
    elif isinstance(value, list):
        return DocumentList(value)
    else:
        return value
Wraps the given value in a Document or DocumentList as applicable.