Changeset 4908 for lang/python

Show
Ignore:
Timestamp:
01/19/08 01:28:48 (5 years ago)
Author:
hakobe
Message:
 
Location:
lang/python/pytc/tags/RELEASE-0.3
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lang/python/pytc/tags/RELEASE-0.3/ChangeLog

    r3823 r4908  
    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  
    712007-12-15  Tasuku SUENAGA <gunyarakun@sourceforge.net> 
    82 
  • lang/python/pytc/tags/RELEASE-0.3/pytc.c

    r3823 r4908  
    11/* Copyright(C) 2007- Tasuku SUENAGA 
    22 
    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. 
     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 
    1416*/ 
    1517#include <Python.h> 
     
    236238  \ 
    237239    if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#s#:" #method, kwlist, \ 
    238                                      &key, &key_len, \ 
    239                                      &value, &value_len)) { \ 
     240                                     &key, &key_len, &value, &value_len)) { \ 
    240241      return NULL; \ 
    241242    } \ 
     
    324325      return NULL; \ 
    325326    } \ 
    326     key = PyString_AsString(_key); \ 
     327    key = PyString_AS_STRING(_key); \ 
    327328    key_len = PyString_GET_SIZE(_key); \ 
    328329    if (!key || !key_len) { \ 
     
    346347  func(type *self, PyObject *_key) { \ 
    347348    bool result; \ 
    348     char *key = PyString_AsString(_key); \ 
     349    char *key = PyString_AS_STRING(_key); \ 
    349350    int key_len = PyString_GET_SIZE(_key); \ 
    350351  \ 
     
    367368  func(type *self, PyObject *_key, PyObject *_value) { \ 
    368369    bool result; \ 
    369     char *key = PyString_AsString(_key), *value = PyString_AsString(_value); \ 
     370    char *key = PyString_AS_STRING(_key), *value = PyString_AS_STRING(_value); \ 
    370371    int key_len = PyString_GET_SIZE(_key), value_len = PyString_GET_SIZE(_value); \ 
    371372  \ 
     
    398399  static int \ 
    399400  func(type *self, PyObject *_key) { \ 
    400     char *key = PyString_AsString(_key); \ 
     401    char *key = PyString_AS_STRING(_key); \ 
    401402    int key_len = PyString_GET_SIZE(_key), value_len; \ 
    402403  \ 
     
    421422  func(type *self, PyObject *_key) { \ 
    422423    PyObject *ret; \ 
    423     char *key = PyString_AsString(_key), *value; \ 
     424    char *key = PyString_AS_STRING(_key), *value; \ 
    424425    int key_len = PyString_GET_SIZE(_key), value_len; \ 
    425426  \ 
     
    475476  if (value) { tcxstrdel(value); } \ 
    476477  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   } 
    498478 
    499479/*** TCHDB ***/ 
     
    14201400  Py_END_ALLOW_THREADS 
    14211401 
    1422   TCLIST2PyList() 
     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  } 
    14231421} 
    14241422 
     
    14351433PY_U_LONG_LONG_NOARGS(PyTCBDB_rnum, PyTCBDB, tcbdbrnum, bdb, tcbdbecode, raise_tcbdb_error) 
    14361434PY_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 } 
    14751435 
    14761436/* TODO: features for experts */ 
     
    17661726   METH_NOARGS, 
    17671727   "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    ""}, 
    17741728  {"__contains__", (PyCFunction)PyTCBDB___contains__, 
    17751729   METH_O | METH_COEXIST, 
  • lang/python/pytc/tags/RELEASE-0.3/setup.py

    r3823 r4908  
    2525 
    2626setup(name = 'pytc', 
    27       version = '0.3', 
     27      version = '0.2', 
    2828      description = 'Tokyo Cabinet Python bindings', 
    2929      long_description = ''' 
  • lang/python/pytc/tags/RELEASE-0.3/tests/testBDB.py

    r3822 r4908  
    174174    self.assertEqual(db.get('moru'), 'pupupu') 
    175175 
    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  
    193176    # vanish 
    194177    db.vanish()