def update(self, data, oid, rsid): try: _ = self.db[oid][rsid] except KeyError: raise UnknownObject() _dat = json.loads(data) _d = dict([(c, v) for c, v in list(_dat.items()) if c in RSR and c != "_id"]) _new = ResourceSetResponse(**_d) _new["_id"] = rsid _new.verify() if _new: self.db[oid][rsid] = _new # new revision self.etag[rsid] = str(uuid.uuid4()) status = StatusResponse(_id=rsid) else: status = StatusResponse(_id=rsid) return status
def create(self, data, oid): rset = ResourceSetResponse().deserialize(data, "json") rset.weed() m = hashlib.md5(rset.to_json().encode("utf8")) rsid = m.hexdigest() rset["_id"] = rsid # Need to add _id before verifying rset.verify() try: self.db[oid][rsid] = rset except KeyError: self.db[oid] = {rsid: rset} # backward lookup table self.rsid2oid[rsid] = oid # add a revision number self.etag[rsid] = str(uuid.uuid4()) status = StatusResponse(_id=rsid) return status