Changeset 3161
- Timestamp:
- 12/15/07 16:50:52 (5 years ago)
- Location:
- lang/python/pytc/trunk
- Files:
-
- 2 modified
-
pytc.c (modified) (4 diffs)
-
tests/testBDB.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/python/pytc/trunk/pytc.c
r3160 r3161 934 934 0, /* tp_richcompare */ 935 935 0, /* tp_weaklistoffset */ 936 PyTCHDB_GetIter_keys,/* tp_iter */936 (getiterfunc)PyTCHDB_GetIter_keys, /* tp_iter */ 937 937 (iternextfunc)PyTCHDB_iternext, /* tp_iternext */ 938 938 PyTCHDB_methods, /* tp_methods */ … … 1041 1041 static PyObject * 1042 1042 PyBDBCUR_iternext(PyBDBCUR *self) { 1043 char *key; 1044 int key_len; 1045 PyObject *ret; 1046 1043 /* TODO: performance up */ 1044 GET_TCXSTR_KEY_VALUE(tcbdbcurrec,self->cur) 1045 if (result) { 1046 switch (self->itype) { 1047 case iter_key: 1048 ret = PyString_FromStringAndSize(tcxstrptr(key), tcxstrsize(key)); 1049 break; 1050 case iter_value: 1051 ret = PyString_FromStringAndSize(tcxstrptr(value), tcxstrsize(value)); 1052 break; 1053 case iter_item: 1054 ret = Py_BuildValue("(s#s#)", tcxstrptr(key), tcxstrsize(key), 1055 tcxstrptr(value), tcxstrsize(value)); 1056 break; 1057 } 1058 } 1047 1059 Py_BEGIN_ALLOW_THREADS 1048 key = tcbdbcurkey(self->cur, &key_len);1060 result = tcbdbcurnext(self->cur); 1049 1061 Py_END_ALLOW_THREADS 1050 1051 if (key) { 1052 ret = PyString_FromStringAndSize(key, key_len); 1053 free(key); 1054 Py_BEGIN_ALLOW_THREADS 1055 tcbdbcurnext(self->cur); 1056 Py_END_ALLOW_THREADS 1057 return ret; 1058 } 1059 return NULL; 1062 CLEAR_TCXSTR_KEY_VALUE() 1060 1063 } 1061 1064 … … 1741 1744 METH_NOARGS, 1742 1745 ""}, 1746 {"iteritems", (PyCFunction)PyTCBDB_GetIter_items, 1747 METH_NOARGS, 1748 ""}, 1749 {"iterkeys", (PyCFunction)PyTCBDB_GetIter_keys, 1750 METH_NOARGS, 1751 ""}, 1752 {"itervalues", (PyCFunction)PyTCBDB_GetIter_values, 1753 METH_NOARGS, 1754 ""}, 1743 1755 /* 1744 1756 {"", (PyCFunction)PyTCBDB_, … … 1798 1810 0, /* tp_richcompare */ 1799 1811 0, /* tp_weaklistoffset */ 1800 PyTCBDB_GetIter_keys,/* tp_iter */1812 (getiterfunc)PyTCBDB_GetIter_keys, /* tp_iter */ 1801 1813 0, /* tp_iternext */ 1802 1814 PyTCBDB_methods, /* tp_methods */ -
lang/python/pytc/trunk/tests/testBDB.py
r3102 r3161 100 100 ('moru', 'pui'), ('moruta', 'puipui')]) 101 101 102 result = [] 103 for key in db.iterkeys(): 104 result.append(key) 105 self.assertEqual(sorted(result), ['hamu', 'kiki', 'kiki', 'moru', 'moruta']) 106 107 result = [] 108 for value in db.itervalues(): 109 result.append(value) 110 self.assertEqual(sorted(result), 111 ['ju', 'nya-nya-nya-', 'pui', 'puipui', 'unya-n']) 112 113 result = [] 114 for (key, value) in db.iteritems(): 115 result.append((key, value)) 116 self.assertEqual(sorted(result),[ 117 ('hamu', 'ju'), ('kiki', 'nya-nya-nya-'), ('kiki', 'unya-n'), 118 ('moru', 'pui'), ('moruta', 'puipui')]) 119 102 120 # this bug is reported by id:a2c 103 121 self.assertRaises(TypeError, eval, 'db[:]', globals(), locals())
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)