Skip to content

Commit

Permalink
Reduce the boilerplate needed to add new tree types.
Browse files Browse the repository at this point in the history
Generate the Python modules and test modules based off a description
of the datatype.

Several tests that were previously only used for a specific classes
are now generalized and added to most trees, such as testing
non-compliant keys and testing overflow for bounded values.

Also always raise ``OverflowError`` for integer keys/values out of range.
  • Loading branch information
jamadden committed Feb 27, 2020
1 parent d1e1f87 commit 0314b24
Show file tree
Hide file tree
Showing 60 changed files with 1,282 additions and 9,711 deletions.
34 changes: 31 additions & 3 deletions BTrees/BucketTemplate.c
Expand Up @@ -57,7 +57,9 @@
** self The bucket
** keyarg The key to look for
** has_key Boolean; if true, return a true/false result; else return
** the value associated with the key.
** the value associated with the key. When true, ignore the TypeError from
** a key conversion issue, instead
** transforming it into a KeyError.
**
** Return
** If has_key:
Expand All @@ -81,7 +83,15 @@ _bucket_get(Bucket *self, PyObject *keyarg, int has_key)
int copied = 1;

COPY_KEY_FROM_ARG(key, keyarg, copied);
UNLESS (copied) return NULL;
UNLESS (copied)
{
if (has_key && PyErr_ExceptionMatches(PyExc_TypeError))
{
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, keyarg);
}
return NULL;
}

UNLESS (PER_USE(self)) return NULL;

Expand All @@ -106,7 +116,17 @@ _bucket_get(Bucket *self, PyObject *keyarg, int has_key)
static PyObject *
bucket_getitem(Bucket *self, PyObject *key)
{
return _bucket_get(self, key, 0);
PyObject* result;

result = _bucket_get(self, key, 0);

if (result == NULL && PyErr_ExceptionMatches(PyExc_TypeError))
{
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, key);
}

return result;
}

/*
Expand Down Expand Up @@ -1448,6 +1468,10 @@ bucket_contains(Bucket *self, PyObject *key)
result = INT_AS_LONG(asobj) ? 1 : 0;
Py_DECREF(asobj);
}
else if (PyErr_ExceptionMatches(PyExc_KeyError)) {
PyErr_Clear();
result = 0;
}
return result;
}

Expand All @@ -1465,6 +1489,10 @@ bucket_getm(Bucket *self, PyObject *args)
r = _bucket_get(self, key, 0);
if (r)
return r;
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
PyErr_SetObject(PyExc_KeyError, key);
}
if (!PyErr_ExceptionMatches(PyExc_KeyError))
return NULL;
PyErr_Clear();
Expand Down
112 changes: 0 additions & 112 deletions BTrees/IFBTree.py

This file was deleted.

113 changes: 0 additions & 113 deletions BTrees/IIBTree.py

This file was deleted.

95 changes: 0 additions & 95 deletions BTrees/IOBTree.py

This file was deleted.

0 comments on commit 0314b24

Please sign in to comment.