Ticket #346: sabrina-python3-update.patch

File sabrina-python3-update.patch, 13.3 KB (added by sabrina, 13 years ago)

This patch makes smoketest3.py work. It also make sortable_serialise and sortable_unserialise functions work well

  • xapian-bindings/python/smoketest3.py

     
    237237    # Check QueryParser pure NOT option
    238238    qp = xapian.QueryParser()
    239239    expect_query(qp.parse_query("NOT test", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
    240                  "(<alldocuments> AND_NOT test:(pos=1))")
     240                 "(<alldocuments> AND_NOT test@1)")
    241241
    242242    # Check QueryParser partial option
    243243    qp = xapian.QueryParser()
     
    246246    qp.set_stemming_strategy(qp.STEM_SOME)
    247247    qp.set_stemmer(xapian.Stem('en'))
    248248    expect_query(qp.parse_query("foo o", qp.FLAG_PARTIAL),
    249                  "(Zfoo:(pos=1) AND ((out:(pos=2) SYNONYM outsid:(pos=2)) OR Zo:(pos=2)))")
     249                  "(Zfoo@1 AND ((out@2 SYNONYM outsid@2) OR Zo@2))")
    250250
    251251    expect_query(qp.parse_query("foo outside", qp.FLAG_PARTIAL),
    252                  "(Zfoo:(pos=1) AND Zoutsid:(pos=2))")
     252                 "(Zfoo@1 AND Zoutsid@2)")
    253253
    254254    # Test supplying unicode strings
    255255    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')),
    256256                 '(foo OR bar)')
    257257    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xa3')),
    258                  '(foo OR bar\xc2\xa3)')
    259     expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xc2\xa3')),
    260                  '(foo OR bar\xc2\xa3)')
     258                 '(foo OR bar\u00a3)')
     259    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\u00a3')),
     260                 '(foo OR bar\u00a3)')
    261261    expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'),
    262262                 '(foo OR bar)')
    263263
    264264    expect_query(qp.parse_query("NOT t\xe9st", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
    265                  "(<alldocuments> AND_NOT Zt\xc3\xa9st:(pos=1))")
     265                 "(<alldocuments> AND_NOT Zt\u00e9st@1)")
    266266
    267267    doc = xapian.Document()
    268268    doc.set_data("Unicode with an acc\xe9nt")
    269269    doc.add_posting(stem("out\xe9r"), 1)
    270     expect(doc.get_data(), "Unicode with an acc\xe9nt".encode('utf-8'))
    271     term = doc.termlist().next().term
    272     expect(term, "out\xe9r".encode('utf-8'))
     270    expect(doc.get_data(), "Unicode with an acc\u00e9nt")
     271    term = next(doc.termlist()).term
     272    expect(term, "out\u00e9r")
    273273
    274274    # Check simple stopper
    275275    stop = xapian.SimpleStopper()
    276276    qp.set_stopper(stop)
    277277    expect(stop('a'), False)
    278278    expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
    279                  "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
     279                 "(Zfoo@1 AND Zbar@2 AND Za@3)")
    280280
    281281    stop.add('a')
    282282    expect(stop('a'), True)
    283283    expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
    284                  "(Zfoo:(pos=1) AND Zbar:(pos=2))")
     284                 "(Zfoo@1 AND Zbar@2)")
    285285
    286286    # Feature test for custom Stopper
    287287    class my_b_stopper(xapian.Stopper):
     
    296296    qp.set_stopper(stop)
    297297    expect(stop('a'), False)
    298298    expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
    299                  "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
     299                 "(Zfoo@1 AND Zbar@2 AND Za@3)")
    300300
    301301    expect(stop('b'), True)
    302302    expect_query(qp.parse_query("foo bar b", qp.FLAG_BOOLEAN),
    303                  "(Zfoo:(pos=1) AND Zbar:(pos=2))")
     303                 "(Zfoo@1 AND Zbar@2)")
    304304
    305305    # Test TermGenerator
    306306    termgen = xapian.TermGenerator()
     
    316316    vrpdate = xapian.DateValueRangeProcessor(1, 1, 1960)
    317317    qp.add_valuerangeprocessor(vrpdate)
    318318    query = qp.parse_query('12/03/99..12/04/01')
    319     expect(str(query), 'Xapian::Query(VALUE_RANGE 1 19991203 20011204)')
     319    expect(str(query), 'Query(0 * VALUE_RANGE 1 19991203 20011204)')
    320320
    321321    # Regression test for bug#193, fixed in 1.0.3.
    322322    context("running regression test for bug#193")
     
    377377    parser = xapian.QueryParser()
    378378    parser.set_stemmer(xapian.Stem(MyStemmer()))
    379379    parser.set_stemming_strategy(xapian.QueryParser.STEM_ALL)
    380     expect_query(parser.parse_query('color television'), '(clr:(pos=1) OR tlvsn:(pos=2))')
     380    expect_query(parser.parse_query('color television'), '(clr@1 OR tlvsn@2)')
    381381
    382382def test_zz9_check_leaks():
    383383    import gc
  • xapian-bindings/python/testsuite3.py

     
    8989        """Check that the description of a query is as expected.
    9090
    9191        """
    92         expected = 'Xapian::Query(' + expected + ')'
     92        expected = 'Query(' + expected + ')'
    9393        desc = str(query)
    9494        if self._verbose > 2:
    9595            self._out.start_line()
  • xapian-bindings/python/util.i

     
    2929
    3030/* Wrap get_description() methods as str(). */
    3131%rename(__str__) get_description;
     32%rename(__next__) next;
    3233
    3334/* Hide "unsafe" C++ iterator methods. */
    3435%rename(_allterms_begin) Xapian::Database::allterms_begin;
     
    166167        PyList_SET_ITEM(retval, idx++, t);
    167168
    168169#if PY_VERSION_HEX >= 0x03000000
    169         PyObject * str = PyBytes_FromStringAndSize((*i).data(), (*i).size());
     170        PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size());
    170171#else
    171172        PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size());
    172173#endif
     
    279280    }
    280281}
    281282
    282 %fragment("XapianSWIG_anystring_as_ptr", "header", fragment="SWIG_AsPtr_std_string") {
     283%fragment("XapianBytes_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
     284SWIGINTERN int
     285XapianBytes_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
     286{
     287%#if PY_VERSION_HEX>=0x03000000
     288  if (PyBytes_Check(obj))
     289%#else 
     290  if (PyString_Check(obj))
     291%#endif
     292  {
     293    char *cstr; Py_ssize_t len;
     294%#if PY_VERSION_HEX>=0x03000000
     295    if (!alloc && cptr) {
     296        /* We can't allow converting without allocation, since the internal
     297           representation of string in Python 3 is UCS-2/UCS-4 but we require
     298           a UTF-8 representation.
     299           TODO(bhy) More detailed explanation */
     300        return SWIG_RuntimeError;
     301    }
     302    PyBytes_AsStringAndSize(obj, &cstr, &len);
     303    if(alloc) *alloc = SWIG_NEWOBJ;
     304%#else
     305    PyString_AsStringAndSize(obj, &cstr, &len);
     306%#endif
     307    if (cptr) {
     308      if (alloc) {
     309        /*
     310           In python the user should not be able to modify the inner
     311           string representation. To warranty that, if you define
     312           SWIG_PYTHON_SAFE_CSTRINGS, a new/copy of the python string
     313           buffer is always returned.
     314
     315           The default behavior is just to return the pointer value,
     316           so, be careful.
     317        */
     318%#if defined(SWIG_PYTHON_SAFE_CSTRINGS)
     319        if (*alloc != SWIG_OLDOBJ)
     320%#else
     321        if (*alloc == SWIG_NEWOBJ)
     322%#endif
     323          {
     324            *cptr = %new_copy_array(cstr, len + 1, char);
     325            *alloc = SWIG_NEWOBJ;
     326          }
     327        else {
     328          *cptr = cstr;
     329          *alloc = SWIG_OLDOBJ;
     330        }
     331      } else {
     332        %#if PY_VERSION_HEX>=0x03000000
     333        assert(0); /* Should never reach here in Python 3 */
     334        %#endif
     335        *cptr = SWIG_Python_str_AsChar(obj);
     336      }
     337    }
     338    if (psize) *psize = len + 1;
     339%#if PY_VERSION_HEX>=0x03000000
     340    Py_XDECREF(obj);
     341%#endif
     342    return SWIG_OK;
     343  } else {
     344    swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
     345    if (pchar_descriptor) {
     346      void* vptr = 0;
     347      if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
     348        if (cptr) *cptr = (char *) vptr;
     349        if (psize) *psize = vptr ? (strlen((char *)vptr) + 1) : 0;
     350        if (alloc) *alloc = SWIG_OLDOBJ;
     351        return SWIG_OK;
     352      }
     353    }
     354  }
     355  return SWIG_TypeError;
     356}
     357}
     358
     359%fragment("XapianBytes_AsPtr_std_string","header",fragment="XapianBytes_AsCharPtrAndSize") {
     360SWIGINTERN int
     361XapianBytes_AsPtr_std_string (PyObject * obj, std::string **val)
     362{
     363  char* buf = 0 ; size_t size = 0; int alloc = SWIG_OLDOBJ;
     364  if (SWIG_IsOK((XapianBytes_AsCharPtrAndSize(obj, &buf, &size, &alloc)))) {
     365    if (buf) {
     366      if (val) *val = new std::string(buf, size - 1);
     367      if (alloc == SWIG_NEWOBJ) delete[] buf;
     368      return SWIG_NEWOBJ;
     369    } else {
     370      if (val) *val = 0;
     371      return SWIG_OLDOBJ;
     372    }
     373  } else {
     374    static int init = 0;
     375    static swig_type_info* descriptor = 0;
     376    if (!init) {
     377      descriptor = SWIG_TypeQuery("std::string" " *");
     378      init = 1;
     379    }
     380    if (descriptor) {
     381      std::string *vptr;
     382      int res = SWIG_ConvertPtr(obj, (void**)&vptr, descriptor, 0);
     383      if (SWIG_IsOK(res) && val) *val = vptr;
     384      return res;
     385    }
     386  }
     387  return SWIG_ERROR;
     388}
     389}
     390
     391%fragment("XapianSWIG_anystring_as_ptr", "header", fragment="SWIG_AsPtr_std_string", fragment="XapianBytes_AsPtr_std_string") {
    283392/* Utility function which works like SWIG_AsPtr_std_string, but
    284393 * converts unicode strings to UTF-8 simple strings first. */
    285394static int
    286395XapianSWIG_anystring_as_ptr(PyObject ** obj, std::string **val)
     396{
     397   if (PyBytes_Check(*obj)) {
     398      return XapianBytes_AsPtr_std_string(*obj, val);  //deal with PyBytes
     399   }
     400   else {
     401     return SWIG_AsPtr_std_string(*obj, val);  //deal with PyUnicode in Python3 and PyString in Python 2.x
     402   }
     403}
     404}
     405
     406
     407%fragment("XapianBytes_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
     408PyObject *
     409XapianBytes_FromCharPtrAndSize(const char* carray, size_t size)
    287410{
    288     if (PyUnicode_Check(*obj)) {
    289         PyObject * strobj = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(*obj), PyUnicode_GET_SIZE(*obj), "ignore");
    290         if (strobj == NULL) return SWIG_ERROR;
    291         int res = SWIG_AsPtr_std_string(strobj, val);
    292         Py_DECREF(strobj);
    293         return res;
     411  if (carray) {
     412    if (size > INT_MAX) {
     413      swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
     414      return pchar_descriptor ?
     415        SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
    294416    } else {
    295         return SWIG_AsPtr_std_string(*obj, val);
     417%#if PY_VERSION_HEX >= 0x03000000
     418      return PyBytes_FromStringAndSize(carray, %numeric_cast(size,int));
     419%#else
     420      return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
     421%#endif
    296422    }
     423  } else {
     424    return SWIG_Py_Void();
     425  }
    297426}
    298427}
    299428
     429%inline %{
     430typedef std::string pybytes;
     431%}
     432
     433
     434%typemap(out,fragment="XapianBytes_FromCharPtrAndSize") pybytes {
     435    $result = XapianBytes_FromCharPtrAndSize(static_cast< std::string >($1).data(),static_cast< std::string >($1).size());
     436}
     437%ignore  sortable_serialise;
     438%rename(sortable_serialise) Xapian::wrap_sortable_serialise;
     439%inline %{
     440namespace Xapian {
     441pybytes wrap_sortable_serialise(double value) {
     442  return Xapian::sortable_serialise(value);
     443
     444}
     445%}
     446
    300447/* These typemaps depends somewhat heavily on the internals of SWIG, so
    301448 * might break with future versions of SWIG.
    302449 */
     
    357504%typemap(directorin,noblock=1) std::string & {
    358505    $input = SWIG_From_std_string(static_cast< std::string >($1_name));
    359506}
     507
    360508%typemap(directorout,noblock=1) Xapian::valueno {
    361509    if (!PyTuple_Check($input)) {
    362510        %dirout_fail(SWIG_TypeError, "($type, std::string, std::string)");
     
    459607
    460608    for (size_t i = 0; i != num_tags; ++i) {
    461609%#if PY_VERSION_HEX >= 0x03000000
    462         PyObject * str = PyBytes_FromStringAndSize(tags[i].data(), tags[i].size());
     610        PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size());
    463611%#else
    464612        PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size());
    465613%#endif
  • xapian-bindings/python/python.i

     
    195195
    196196        // Unicode object.
    197197        if (PyUnicode_Check(obj)) {
    198             PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
    199                                                PyUnicode_GET_SIZE(obj),
    200                                                "ignore");
     198           // PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
     199                                               //PyUnicode_GET_SIZE(obj),
     200                                               //"ignore");
     201      PyObject *s=PyUnicode_AsUTF8String(obj);
    201202            if (!s) goto fail;
    202203            Xapian::Query result = str_obj_to_query(s);
    203204            Py_DECREF(s);
  • xapian-bindings/python/Makefile.am

     
    3131
    3232# Install as _DATA rather than _SCRIPTS because we don't want to make these
    3333# executable (they don't have a #! line).
    34 pkgpylib_DATA = xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo
     34pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo
    3535
    3636pkgpylib_LTLIBRARIES = _xapian.la
    3737
     
    6767
    6868# We "import _xapian" first so that if we fail to import the glue library
    6969# we don't generate a broken __init__.pyc or __init__.pyo.
    70 xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     70xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
    7171        PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian"
    7272        PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian"
    7373
    74 xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     74xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
    7575        PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian"
    7676        PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian"
    7777