summaryrefslogtreecommitdiff
path: root/python/rpmmi-py.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-30 16:45:46 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-30 16:45:46 +0300
commit909982b1b5d2bccbf28ecfb38064ab86e09d4523 (patch)
tree7a8c2bf5841d1fff1de576a13a9ae7111c0c785e /python/rpmmi-py.c
parent8cb920eb32f36297e2154b7ebcc25851d9a7b39d (diff)
downloadlibrpm-tizen-909982b1b5d2bccbf28ecfb38064ab86e09d4523.tar.gz
librpm-tizen-909982b1b5d2bccbf28ecfb38064ab86e09d4523.tar.bz2
librpm-tizen-909982b1b5d2bccbf28ecfb38064ab86e09d4523.zip
Deprecate custom foo.count() methods, support len() instead
Diffstat (limited to 'python/rpmmi-py.c')
-rw-r--r--python/rpmmi-py.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/python/rpmmi-py.c b/python/rpmmi-py.c
index 70584fff4..8a5aa6b7c 100644
--- a/python/rpmmi-py.c
+++ b/python/rpmmi-py.c
@@ -93,12 +93,8 @@ rpmmi_Instance(rpmmiObject * s)
static PyObject *
rpmmi_Count(rpmmiObject * s)
{
- int rc = 0;
-
- if (s->mi != NULL)
- rc = rpmdbGetIteratorCount(s->mi);
-
- return Py_BuildValue("i", rc);
+ DEPRECATED_METHOD;
+ return Py_BuildValue("i", PyDict_Size((PyObject *)s));
}
static PyObject *
@@ -136,6 +132,16 @@ static void rpmmi_dealloc(rpmmiObject * s)
s->ob_type->tp_free((PyObject *)s);
}
+static Py_ssize_t rpmmi_length(rpmmiObject * s)
+{
+ return s->mi ? rpmdbGetIteratorCount(s->mi) : 0;
+}
+
+PyMappingMethods rpmmi_as_mapping = {
+ (lenfunc) rpmmi_length, /* mp_length */
+ 0,
+};
+
static char rpmmi_doc[] =
"";
@@ -153,7 +159,7 @@ PyTypeObject rpmmi_Type = {
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
+ &rpmmi_as_mapping, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */