def put(self,dic,number=-1): if number == -1: number=self.get_length() dic["++unique++"]=str(number) con = PyTyrant.open("localhost") self.__put(dic,str(number),self.header) con.close()
def __put(self,scheme,number,header=""): for k,v in scheme.iteritems(): if type(v)==dict : self.__put(v,number,header+"/"+k) elif type(v) == str : query = header + "/" + k+"_"+number con = PyTyrant.open("localhost") con[query] = v con.close()
def raw_get(self,where="",number=-1): obj = {} query = self.header+"/"+where con = PyTyrant.open("localhost") ret = con.prefix_keys(query) for i in sorted(ret): if number==-1 or int(i.split("_")[-1]) == number : obj[i]=con[i] con.close() return obj
def lookup(address, host=None): name, addr = parseaddr(address) table = PyTyrant.open() user = table[addr] table.close() if host: return user + '@' + host else: return user
def get(self,where="",number=-1): if type(where)==str : where = [where] objs=[] con = PyTyrant.open("localhost") ret = [] for i in where : query = self.header+"/"+i ret += con.prefix_keys(query) for i in sorted(ret): ids=i.split("_")[-1] if number==-1 or ids == str(number) : item = self.__parse(i,con[i]) item.update({"ids":ids}) objs.append(item ) con.close() return sorted(objs)
def open_connection(self, host, port): self.db_conn = PyTyrant.open(host, int(port))
def delete_all(self): con=PyTyrant.open("localhost") ret = con.prefix_keys(self.header) for i in ret: del con[i] con.close()
def get_length(self): con = PyTyrant.open("localhost") query = self.header+"/"+"++unique++" length= len(con.prefix_keys(query)) con.close() return length
def delete(address): name, addr = parseaddr(address) table = PyTyrant.open() del table[addr] table.close()
def store(address, maps_to): name, addr = parseaddr(address) table = PyTyrant.open() table[addr] = maps_to table.close()