예제 #1
0
 def out(self, key, as_raw=False):
     """Remove a Python object of a hash database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_out(self.db, c_key, c_key_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #2
0
 def memsync(self, phys):
     """Synchronize updating contents on memory of a hash database
     object."""
     result = tc.hdb_memsync(self.db, phys)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #3
0
 def memsync(self, phys):
     """Synchronize updating contents on memory of a hash database
     object."""
     result = tc.hdb_memsync(self.db, phys)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #4
0
 def fsiz(self):
     """Get the size of the database file of a hash database
     object."""
     result = tc.hdb_fsiz(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #5
0
 def out(self, key, as_raw=False):
     """Remove a Python object of a hash database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_out(self.db, c_key, c_key_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #6
0
 def fsiz(self):
     """Get the size of the database file of a hash database
     object."""
     result = tc.hdb_fsiz(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #7
0
 def sync(self):
     """Synchronize updated contents of a hash database object with
     the file and the device."""
     result = tc.hdb_sync(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #8
0
 def out(self, key):
     """Remove a string record of a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     result = tc.hdb_out2(self.db, key)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #9
0
 def defrag(self, step):
     """Perform dynamic defragmentation of a hash database
     object."""
     result = tc.hdb_defrag(self.db, step)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #10
0
 def sync(self):
     """Synchronize updated contents of a hash database object with
     the file and the device."""
     result = tc.hdb_sync(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #11
0
 def vsiz(self, key):
     """Get the size of the value of a Python object in a hash
     database object."""
     result = tc.hdb_vsiz2(self.db, key)
     if result == -1:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #12
0
 def out(self, key):
     """Remove a string record of a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     result = tc.hdb_out2(self.db, key)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #13
0
 def defrag(self, step):
     """Perform dynamic defragmentation of a hash database
     object."""
     result = tc.hdb_defrag(self.db, step)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #14
0
 def vsiz(self, key):
     """Get the size of the value of a Python object in a hash
     database object."""
     result = tc.hdb_vsiz2(self.db, key)
     if result == -1:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #15
0
 def fwmkeys(self, prefix, max_=-1, as_raw=True):
     """Get forward matching string keys in a hash database object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.hdb_fwmkeys(self.db, c_prefix, c_prefix_len, max_)
     if not tclist_objs:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
예제 #16
0
 def put(self, key, value, raw_key=False, raw_value=False):
     """Store any Python object into a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_put(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #17
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a record in a hash database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #18
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in a hash
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #19
0
 def vsiz(self, key, as_raw=False):
     """Get the size of the value of a Python object in a hash
     database object."""
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_vsiz(self.db, c_key, c_key_len)
     if result == -1:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #20
0
 def put(self, key, value):
     """Store a string record into a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     # assert isinstance(value, str), 'Value is not a string'
     result = tc.hdb_put2(self.db, key, value)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #21
0
 def add_float(self, key, num, as_raw=False):
     """Add a real number to a record in a hash database object."""
     assert isinstance(num, float), 'Value is not a float'
     (c_key, c_key_len) = util.serialize(key, as_raw)
     result = tc.hdb_adddouble(self.db, c_key, c_key_len, num)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #22
0
 def put(self, key, value, raw_key=False, raw_value=False):
     """Store any Python object into a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_put(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #23
0
 def put(self, key, value):
     """Store a string record into a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     # assert isinstance(value, str), 'Value is not a string'
     result = tc.hdb_put2(self.db, key, value)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #24
0
 def fwmkeys(self, prefix, max_=-1, as_raw=True):
     """Get forward matching string keys in a hash database object."""
     (c_prefix, c_prefix_len) = util.serialize(prefix, as_raw)
     tclist_objs = tc.hdb_fwmkeys(self.db, c_prefix, c_prefix_len, max_)
     if not tclist_objs:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     as_type = util.get_type(prefix, as_raw)
     return util.deserialize_tclist(tclist_objs, as_type)
예제 #25
0
 def putcat(self, key, value):
     """Concatenate a string value at the end of the existing
     record in a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     # assert isinstance(value, str), 'Value is not a string'
     result = tc.hdb_putcat2(self.db, key, value)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #26
0
 def putcat(self, key, value, raw_key=False, raw_value=False):
     """Concatenate an object value at the end of the existing
     record in a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_putcat(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #27
0
 def iterkeys(self):
     """Iterate for every key in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         key = tc.hdb_iternext2(self.db)
         if not key:
             break
         yield key.value
예제 #28
0
 def putcat(self, key, value, raw_key=False, raw_value=False):
     """Concatenate an object value at the end of the existing
     record in a hash database object."""
     (c_key, c_key_len) = util.serialize(key, raw_key)
     (c_value, c_value_len) = util.serialize(value, raw_value)
     result = tc.hdb_putcat(self.db, c_key, c_key_len, c_value, c_value_len)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #29
0
 def putcat(self, key, value):
     """Concatenate a string value at the end of the existing
     record in a hash database object."""
     # assert isinstance(key, str), 'Key is not a string'
     # assert isinstance(value, str), 'Value is not a string'
     result = tc.hdb_putcat2(self.db, key, value)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #30
0
 def iterkeys(self):
     """Iterate for every key in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         key = tc.hdb_iternext2(self.db)
         if not key:
             break
         yield key.value
예제 #31
0
 def itervalues(self):
     """Iterate for every value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         key = tc.hdb_iternext2(self.db)
         if not key:
             break
         value = tc.hdb_get2(self.db, key)
         yield value.value
예제 #32
0
 def itervalues(self):
     """Iterate for every value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         key = tc.hdb_iternext2(self.db)
         if not key:
             break
         value = tc.hdb_get2(self.db, key)
         yield value.value
예제 #33
0
 def optimize(self, bnum=None, apow=None, fpow=None, opts=None):
     """Optimize the file of a hash database object."""
     kwargs = dict([
         x for x in (('bnum', bnum), ('apow', apow), ('fpow', fpow),
                     ('opts', opts)) if x[1]
     ])
     result = tc.hdb_optimize(self.db, **kwargs)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #34
0
 def iterkeys(self, as_type=None):
     """Iterate for every key in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.hdb_iternext(self.db)
         if not c_key:
             break
         key = util.deserialize(c_key, c_key_len, as_type)
         yield key
예제 #35
0
 def iterkeys(self, as_type=None):
     """Iterate for every key in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.hdb_iternext(self.db)
         if not c_key:
             break
         key = util.deserialize(c_key, c_key_len, as_type)
         yield key
예제 #36
0
 def optimize(self, bnum=None, apow=None, fpow=None, opts=None):
     """Optimize the file of a hash database object."""
     kwargs = dict([x for x in (('bnum', bnum),
                                ('apow', apow),
                                ('fpow', fpow),
                                ('opts', opts)) if x[1]])
     result = tc.hdb_optimize(self.db, **kwargs)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #37
0
 def itervalues(self, as_type=None):
     """Iterate for every value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.hdb_iternext(self.db)
         if not c_key:
             break
         (c_value, c_value_len) = tc.hdb_get(self.db, c_key, c_key_len)
         value = util.deserialize(c_value, c_value_len, as_type)
         yield value
예제 #38
0
 def itervalues(self, as_type=None):
     """Iterate for every value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         c_key, c_key_len = tc.hdb_iternext(self.db)
         if not c_key:
             break
         (c_value, c_value_len) = tc.hdb_get(self.db, c_key, c_key_len)
         value = util.deserialize(c_value, c_value_len, as_type)
         yield value
예제 #39
0
 def iteritems(self, key_type=None, value_type=None):
     """Iterate for every key / value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         xstr_key = tc.tcxstrnew()
         xstr_value = tc.tcxstrnew()
         result = tc.hdb_iternext3(self.db, xstr_key, xstr_value)
         if not result:
             break
         key = util.deserialize_xstr(xstr_key, key_type)
         value = util.deserialize_xstr(xstr_value, value_type)
         yield (key, value)
예제 #40
0
 def iteritems(self, key_type=None, value_type=None):
     """Iterate for every key / value in a hash database object."""
     if not tc.hdb_iterinit(self.db):
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     while True:
         xstr_key = tc.tcxstrnew()
         xstr_value = tc.tcxstrnew()
         result = tc.hdb_iternext3(self.db, xstr_key, xstr_value)
         if not result:
             break
         key = util.deserialize_xstr(xstr_key, key_type)
         value = util.deserialize_xstr(xstr_value, value_type)
         yield (key, value)
예제 #41
0
    def foreach(self, proc, op, key_type=None, value_type=None):
        """Process each record atomically of a hash database
        object."""
        def proc_wraper(c_key, c_key_len, c_value, c_value_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, key_type)
            value = util.deserialize(ctypes.cast(c_value, ctypes.c_void_p),
                                     c_value_len, value_type)
            return proc(key, value, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.hdb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
        return result
예제 #42
0
    def foreach(self, proc, op, key_type=None, value_type=None):
        """Process each record atomically of a hash database
        object."""
        def proc_wraper(c_key, c_key_len, c_value, c_value_len, op):
            key = util.deserialize(ctypes.cast(c_key, ctypes.c_void_p),
                                   c_key_len, key_type)
            value = util.deserialize(ctypes.cast(c_value, ctypes.c_void_p),
                                     c_value_len, value_type)
            return proc(key, value, ctypes.cast(op, ctypes.c_char_p).value)

        result = tc.hdb_foreach(self.db, tc.TCITER(proc_wraper), op)
        if not result:
            raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
        return result
예제 #43
0
    def open(self, path, omode=OWRITER|OCREAT, bnum=0, apow=-1, fpow=-1,
             opts=0, rcnum=0, xmsiz=67108864, dfunit=0):
        """Open a database file and connect a hash database object."""
        if bnum or apow >= 0 or fpow >= 0 or opts:
            self.tune(bnum, apow, fpow, opts)
        if rcnum:
            self.setcache(rcnum)
        if xmsiz != 67108864:
            self.setxmsiz(xmsiz)
        if dfunit:
            self.setdfunit(dfunit)

        if not tc.hdb_open(self.db, path, omode):
            raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
예제 #44
0
 def _raise(self, msg=None):
     """Raise an exception based on the internal database object."""
     mode = self.omode()
     if mode == OMDB:
         msg = 'Error in hash memory abstract database object.'
     elif mode == ONDB:
         msg = 'Error in B+ tree memory abstract database object.'
     elif mode == OHDB:
         msg = tc.hdb_errmsg(tc.hdb_ecode(self.reveal()))
     elif mode == OBDB:
         msg = tc.bdb_errmsg(tc.bdb_ecode(self.reveal()))
     elif mode == OFDB:
         msg = tc.fdb_errmsg(tc.fdb_ecode(self.reveal()))
     elif mode == OTDB:
         msg = tc.tdb_errmsg(tc.tdb_ecode(self.reveal()))
     raise tc.TCException(msg)
예제 #45
0
 def _raise(self, msg=None):
     """Raise an exception based on the internal database object."""
     mode = self.omode()
     if mode == OMDB:
         msg = 'Error in hash memory abstract database object.'
     elif mode == ONDB:
         msg = 'Error in B+ tree memory abstract database object.'
     elif mode == OHDB:
         msg = tc.hdb_errmsg(tc.hdb_ecode(self.reveal()))
     elif mode == OBDB:
         msg = tc.bdb_errmsg(tc.bdb_ecode(self.reveal()))
     elif mode == OFDB:
         msg = tc.fdb_errmsg(tc.fdb_ecode(self.reveal()))
     elif mode == OTDB:
         msg = tc.tdb_errmsg(tc.tdb_ecode(self.reveal()))
     raise tc.TCException(msg)
예제 #46
0
    def open(self,
             path,
             omode=OWRITER | OCREAT,
             bnum=0,
             apow=-1,
             fpow=-1,
             opts=0,
             rcnum=0,
             xmsiz=67108864,
             dfunit=0):
        """Open a database file and connect a hash database object."""
        if bnum or apow >= 0 or fpow >= 0 or opts:
            self.tune(bnum, apow, fpow, opts)
        if rcnum:
            self.setcache(rcnum)
        if xmsiz != 67108864:
            self.setxmsiz(xmsiz)
        if dfunit:
            self.setdfunit(dfunit)

        if not tc.hdb_open(self.db, path, omode):
            raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
예제 #47
0
 def fwmkeys(self, prefix, max_=-1):
     """Get forward matching string keys in a hash database object."""
     tclist_objs = tc.hdb_fwmkeys2(self.db, prefix, max_)
     if not tclist_objs:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return util.deserialize_tclist(tclist_objs, str)
예제 #48
0
 def vanish(self):
     """Remove all records of a hash database object."""
     result = tc.hdb_vanish(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #49
0
 def copy(self, path):
     """Copy the database file of a hash database object."""
     result = tc.hdb_copy(self.db, path)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #50
0
 def path(self):
     """Get the file path of a hash database object."""
     result = tc.hdb_path(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #51
0
 def cacheclear(self):
     """Clear the cache of a hash tree database object."""
     result = tc.hdb_cacheclear(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #52
0
 def tranvoid(self):
     """Void the transaction of a hash database object."""
     result = tc.hdb_tranvoid(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #53
0
 def close(self):
     """Close a hash database object."""
     result = tc.hdb_close(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #54
0
 def tranvoid(self):
     """Void the transaction of a hash database object."""
     result = tc.hdb_tranvoid(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #55
0
 def close(self):
     """Close a hash database object."""
     result = tc.hdb_close(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #56
0
 def fwmkeys(self, prefix, max_=-1):
     """Get forward matching string keys in a hash database object."""
     tclist_objs = tc.hdb_fwmkeys2(self.db, prefix, max_)
     if not tclist_objs:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return util.deserialize_tclist(tclist_objs, str)
예제 #57
0
 def cacheclear(self):
     """Clear the cache of a hash tree database object."""
     result = tc.hdb_cacheclear(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #58
0
 def vanish(self):
     """Remove all records of a hash database object."""
     result = tc.hdb_vanish(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #59
0
 def copy(self, path):
     """Copy the database file of a hash database object."""
     result = tc.hdb_copy(self.db, path)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result
예제 #60
0
 def path(self):
     """Get the file path of a hash database object."""
     result = tc.hdb_path(self.db)
     if not result:
         raise tc.TCException(tc.hdb_errmsg(tc.hdb_ecode(self.db)))
     return result