def delete_doc(self, doc): if doc.doc_id is None: raise errors.InvalidDocId() params = {'old_rev': doc.rev} res, headers = self._request_json('DELETE', ['doc', doc.doc_id], params) doc.make_tombstone() doc.rev = res['rev']
def put_doc(self, doc): if doc.doc_id is None: raise errors.InvalidDocId() params = {} if doc.rev is not None: params['old_rev'] = doc.rev res, headers = self._request_json('PUT', ['doc', doc.doc_id], params, doc.get_json(), 'application/json') doc.rev = res['rev'] return res['rev']
def put_doc(self, doc): if doc.doc_id is None: raise errors.InvalidDocId() self._check_doc_id(doc.doc_id) if self._has_conflicts(doc.doc_id): raise errors.ConflictedDoc() old_doc = self._get_doc(doc.doc_id) if old_doc and doc.rev is None and old_doc.is_tombstone(): new_rev = self._allocate_doc_rev(old_doc.rev) else: if old_doc is not None: if old_doc.rev != doc.rev: raise errors.RevisionConflict() else: if doc.rev is not None: raise errors.RevisionConflict() new_rev = self._allocate_doc_rev(doc.rev) doc.rev = new_rev self._put_and_update_indexes(old_doc, doc) return new_rev
def _check_doc_id(self, doc_id): if not check_doc_id_re.match(doc_id): raise errors.InvalidDocId()