Changeset 4919 for lang/python
- Timestamp:
- 01/19/08 05:07:46 (5 years ago)
- Location:
- lang/python/pytc/tags/RELEASE-0.3
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/python/pytc/tags/RELEASE-0.3/ChangeLog
r4908 r4919 1 2007-12-30 Tasuku SUENAGA <gunyarakun@sourceforge.net> 2 3 * version 0.3 4 * modified setup.py for darwin 5 * added TCBDB.range and TCBDB.rangefwm 6 1 7 2007-12-15 Tasuku SUENAGA <gunyarakun@sourceforge.net> 2 8 -
lang/python/pytc/tags/RELEASE-0.3/pytc.c
r4908 r4919 1 1 /* Copyright(C) 2007- Tasuku SUENAGA 2 2 3 This library is free software; you can redistribute it and/or 4 modify it under the terms of the GNU Lesser General Public 5 License as published by the Free Software Foundation; either 6 version 2.1 of the License, or (at your option) any later version. 7 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Lesser General Public License for more details. 12 13 You should have received a copy of the GNU Lesser General Public 14 License along with this library; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 3 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 4 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 5 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 6 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 7 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 8 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 9 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 10 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 11 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 12 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 13 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 14 */ 17 15 #include <Python.h> … … 238 236 \ 239 237 if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#s#:" #method, kwlist, \ 240 &key, &key_len, &value, &value_len)) { \ 238 &key, &key_len, \ 239 &value, &value_len)) { \ 241 240 return NULL; \ 242 241 } \ … … 325 324 return NULL; \ 326 325 } \ 327 key = PyString_A S_STRING(_key); \326 key = PyString_AsString(_key); \ 328 327 key_len = PyString_GET_SIZE(_key); \ 329 328 if (!key || !key_len) { \ … … 347 346 func(type *self, PyObject *_key) { \ 348 347 bool result; \ 349 char *key = PyString_A S_STRING(_key); \348 char *key = PyString_AsString(_key); \ 350 349 int key_len = PyString_GET_SIZE(_key); \ 351 350 \ … … 368 367 func(type *self, PyObject *_key, PyObject *_value) { \ 369 368 bool result; \ 370 char *key = PyString_A S_STRING(_key), *value = PyString_AS_STRING(_value); \369 char *key = PyString_AsString(_key), *value = PyString_AsString(_value); \ 371 370 int key_len = PyString_GET_SIZE(_key), value_len = PyString_GET_SIZE(_value); \ 372 371 \ … … 399 398 static int \ 400 399 func(type *self, PyObject *_key) { \ 401 char *key = PyString_A S_STRING(_key); \400 char *key = PyString_AsString(_key); \ 402 401 int key_len = PyString_GET_SIZE(_key), value_len; \ 403 402 \ … … 422 421 func(type *self, PyObject *_key) { \ 423 422 PyObject *ret; \ 424 char *key = PyString_A S_STRING(_key), *value; \423 char *key = PyString_AsString(_key), *value; \ 425 424 int key_len = PyString_GET_SIZE(_key), value_len; \ 426 425 \ … … 476 475 if (value) { tcxstrdel(value); } \ 477 476 return ret; 477 478 #define TCLIST2PyList() \ 479 if (!list) { \ 480 raise_tcbdb_error(self->bdb); \ 481 return NULL; \ 482 } else { \ 483 PyObject *ret; \ 484 int i, n = tclistnum(list); \ 485 if ((ret = PyList_New(n))) { \ 486 for (i = 0; i < n; i++) { \ 487 int value_len; \ 488 PyObject *_value; \ 489 const char *value; \ 490 value = tclistval(list, i, &value_len); \ 491 _value = PyString_FromStringAndSize(value, value_len); \ 492 PyList_SET_ITEM(ret, i, _value); \ 493 } \ 494 } \ 495 tclistdel(list); \ 496 return ret; \ 497 } 478 498 479 499 /*** TCHDB ***/ … … 1400 1420 Py_END_ALLOW_THREADS 1401 1421 1402 if (!list) { 1403 raise_tcbdb_error(self->bdb); 1404 return NULL; 1405 } else { 1406 PyObject *ret; 1407 int i, n = tclistnum(list); 1408 if ((ret = PyList_New(n))) { 1409 for (i = 0; i < n; i++) { 1410 int value_len; 1411 PyObject *_value; 1412 const char *value; 1413 value = tclistval(list, i, &value_len); 1414 _value = PyString_FromStringAndSize(value, value_len); 1415 PyList_SET_ITEM(ret, i, _value); 1416 } 1417 } 1418 tclistdel(list); 1419 return ret; 1420 } 1422 TCLIST2PyList() 1421 1423 } 1422 1424 … … 1433 1435 PY_U_LONG_LONG_NOARGS(PyTCBDB_rnum, PyTCBDB, tcbdbrnum, bdb, tcbdbecode, raise_tcbdb_error) 1434 1436 PY_U_LONG_LONG_NOARGS(PyTCBDB_fsiz, PyTCBDB, tcbdbrnum, bdb, tcbdbecode, raise_tcbdb_error) 1437 1438 static PyObject * 1439 PyTCBDB_range(PyTCBDB *self, PyObject *args, PyObject *keywds) { 1440 TCLIST *list; 1441 char *bkey, *ekey; 1442 int bkey_len, binc, ekey_len, einc, max; 1443 static char *kwlist[] = {"bkey", "binc", "ekey", "einc", "max", NULL}; 1444 1445 if (!PyArg_ParseTupleAndKeywords(args, keywds, "z#iz#ii:range", kwlist, 1446 &bkey, &bkey_len, &binc, 1447 &ekey, &ekey_len, &einc, &max)) { 1448 return NULL; 1449 } 1450 Py_BEGIN_ALLOW_THREADS 1451 list = tcbdbrange(self->bdb, bkey, bkey_len, binc, 1452 ekey, ekey_len, einc, max); 1453 Py_END_ALLOW_THREADS 1454 1455 TCLIST2PyList() 1456 } 1457 1458 static PyObject * 1459 PyTCBDB_rangefwm(PyTCBDB *self, PyObject *args, PyObject *keywds) { 1460 int max; 1461 TCLIST *list; 1462 char *prefix; 1463 static char *kwlist[] = {"prefix", "max", NULL}; 1464 1465 if (!PyArg_ParseTupleAndKeywords(args, keywds, "si:rangefwm", kwlist, 1466 &prefix, &max)) { 1467 return NULL; 1468 } 1469 Py_BEGIN_ALLOW_THREADS 1470 list = tcbdbrange3(self->bdb, prefix, max); 1471 Py_END_ALLOW_THREADS 1472 1473 TCLIST2PyList() 1474 } 1435 1475 1436 1476 /* TODO: features for experts */ … … 1726 1766 METH_NOARGS, 1727 1767 "Create a cursor object."}, 1768 {"range", (PyCFunction)PyTCBDB_range, 1769 METH_VARARGS | METH_KEYWORDS, 1770 ""}, 1771 {"rangefwm", (PyCFunction)PyTCBDB_rangefwm, 1772 METH_VARARGS | METH_KEYWORDS, 1773 ""}, 1728 1774 {"__contains__", (PyCFunction)PyTCBDB___contains__, 1729 1775 METH_O | METH_COEXIST, -
lang/python/pytc/tags/RELEASE-0.3/setup.py
r4908 r4919 25 25 26 26 setup(name = 'pytc', 27 version = '0. 2',27 version = '0.3', 28 28 description = 'Tokyo Cabinet Python bindings', 29 29 long_description = ''' -
lang/python/pytc/tags/RELEASE-0.3/tests/testBDB.py
r4908 r4919 174 174 self.assertEqual(db.get('moru'), 'pupupu') 175 175 176 db['nagasaki'] = 'ichiban' 177 db['nagasaki-higashi'] = 'toh' 178 db['nagasaki-nishi'] = 'zai' 179 db['nagasaki-minami'] = 'nan' 180 db['nagasaki-kita'] = 'boku' 181 db['nagasaki-hokuyodai'] = 'hokuyodai' 182 # range 183 self.assertEqual(db.range('nagasaki', False, 'nagasaki-kita', True, 3), 184 ['nagasaki-higashi', 185 'nagasaki-hokuyodai', 186 'nagasaki-kita']) 187 # rangefwm 188 self.assertEqual(db.rangefwm('nagasaki', 5), 189 ['nagasaki', 'nagasaki-higashi', 190 'nagasaki-hokuyodai', 'nagasaki-kita', 191 'nagasaki-minami']) 192 176 193 # vanish 177 194 db.vanish()
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)