Store data <data> index by key <key>

    Args

    key <string> couchdb document id
    data <dict> data to store

def set(self, key, data, retry=0):

    """
    Store data <data> index by key <key>

    Args

    key <string> couchdb document id
    data <dict> data to store
    """

    try:

      if type(data) != dict:
        raise Exception("data needs to be of type <dict>")

      #t1 = time.time()

      if not data.has_key("_rev"):
        exists = self.bucket.get(key)
        if exists:
          data["_rev"] = exists.get("_rev")
      data["_id"] = key
      try:
        #print "Preparing save: %s %s" % (key, data)
        (id, rev) = self.bucket.save(data)
      except couchdb.http.ResourceConflict, inst:
        if retry > 0:
          if data.has_key("_rev"):
            del data["_rev"]
          retry -= 1
          return self.set(key, data, retry=retry)
        else:
          if self.logger:
            self.logger.error("Document update conflict '%s' on '%s', rev '%s'" % (inst, key, data.get("_rev")))
            return 0
          else:
            raise

      return rev

      #print "Saved in %.5f" % (time.time() - t1)
    except:
      raise