def transform_value(value): if isinstance(value, types.DictType): if "_id" in value and "_ns" in value: return DBRef(value["_ns"], transform_value(value["_id"])) else: return transform_dict(SON(value)) elif isinstance(value, types.ListType): return [transform_value(v) for v in value] return value
def make_ref(dbref): return DBRef(make_elem(dbref[0]), make_elem(dbref[1]))
def _get_object(data): (object, data) = _bson_to_dict(data) if "$ref" in object: return (DBRef(object["$ref"], object["$id"], object.get("$db", None)), data) return (object, data)
def _get_ref(data): (collection, data) = _get_c_string(data[4:]) (oid, data) = _get_oid(data) return (DBRef(collection, oid), data)
def object_hook(dct): if "$oid" in dct: return ObjectId(str(dct["$oid"])) if "$ref" in dct: return DBRef(dct["$ref"], dct["$id"], dct.get("$db", None)) return dct