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