def getdatum(self): __func = gdp.gdp_event_getdatum __func.argtypes = [POINTER(self.gdp_event_t)] __func.restype = POINTER(_gdp.GDP_DATUM.gdp_datum_t) datum_ptr = __func(self.ptr) datum = _gdp.GDP_DATUM(ptr=datum_ptr) datum.event = self # garbage collection workaround return datum
def main(name_str, keyfile=None): # the data that will be written data = generate_random_data(1000, 1000) # XXX handling secret key at Python level doesn't work at the moment open_info = {} if keyfile is not None: skey = gdp.EP_CRYPTO_KEY(filename=keyfile, keyform=gdp.EP_CRYPTO_KEYFORM_PEM, flags=gdp.EP_CRYPTO_F_SECRET) open_info = {'skey': skey} gin_name = gdp.GDP_NAME(name_str) _name = "".join(["%0.2x" % ord(x) for x in gin_name.internal_name()]) print "opening", _name gin_handle = gdp.GDP_GIN(gin_name, gdp.GDP_MODE_RA, open_info) # writing the actual data for (idx, s) in enumerate(data): print "writing message", idx datum = gdp.GDP_DATUM() datum["buf"].write(s) # C implementation does not handle more than # a single datum appends at a time... yet. gin_handle.append_async([datum]) ## collect as many events as we had append operations for idx in xrange(len(data)): e = gin_handle.get_next_event(None) assert e["type"] == gdp.GDP_EVENT_CREATED or \ e["type"] == gdp.GDP_EVENT_SUCCESS ################################ #### reading the data back #### ################################ read_data = [] gin_handle.read_by_recno_async(-1 * len(data), len(data)) while True: e = gin_handle.get_next_event(None) if e["type"] == gdp.GDP_EVENT_DONE: break assert e["type"] == gdp.GDP_EVENT_DATA read_data.append(e["datum"]["buf"].peek()) print len(data), len(read_data) for idx in xrange(len(data)): # verify correctness if data[idx] == read_data[idx]: print "message %d matches" % idx
def main(name_str, keyfile): skey = gdp.EP_CRYPTO_KEY(filename=keyfile, keyform=gdp.EP_CRYPTO_KEYFORM_PEM, flags=gdp.EP_CRYPTO_F_SECRET) # Create a GDP_NAME object from a python string provided as argument _name = gdp.GDP_NAME(name_str) # There's a GCL with the given name, so let's open it gin_handle = gdp.GDP_GIN(_name, gdp.GDP_MODE_AO, open_info={'skey': skey}) datum = gdp.GDP_DATUM() while True: line = sys.stdin.readline().strip() # read from stdin datum["buf"].reset() datum["buf"].write(line) gin_handle.append(datum) # Write this datum to the GCL
def main(name_str, keyfile=None): # the data that will be written data = generate_random_data(100, 10) # XXX handling secret key at Python level doesn't work at the moment open_info = {} if keyfile is not None: skey = gdp.EP_CRYPTO_KEY(filename=keyfile, keyform=gdp.EP_CRYPTO_KEYFORM_PEM, flags=gdp.EP_CRYPTO_F_SECRET) open_info = {'skey': skey} gin_name = gdp.GDP_NAME(name_str) _name = "".join(["%0.2x" % ord(x) for x in gin_name.internal_name()]) print "opening", _name gin_handle = gdp.GDP_GIN(gin_name, gdp.GDP_MODE_RA, open_info) # writing the actual data datum = gdp.GDP_DATUM() # reusable datum for (idx, s) in enumerate(data): print "writing message", idx datum["buf"].reset() datum["buf"].write(s) gin_handle.append(datum) ################################ #### reading the data back #### ################################ # read by recno (synchronous) read_by_recno = [] for idx in xrange(-1*len(data),0): print "reading message", -1*idx, "from the end" datum = gin_handle.read_by_recno(idx) # -n => n-th record from end read_by_recno.append(datum["buf"].peek()) for idx in xrange(len(data)): # verify correctness if data[idx] == read_by_recno[idx]: print "message %d matches" % idx