def save(self, doc):
        if doc.id:
            return self.update(doc)
        else:
            return self.insert(doc)
def lock_temp(self, key):
    self.lock(key)
    try:
      yield
    finally:
      self.unlock(key)