Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Here is SWIG patch:
- Index: Lib/python/pystrings.swg
- ===================================================================
- --- Lib/python/pystrings.swg (Version 12767)
- +++ Lib/python/pystrings.swg (Working Copy)
- @@ -6,7 +6,7 @@
- SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
- {
- %#if PY_VERSION_HEX>=0x03000000
- - if (PyUnicode_Check(obj))
- + if (PyUnicode_Check(obj) || PyBytes_Check(obj))
- %#else
- if (PyString_Check(obj))
- %#endif
- @@ -20,7 +20,10 @@
- TODO(bhy) More detailed explanation */
- return SWIG_RuntimeError;
- }
- - obj = PyUnicode_AsUTF8String(obj);
- + if (PyUnicode_Check(obj))
- + {
- + obj = PyUnicode_AsUTF8String(obj);
- + }
- PyBytes_AsStringAndSize(obj, &cstr, &len);
- if(alloc) *alloc = SWIG_NEWOBJ;
- %#else
- @@ -89,7 +92,10 @@
- SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
- } else {
- %#if PY_VERSION_HEX >= 0x03000000
- - return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
- + //return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
- + PyObject * obj = PyUnicode_DecodeUTF8(carray, %numeric_cast(size,int), NULL);
- + if (!obj) obj = PyBytes_FromStringAndSize(carray, %numeric_cast(size,int));
- + return obj;
- %#else
- return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
- %#endif
- Here is Xapian patch:
- Index: xapian-bindings/python/smoketest3.py
- ===================================================================
- --- xapian-bindings/python/smoketest3.py (Versoion 16472)
- +++ xapian-bindings/python/smoketest3.py (Working Copy)
- @@ -237,7 +237,7 @@
- # Check QueryParser pure NOT option
- qp = xapian.QueryParser()
- expect_query(qp.parse_query("NOT test", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
- - "(<alldocuments> AND_NOT test:(pos=1))")
- + "(<alldocuments> AND_NOT test@1)")
- # Check QueryParser partial option
- qp = xapian.QueryParser()
- @@ -246,42 +246,42 @@
- qp.set_stemming_strategy(qp.STEM_SOME)
- qp.set_stemmer(xapian.Stem('en'))
- expect_query(qp.parse_query("foo o", qp.FLAG_PARTIAL),
- - "(Zfoo:(pos=1) AND ((out:(pos=2) SYNONYM outsid:(pos=2)) OR Zo:(pos=2)))")
- + "(Zfoo@1 AND ((out@2 SYNONYM outsid@2) OR Zo@2))")
- expect_query(qp.parse_query("foo outside", qp.FLAG_PARTIAL),
- - "(Zfoo:(pos=1) AND Zoutsid:(pos=2))")
- + "(Zfoo@1 AND Zoutsid@2)")
- # Test supplying unicode strings
- expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')),
- '(foo OR bar)')
- expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xa3')),
- - '(foo OR bar\xc2\xa3)')
- - expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xc2\xa3')),
- - '(foo OR bar\xc2\xa3)')
- + '(foo OR bar\u00a3)')
- + expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\u00a3')),
- + '(foo OR bar\u00a3)')
- expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'),
- '(foo OR bar)')
- expect_query(qp.parse_query("NOT t\xe9st", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
- - "(<alldocuments> AND_NOT Zt\xc3\xa9st:(pos=1))")
- + "(<alldocuments> AND_NOT Zt\u00e9st@1)")
- doc = xapian.Document()
- doc.set_data("Unicode with an acc\xe9nt")
- doc.add_posting(stem("out\xe9r"), 1)
- - expect(doc.get_data(), "Unicode with an acc\xe9nt".encode('utf-8'))
- - term = doc.termlist().next().term
- - expect(term, "out\xe9r".encode('utf-8'))
- + expect(doc.get_data(), "Unicode with an acc\u00e9nt")
- + term = next(doc.termlist()).term
- + expect(term, "out\u00e9r")
- # Check simple stopper
- stop = xapian.SimpleStopper()
- qp.set_stopper(stop)
- expect(stop('a'), False)
- expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
- - "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
- + "(Zfoo@1 AND Zbar@2 AND Za@3)")
- stop.add('a')
- expect(stop('a'), True)
- expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
- - "(Zfoo:(pos=1) AND Zbar:(pos=2))")
- + "(Zfoo@1 AND Zbar@2)")
- # Feature test for custom Stopper
- class my_b_stopper(xapian.Stopper):
- @@ -296,11 +296,11 @@
- qp.set_stopper(stop)
- expect(stop('a'), False)
- expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
- - "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
- + "(Zfoo@1 AND Zbar@2 AND Za@3)")
- expect(stop('b'), True)
- expect_query(qp.parse_query("foo bar b", qp.FLAG_BOOLEAN),
- - "(Zfoo:(pos=1) AND Zbar:(pos=2))")
- + "(Zfoo@1 AND Zbar@2)")
- # Test TermGenerator
- termgen = xapian.TermGenerator()
- @@ -316,7 +316,7 @@
- vrpdate = xapian.DateValueRangeProcessor(1, 1, 1960)
- qp.add_valuerangeprocessor(vrpdate)
- query = qp.parse_query('12/03/99..12/04/01')
- - expect(str(query), 'Xapian::Query(VALUE_RANGE 1 19991203 20011204)')
- + expect(str(query), 'Query(0 * VALUE_RANGE 1 19991203 20011204)')
- # Regression test for bug#193, fixed in 1.0.3.
- context("running regression test for bug#193")
- @@ -377,7 +377,7 @@
- parser = xapian.QueryParser()
- parser.set_stemmer(xapian.Stem(MyStemmer()))
- parser.set_stemming_strategy(xapian.QueryParser.STEM_ALL)
- - expect_query(parser.parse_query('color television'), '(clr:(pos=1) OR tlvsn:(pos=2))')
- + expect_query(parser.parse_query('color television'), '(clr@1 OR tlvsn@2)')
- def test_zz9_check_leaks():
- import gc
- Index: xapian-bindings/python/testsuite3.py
- ===================================================================
- --- xapian-bindings/python/testsuite3.py (Versoion 16472)
- +++ xapian-bindings/python/testsuite3.py (Working Copy)
- @@ -89,7 +89,7 @@
- """Check that the description of a query is as expected.
- """
- - expected = 'Xapian::Query(' + expected + ')'
- + expected = 'Query(' + expected + ')'
- desc = str(query)
- if self._verbose > 2:
- self._out.start_line()
- Index: xapian-bindings/python/util.i
- ===================================================================
- --- xapian-bindings/python/util.i (Versoion 16472)
- +++ xapian-bindings/python/util.i (Working Copy)
- @@ -29,6 +29,7 @@
- /* Wrap get_description() methods as str(). */
- %rename(__str__) get_description;
- +%rename(__next__) next;
- /* Hide "unsafe" C++ iterator methods. */
- %rename(_allterms_begin) Xapian::Database::allterms_begin;
- @@ -166,7 +167,7 @@
- PyList_SET_ITEM(retval, idx++, t);
- #if PY_VERSION_HEX >= 0x03000000
- - PyObject * str = PyBytes_FromStringAndSize((*i).data(), (*i).size());
- + PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size());
- #else
- PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size());
- #endif
- @@ -285,18 +286,15 @@
- static int
- XapianSWIG_anystring_as_ptr(PyObject ** obj, std::string **val)
- {
- - if (PyUnicode_Check(*obj)) {
- - PyObject * strobj = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(*obj), PyUnicode_GET_SIZE(*obj), "ignore");
- - if (strobj == NULL) return SWIG_ERROR;
- - int res = SWIG_AsPtr_std_string(strobj, val);
- - Py_DECREF(strobj);
- - return res;
- - } else {
- - return SWIG_AsPtr_std_string(*obj, val);
- - }
- + if (PyUnicode_Check(*obj) || PyBytes_Check(*obj)) {
- + return SWIG_AsPtr_std_string(*obj, val);
- + } else {
- + return SWIG_ERROR;
- + }
- }
- }
- +
- /* These typemaps depends somewhat heavily on the internals of SWIG, so
- * might break with future versions of SWIG.
- */
- @@ -357,6 +355,7 @@
- %typemap(directorin,noblock=1) std::string & {
- $input = SWIG_From_std_string(static_cast< std::string >($1_name));
- }
- +
- %typemap(directorout,noblock=1) Xapian::valueno {
- if (!PyTuple_Check($input)) {
- %dirout_fail(SWIG_TypeError, "($type, std::string, std::string)");
- @@ -459,7 +458,7 @@
- for (size_t i = 0; i != num_tags; ++i) {
- %#if PY_VERSION_HEX >= 0x03000000
- - PyObject * str = PyBytes_FromStringAndSize(tags[i].data(), tags[i].size());
- + PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size());
- %#else
- PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size());
- %#endif
- Index: xapian-bindings/python/python.i
- ===================================================================
- --- xapian-bindings/python/python.i (Versoion 16472)
- +++ xapian-bindings/python/python.i (Working Copy)
- @@ -195,9 +195,10 @@
- // Unicode object.
- if (PyUnicode_Check(obj)) {
- - PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
- - PyUnicode_GET_SIZE(obj),
- - "ignore");
- + // PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
- + //PyUnicode_GET_SIZE(obj),
- + //"ignore");
- + PyObject *s=PyUnicode_AsUTF8String(obj);
- if (!s) goto fail;
- Xapian::Query result = str_obj_to_query(s);
- Py_DECREF(s);
- Index: xapian-bindings/python/Makefile.am
- ===================================================================
- --- xapian-bindings/python/Makefile.am (Versoion 16472)
- +++ xapian-bindings/python/Makefile.am (Working Copy)
- @@ -31,7 +31,7 @@
- # Install as _DATA rather than _SCRIPTS because we don't want to make these
- # executable (they don't have a #! line).
- -pkgpylib_DATA = xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo
- +pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo
- pkgpylib_LTLIBRARIES = _xapian.la
- @@ -67,11 +67,11 @@
- # We "import _xapian" first so that if we fail to import the glue library
- # we don't generate a broken __init__.pyc or __init__.pyo.
- -xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
- +xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian"
- PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian"
- -xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
- +xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
- PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian"
- PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement