Ticket #346: sabrina-python3-git-trunk.patch

File sabrina-python3-git-trunk.patch, 9.5 KB (added by sabrina, 13 years ago)

This patch is the latest git trunk patch that makes smoketest3.py work.

  • xapian-bindings/python/Makefile.am

    diff --git a/xapian-bindings/python/Makefile.am b/xapian-bindings/python/Makefile.am
    index 2f5fad7..c55497d 100644
    a b pkgpylibdir = @PYTHON_LIB@/xapian  
    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
     34#pkgpylib_DATA = xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo
     35pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo
    3536
    3637pkgpylib_LTLIBRARIES = _xapian.la
    3738
    xapian/__init__.py: modern/xapian.py  
    6768
    6869# We "import _xapian" first so that if we fail to import the glue library
    6970# we don't generate a broken __init__.pyc or __init__.pyo.
    70 xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     71#xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     72xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
    7173        PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian"
    7274        PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian"
    7375
    74 xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     76#xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
     77xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
    7578        PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian"
    7679        PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian"
    7780
  • xapian-bindings/python/smoketest3.py

    diff --git a/xapian-bindings/python/smoketest3.py b/xapian-bindings/python/smoketest3.py
    index 76c80e9..46adbb4 100644
    a b def test_all():  
    261261    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')),
    262262                 '(foo OR bar)')
    263263    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xa3')),
    264                  '(foo OR bar\xc2\xa3)')
    265     expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xc2\xa3')),
    266                  '(foo OR bar\xc2\xa3)')
     264                 '(foo OR bar\u00a3)')
     265    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\u00a3')),
     266                 '(foo OR bar\u00a3)')
    267267    expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'),
    268268                 '(foo OR bar)')
    269269
    270270    expect_query(qp.parse_query("NOT t\xe9st", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
    271                  "(<alldocuments> AND_NOT Zt\xc3\xa9st@1)")
     271                 "(<alldocuments> AND_NOT Zt\u00e9st@1)")
    272272
    273273    doc = xapian.Document()
    274274    doc.set_data("Unicode with an acc\xe9nt")
    275275    doc.add_posting(stem("out\xe9r"), 1)
    276     expect(doc.get_data(), "Unicode with an acc\xe9nt".encode('utf-8'))
    277     term = doc.termlist().next().term
    278     expect(term, "out\xe9r".encode('utf-8'))
     276    expect(doc.get_data(), "Unicode with an acc\u00e9nt")
     277    term = next(doc.termlist()).term
     278    expect(term, "out\u00e9r")
    279279
    280280    # Check simple stopper
    281281    stop = xapian.SimpleStopper()
  • xapian-bindings/python/util.i

    diff --git a/xapian-bindings/python/util.i b/xapian-bindings/python/util.i
    index 7c03be7..d7ea7bb 100644
    a b  
    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;
    PyObject *Xapian_ESet_items_get(Xapian::ESet *eset)  
    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
    namespace Xapian {  
    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)
    287396{
    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;
     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%fragment("XapianBytes_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
     407PyObject *
     408XapianBytes_FromCharPtrAndSize(const char* carray, size_t size)
     409{
     410  if (carray) {
     411    if (size > INT_MAX) {
     412      swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
     413      return pchar_descriptor ?
     414        SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
    294415    } else {
    295         return SWIG_AsPtr_std_string(*obj, val);
     416%#if PY_VERSION_HEX >= 0x03000000
     417      return PyBytes_FromStringAndSize(carray, %numeric_cast(size,int));
     418%#else
     419      return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
     420%#endif
    296421    }
     422  } else {
     423    return SWIG_Py_Void();
     424  }
    297425}
    298426}
    299427
     428%inline %{
     429typedef std::string pybytes;
     430%}
     431
     432
     433%typemap(out,fragment="XapianBytes_FromCharPtrAndSize") pybytes {
     434    $result = XapianBytes_FromCharPtrAndSize(static_cast< std::string >($1).data(),static_cast< std::string >($1).size());
     435}
     436%ignore  sortable_serialise;
     437%rename(sortable_serialise) Xapian::wrap_sortable_serialise;
     438%inline %{
     439namespace Xapian {
     440pybytes wrap_sortable_serialise(double value) {
     441  return Xapian::sortable_serialise(value);
     442
     443}
     444%}
     445
    300446/* These typemaps depends somewhat heavily on the internals of SWIG, so
    301447 * might break with future versions of SWIG.
    302448 */
    XapianSWIG_anystring_as_ptr(PyObject ** obj, std::string **val)  
    459605
    460606    for (size_t i = 0; i != num_tags; ++i) {
    461607%#if PY_VERSION_HEX >= 0x03000000
    462         PyObject * str = PyBytes_FromStringAndSize(tags[i].data(), tags[i].size());
     608        PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size());
    463609%#else
    464610        PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size());
    465611%#endif