pybsddb with cffi

Check-in [d2e59555d5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:passed test_dbshelve
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d2e59555d5f3432bf2b329dd3976b9aec2908514
User & Date: broker-3 2013-02-07 13:42:02
Context
2013-02-07
13:56
passed test_compare check-in: bb079ca309 user: broker-3 tags: trunk
13:42
passed test_dbshelve check-in: d2e59555d5 user: broker-3 tags: trunk
13:40
minor PyPy specific fix as cPickle=pickle check-in: 2fd97e0796 user: broker-3 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bsddb3/db.py.

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680


681
682
683
684
685
686
687
...
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719

    has_key = exists  # not 100% copy of pybsddb
    __contains__ = has_key

    def __setitem__(self, key, value):  # DB_ass_sub
        if not self.db:
            raise DBError(0, "DB object has been closed")
        key, flags = _make_key_dbt(self, key)
        if value is None:  # delete value
            raise Exception("Not yet (DB.__setitem__)")
        else:
            data = _make_dbt(value)
            id_dup = self._setflags & (DB_DUP | DB_DUPSORT)
            if id_dup:
                # dictionaries shouldn't have duplicate keys
                flags = DB_NOOVERWRITE
            ret = self.db.put(self.db, ffi.NULL, key, data, flags)  # must call self._put instead. debugging right now
            if id_dup and ret == DB_KEYEXIST:
                getattr(self.db, 'del')(self.db, ffi.NULL, key, 0)
                self.db.put(self.db, ffi.NULL, key, data, flags)



    def __delitem__(self, key):
        self.delete(key)

    type = get_type

    def _make_list(self, txn, what):
................................................................................
        cursor = cursor[0]
        key = ffi.new("DBT *")
        data = ffi.new("DBT *")
        if what == 'keys':
            def func():
                if dbtype == DB_BTREE or dbtype == DB_HASH:
                    return ffi.buffer(key.data, key.size)[:]
                return int(ffi.cast("db_recno_t *", key.data)[0])
        elif what == 'values':
            def func():
                if dbtype == DB_BTREE or dbtype == DB_HASH:
                    return ffi.buffer(data.data, data.size)[:]
                return int(ffi.cast("db_recno_t *", key.data)[0])
        elif what == 'items':
            def func():
                ret = ffi.buffer(data.data, data.size)[:]
                if dbtype == DB_BTREE or dbtype == DB_HASH:
                    return ffi.buffer(key.data, key.size)[:], ret
                return int(ffi.cast("db_recno_t *", key.data)[0]), ret
        while True:
            err = cursor.get(cursor, key, data, DB_NEXT)
            if err:
                cursor.close(cursor)
                break
            yield func()








|





<
|
|
|
|

|
>
>







 







|


<
|
<





|







661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
...
695
696
697
698
699
700
701
702
703
704

705

706
707
708
709
710
711
712
713
714
715
716
717
718

    has_key = exists  # not 100% copy of pybsddb
    __contains__ = has_key

    def __setitem__(self, key, value):  # DB_ass_sub
        if not self.db:
            raise DBError(0, "DB object has been closed")
        key, _ = _make_key_dbt(self, key, None)
        if value is None:  # delete value
            raise Exception("Not yet (DB.__setitem__)")
        else:
            data = _make_dbt(value)
            id_dup = self._setflags & (DB_DUP | DB_DUPSORT)

            # dictionaries shouldn't have duplicate keys
            flags = DB_NOOVERWRITE if id_dup else 0
            err = self.db.put(self.db, ffi.NULL, key, data, flags)  # must call self._put instead. debugging right now
            if id_dup and err == DB_KEYEXIST:
                getattr(self.db, 'del')(self.db, ffi.NULL, key, 0)
                check_error(self.db.put(self.db, ffi.NULL, key, data, flags))
            else:
                check_error(err)

    def __delitem__(self, key):
        self.delete(key)

    type = get_type

    def _make_list(self, txn, what):
................................................................................
        cursor = cursor[0]
        key = ffi.new("DBT *")
        data = ffi.new("DBT *")
        if what == 'keys':
            def func():
                if dbtype == DB_BTREE or dbtype == DB_HASH:
                    return ffi.buffer(key.data, key.size)[:]
                return ffi.cast("int *", key.data)[0]  # db_recno_t
        elif what == 'values':
            def func():

                return ffi.buffer(data.data, data.size)[:]

        elif what == 'items':
            def func():
                ret = ffi.buffer(data.data, data.size)[:]
                if dbtype == DB_BTREE or dbtype == DB_HASH:
                    return ffi.buffer(key.data, key.size)[:], ret
                return ffi.cast("int *", key.data)[0], ret  # db_recno_t
        while True:
            err = cursor.get(cursor, key, data, DB_NEXT)
            if err:
                cursor.close(cursor)
                break
            yield func()