pybsddb with cffi

Check-in [e1116161a5]
Login

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

Overview
Comment:AV fixed
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e1116161a55dfd26827804f9d02f26f7e96953e0
User & Date: broker-3 2013-02-06 17:30:11
Context
2013-02-06
17:38
pass test_join check-in: 47e4a41be9 user: broker-3 tags: trunk
17:30
AV fixed check-in: e1116161a5 user: broker-3 tags: trunk
14:07
use ffi.buffer instad of memcpy check-in: 75f4ad7d3c user: broker-3 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bsddb3/db.py.

1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
....
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
....
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770

1771
1772
1773
1774
1775
1776
1777
        db.children_cursors.add(ref(self))

    @staticmethod
    def _check_dbc(dbc):
        if dbc is None:
            raise DBCursorClosedError(0, "DBCursor object has been closed")

    def _get(self, flags, dlen, doff):
        self._check_dbc(self.dbc)
        key = ffi.new("DBT *")
        data = ffi.new("DBT *")
        _add_partial_dbt(data, dlen, doff)
        err = self.dbc.get(self.dbc, key, data, flags)
        db = self.mydb
        if (err == DB_NOTFOUND or err == DB_KEYEMPTY) and db._getReturnsNone:
................................................................................
    def put(self, key, data, flags=0, dlen= -1, doff= -1):
        self._check_dbc(self.dbc)
        key, _ = _make_key_dbt(self.mydb, key)
        data = _make_dbt(data)
        _add_partial_dbt(data, dlen, doff)
        check_error(self.dbc.put(self.dbc, key, data, flags))

    def get(self, *args, **kwargs):
        # hell is here
        l = len(args)
        key = kwargs.get('key', None)
        data = kwargs.get('data', None)
        flags = kwargs.get('flags', 0)
        dlen = kwargs.get('dlen', -1)
        doff = kwargs.get('doff', -1)
................................................................................
            else:
                raise TypeError()

        # key, data=None, flags=0, dlen= -1, doff= -1
        self._check_dbc(self.dbc)
        db = self.mydb
        key, _ = _make_key_dbt(db, key, None)
        if data is None:
            data = ffi.NULL
        else:
            data = _make_dbt(data)
            _add_partial_dbt(data, dlen, doff)
        err = self.dbc.get(self.dbc, key, data, flags)
        if (err == DB_NOTFOUND or err == DB_KEYEMPTY) and db._getReturnsNone:
            return
        check_error(err)

        if dbtype == -1:
            raise Exception("wrong type")
        if dbtype == DB_RECNO or dbtype == DB_QUEUE:
            raise Exception("not yet")
        return (ffi.buffer(key.data, key.size)[:],
                ffi.buffer(data.data, data.size)[:])








|







 







|







 







<
<
<
|
|




>







1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
....
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
....
1755
1756
1757
1758
1759
1760
1761



1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
        db.children_cursors.add(ref(self))

    @staticmethod
    def _check_dbc(dbc):
        if dbc is None:
            raise DBCursorClosedError(0, "DBCursor object has been closed")

    def _get(self, flags, dlen, doff):  # _DBCursor_get
        self._check_dbc(self.dbc)
        key = ffi.new("DBT *")
        data = ffi.new("DBT *")
        _add_partial_dbt(data, dlen, doff)
        err = self.dbc.get(self.dbc, key, data, flags)
        db = self.mydb
        if (err == DB_NOTFOUND or err == DB_KEYEMPTY) and db._getReturnsNone:
................................................................................
    def put(self, key, data, flags=0, dlen= -1, doff= -1):
        self._check_dbc(self.dbc)
        key, _ = _make_key_dbt(self.mydb, key)
        data = _make_dbt(data)
        _add_partial_dbt(data, dlen, doff)
        check_error(self.dbc.put(self.dbc, key, data, flags))

    def get(self, *args, **kwargs):  # DBC_get
        # hell is here
        l = len(args)
        key = kwargs.get('key', None)
        data = kwargs.get('data', None)
        flags = kwargs.get('flags', 0)
        dlen = kwargs.get('dlen', -1)
        doff = kwargs.get('doff', -1)
................................................................................
            else:
                raise TypeError()

        # key, data=None, flags=0, dlen= -1, doff= -1
        self._check_dbc(self.dbc)
        db = self.mydb
        key, _ = _make_key_dbt(db, key, None)



        data = _make_dbt(data)
        _add_partial_dbt(data, dlen, doff)
        err = self.dbc.get(self.dbc, key, data, flags)
        if (err == DB_NOTFOUND or err == DB_KEYEMPTY) and db._getReturnsNone:
            return
        check_error(err)
        dbtype = db.get_type()
        if dbtype == -1:
            raise Exception("wrong type")
        if dbtype == DB_RECNO or dbtype == DB_QUEUE:
            raise Exception("not yet")
        return (ffi.buffer(key.data, key.size)[:],
                ffi.buffer(data.data, data.size)[:])