Advertisement
Guest User

update patch to make smoketest3.py work

a guest
Apr 11th, 2012
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.36 KB | None | 0 0
  1. Here is SWIG patch:
  2. Index: Lib/python/pystrings.swg
  3. ===================================================================
  4. --- Lib/python/pystrings.swg (Version 12767)
  5. +++ Lib/python/pystrings.swg (Working Copy)
  6. @@ -6,7 +6,7 @@
  7. SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
  8. {
  9. %#if PY_VERSION_HEX>=0x03000000
  10. - if (PyUnicode_Check(obj))
  11. + if (PyUnicode_Check(obj) || PyBytes_Check(obj))
  12. %#else
  13. if (PyString_Check(obj))
  14. %#endif
  15. @@ -20,7 +20,10 @@
  16. TODO(bhy) More detailed explanation */
  17. return SWIG_RuntimeError;
  18. }
  19. - obj = PyUnicode_AsUTF8String(obj);
  20. + if (PyUnicode_Check(obj))
  21. + {
  22. + obj = PyUnicode_AsUTF8String(obj);
  23. + }
  24. PyBytes_AsStringAndSize(obj, &cstr, &len);
  25. if(alloc) *alloc = SWIG_NEWOBJ;
  26. %#else
  27. @@ -89,7 +92,10 @@
  28. SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
  29. } else {
  30. %#if PY_VERSION_HEX >= 0x03000000
  31. - return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
  32. + //return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
  33. + PyObject * obj = PyUnicode_DecodeUTF8(carray, %numeric_cast(size,int), NULL);
  34. + if (!obj) obj = PyBytes_FromStringAndSize(carray, %numeric_cast(size,int));
  35. + return obj;
  36. %#else
  37. return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
  38. %#endif
  39.  
  40.  
  41. Here is Xapian patch:
  42. Index: xapian-bindings/python/smoketest3.py
  43. ===================================================================
  44. --- xapian-bindings/python/smoketest3.py (Versoion 16472)
  45. +++ xapian-bindings/python/smoketest3.py (Working Copy)
  46. @@ -237,7 +237,7 @@
  47. # Check QueryParser pure NOT option
  48. qp = xapian.QueryParser()
  49. expect_query(qp.parse_query("NOT test", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
  50. - "(<alldocuments> AND_NOT test:(pos=1))")
  51. + "(<alldocuments> AND_NOT test@1)")
  52.  
  53. # Check QueryParser partial option
  54. qp = xapian.QueryParser()
  55. @@ -246,42 +246,42 @@
  56. qp.set_stemming_strategy(qp.STEM_SOME)
  57. qp.set_stemmer(xapian.Stem('en'))
  58. expect_query(qp.parse_query("foo o", qp.FLAG_PARTIAL),
  59. - "(Zfoo:(pos=1) AND ((out:(pos=2) SYNONYM outsid:(pos=2)) OR Zo:(pos=2)))")
  60. + "(Zfoo@1 AND ((out@2 SYNONYM outsid@2) OR Zo@2))")
  61.  
  62. expect_query(qp.parse_query("foo outside", qp.FLAG_PARTIAL),
  63. - "(Zfoo:(pos=1) AND Zoutsid:(pos=2))")
  64. + "(Zfoo@1 AND Zoutsid@2)")
  65.  
  66. # Test supplying unicode strings
  67. expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')),
  68. '(foo OR bar)')
  69. expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xa3')),
  70. - '(foo OR bar\xc2\xa3)')
  71. - expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xc2\xa3')),
  72. - '(foo OR bar\xc2\xa3)')
  73. + '(foo OR bar\u00a3)')
  74. + expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\u00a3')),
  75. + '(foo OR bar\u00a3)')
  76. expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'),
  77. '(foo OR bar)')
  78.  
  79. expect_query(qp.parse_query("NOT t\xe9st", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
  80. - "(<alldocuments> AND_NOT Zt\xc3\xa9st:(pos=1))")
  81. + "(<alldocuments> AND_NOT Zt\u00e9st@1)")
  82.  
  83. doc = xapian.Document()
  84. doc.set_data("Unicode with an acc\xe9nt")
  85. doc.add_posting(stem("out\xe9r"), 1)
  86. - expect(doc.get_data(), "Unicode with an acc\xe9nt".encode('utf-8'))
  87. - term = doc.termlist().next().term
  88. - expect(term, "out\xe9r".encode('utf-8'))
  89. + expect(doc.get_data(), "Unicode with an acc\u00e9nt")
  90. + term = next(doc.termlist()).term
  91. + expect(term, "out\u00e9r")
  92.  
  93. # Check simple stopper
  94. stop = xapian.SimpleStopper()
  95. qp.set_stopper(stop)
  96. expect(stop('a'), False)
  97. expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
  98. - "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
  99. + "(Zfoo@1 AND Zbar@2 AND Za@3)")
  100.  
  101. stop.add('a')
  102. expect(stop('a'), True)
  103. expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
  104. - "(Zfoo:(pos=1) AND Zbar:(pos=2))")
  105. + "(Zfoo@1 AND Zbar@2)")
  106.  
  107. # Feature test for custom Stopper
  108. class my_b_stopper(xapian.Stopper):
  109. @@ -296,11 +296,11 @@
  110. qp.set_stopper(stop)
  111. expect(stop('a'), False)
  112. expect_query(qp.parse_query("foo bar a", qp.FLAG_BOOLEAN),
  113. - "(Zfoo:(pos=1) AND Zbar:(pos=2) AND Za:(pos=3))")
  114. + "(Zfoo@1 AND Zbar@2 AND Za@3)")
  115.  
  116. expect(stop('b'), True)
  117. expect_query(qp.parse_query("foo bar b", qp.FLAG_BOOLEAN),
  118. - "(Zfoo:(pos=1) AND Zbar:(pos=2))")
  119. + "(Zfoo@1 AND Zbar@2)")
  120.  
  121. # Test TermGenerator
  122. termgen = xapian.TermGenerator()
  123. @@ -316,7 +316,7 @@
  124. vrpdate = xapian.DateValueRangeProcessor(1, 1, 1960)
  125. qp.add_valuerangeprocessor(vrpdate)
  126. query = qp.parse_query('12/03/99..12/04/01')
  127. - expect(str(query), 'Xapian::Query(VALUE_RANGE 1 19991203 20011204)')
  128. + expect(str(query), 'Query(0 * VALUE_RANGE 1 19991203 20011204)')
  129.  
  130. # Regression test for bug#193, fixed in 1.0.3.
  131. context("running regression test for bug#193")
  132. @@ -377,7 +377,7 @@
  133. parser = xapian.QueryParser()
  134. parser.set_stemmer(xapian.Stem(MyStemmer()))
  135. parser.set_stemming_strategy(xapian.QueryParser.STEM_ALL)
  136. - expect_query(parser.parse_query('color television'), '(clr:(pos=1) OR tlvsn:(pos=2))')
  137. + expect_query(parser.parse_query('color television'), '(clr@1 OR tlvsn@2)')
  138.  
  139. def test_zz9_check_leaks():
  140. import gc
  141. Index: xapian-bindings/python/testsuite3.py
  142. ===================================================================
  143. --- xapian-bindings/python/testsuite3.py (Versoion 16472)
  144. +++ xapian-bindings/python/testsuite3.py (Working Copy)
  145. @@ -89,7 +89,7 @@
  146. """Check that the description of a query is as expected.
  147.  
  148. """
  149. - expected = 'Xapian::Query(' + expected + ')'
  150. + expected = 'Query(' + expected + ')'
  151. desc = str(query)
  152. if self._verbose > 2:
  153. self._out.start_line()
  154. Index: xapian-bindings/python/util.i
  155. ===================================================================
  156. --- xapian-bindings/python/util.i (Versoion 16472)
  157. +++ xapian-bindings/python/util.i (Working Copy)
  158. @@ -29,6 +29,7 @@
  159.  
  160. /* Wrap get_description() methods as str(). */
  161. %rename(__str__) get_description;
  162. +%rename(__next__) next;
  163.  
  164. /* Hide "unsafe" C++ iterator methods. */
  165. %rename(_allterms_begin) Xapian::Database::allterms_begin;
  166. @@ -166,7 +167,7 @@
  167. PyList_SET_ITEM(retval, idx++, t);
  168.  
  169. #if PY_VERSION_HEX >= 0x03000000
  170. - PyObject * str = PyBytes_FromStringAndSize((*i).data(), (*i).size());
  171. + PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size());
  172. #else
  173. PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size());
  174. #endif
  175. @@ -285,18 +286,15 @@
  176. static int
  177. XapianSWIG_anystring_as_ptr(PyObject ** obj, std::string **val)
  178. {
  179. - if (PyUnicode_Check(*obj)) {
  180. - PyObject * strobj = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(*obj), PyUnicode_GET_SIZE(*obj), "ignore");
  181. - if (strobj == NULL) return SWIG_ERROR;
  182. - int res = SWIG_AsPtr_std_string(strobj, val);
  183. - Py_DECREF(strobj);
  184. - return res;
  185. - } else {
  186. - return SWIG_AsPtr_std_string(*obj, val);
  187. - }
  188. + if (PyUnicode_Check(*obj) || PyBytes_Check(*obj)) {
  189. + return SWIG_AsPtr_std_string(*obj, val);
  190. + } else {
  191. + return SWIG_ERROR;
  192. + }
  193. }
  194. }
  195.  
  196. +
  197. /* These typemaps depends somewhat heavily on the internals of SWIG, so
  198. * might break with future versions of SWIG.
  199. */
  200. @@ -357,6 +355,7 @@
  201. %typemap(directorin,noblock=1) std::string & {
  202. $input = SWIG_From_std_string(static_cast< std::string >($1_name));
  203. }
  204. +
  205. %typemap(directorout,noblock=1) Xapian::valueno {
  206. if (!PyTuple_Check($input)) {
  207. %dirout_fail(SWIG_TypeError, "($type, std::string, std::string)");
  208. @@ -459,7 +458,7 @@
  209.  
  210. for (size_t i = 0; i != num_tags; ++i) {
  211. %#if PY_VERSION_HEX >= 0x03000000
  212. - PyObject * str = PyBytes_FromStringAndSize(tags[i].data(), tags[i].size());
  213. + PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size());
  214. %#else
  215. PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size());
  216. %#endif
  217. Index: xapian-bindings/python/python.i
  218. ===================================================================
  219. --- xapian-bindings/python/python.i (Versoion 16472)
  220. +++ xapian-bindings/python/python.i (Working Copy)
  221. @@ -195,9 +195,10 @@
  222.  
  223. // Unicode object.
  224. if (PyUnicode_Check(obj)) {
  225. - PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
  226. - PyUnicode_GET_SIZE(obj),
  227. - "ignore");
  228. + // PyObject *s = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(obj),
  229. + //PyUnicode_GET_SIZE(obj),
  230. + //"ignore");
  231. + PyObject *s=PyUnicode_AsUTF8String(obj);
  232. if (!s) goto fail;
  233. Xapian::Query result = str_obj_to_query(s);
  234. Py_DECREF(s);
  235. Index: xapian-bindings/python/Makefile.am
  236. ===================================================================
  237. --- xapian-bindings/python/Makefile.am (Versoion 16472)
  238. +++ xapian-bindings/python/Makefile.am (Working Copy)
  239. @@ -31,7 +31,7 @@
  240.  
  241. # Install as _DATA rather than _SCRIPTS because we don't want to make these
  242. # executable (they don't have a #! line).
  243. -pkgpylib_DATA = xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo
  244. +pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo
  245.  
  246. pkgpylib_LTLIBRARIES = _xapian.la
  247.  
  248. @@ -67,11 +67,11 @@
  249.  
  250. # We "import _xapian" first so that if we fail to import the glue library
  251. # we don't generate a broken __init__.pyc or __init__.pyo.
  252. -xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
  253. +xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
  254. PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian"
  255. PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian"
  256.  
  257. -xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
  258. +xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)
  259. PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian"
  260. PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement