Changeset 4919 for lang/python

Show
Ignore:
Timestamp:
01/19/08 05:07:46 (5 years ago)
Author:
yappo
Message:

revert revision 4905, 4906, 4907, 4908, 4909

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  
     12007-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 
    172007-12-15  Tasuku SUENAGA <gunyarakun@sourceforge.net> 
    28 
  • lang/python/pytc/tags/RELEASE-0.3/pytc.c

    r4908 r4919  
    11/* Copyright(C) 2007- Tasuku SUENAGA 
    22 
    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 
     3THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     4"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     5LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
     6A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
     7CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
     8EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
     9PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
     10PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
     11LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
     12NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
     13SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    1614*/ 
    1715#include <Python.h> 
     
    238236  \ 
    239237    if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#s#:" #method, kwlist, \ 
    240                                      &key, &key_len, &value, &value_len)) { \ 
     238                                     &key, &key_len, \ 
     239                                     &value, &value_len)) { \ 
    241240      return NULL; \ 
    242241    } \ 
     
    325324      return NULL; \ 
    326325    } \ 
    327     key = PyString_AS_STRING(_key); \ 
     326    key = PyString_AsString(_key); \ 
    328327    key_len = PyString_GET_SIZE(_key); \ 
    329328    if (!key || !key_len) { \ 
     
    347346  func(type *self, PyObject *_key) { \ 
    348347    bool result; \ 
    349     char *key = PyString_AS_STRING(_key); \ 
     348    char *key = PyString_AsString(_key); \ 
    350349    int key_len = PyString_GET_SIZE(_key); \ 
    351350  \ 
     
    368367  func(type *self, PyObject *_key, PyObject *_value) { \ 
    369368    bool result; \ 
    370     char *key = PyString_AS_STRING(_key), *value = PyString_AS_STRING(_value); \ 
     369    char *key = PyString_AsString(_key), *value = PyString_AsString(_value); \ 
    371370    int key_len = PyString_GET_SIZE(_key), value_len = PyString_GET_SIZE(_value); \ 
    372371  \ 
     
    399398  static int \ 
    400399  func(type *self, PyObject *_key) { \ 
    401     char *key = PyString_AS_STRING(_key); \ 
     400    char *key = PyString_AsString(_key); \ 
    402401    int key_len = PyString_GET_SIZE(_key), value_len; \ 
    403402  \ 
     
    422421  func(type *self, PyObject *_key) { \ 
    423422    PyObject *ret; \ 
    424     char *key = PyString_AS_STRING(_key), *value; \ 
     423    char *key = PyString_AsString(_key), *value; \ 
    425424    int key_len = PyString_GET_SIZE(_key), value_len; \ 
    426425  \ 
     
    476475  if (value) { tcxstrdel(value); } \ 
    477476  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  } 
    478498 
    479499/*** TCHDB ***/ 
     
    14001420  Py_END_ALLOW_THREADS 
    14011421 
    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() 
    14211423} 
    14221424 
     
    14331435PY_U_LONG_LONG_NOARGS(PyTCBDB_rnum, PyTCBDB, tcbdbrnum, bdb, tcbdbecode, raise_tcbdb_error) 
    14341436PY_U_LONG_LONG_NOARGS(PyTCBDB_fsiz, PyTCBDB, tcbdbrnum, bdb, tcbdbecode, raise_tcbdb_error) 
     1437 
     1438static PyObject * 
     1439PyTCBDB_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 
     1458static PyObject * 
     1459PyTCBDB_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} 
    14351475 
    14361476/* TODO: features for experts */ 
     
    17261766   METH_NOARGS, 
    17271767   "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   ""}, 
    17281774  {"__contains__", (PyCFunction)PyTCBDB___contains__, 
    17291775   METH_O | METH_COEXIST, 
  • lang/python/pytc/tags/RELEASE-0.3/setup.py

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

    r4908 r4919  
    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 
    176193    # vanish 
    177194    db.vanish()