Ticket #346: sabrina-python3-update.patch
File sabrina-python3-update.patch, 13.3 KB (added by , 13 years ago) |
---|
-
xapian-bindings/python/smoketest3.py
237 237 # Check QueryParser pure NOT option 238 238 qp = xapian.QueryParser() 239 239 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)") 241 241 242 242 # Check QueryParser partial option 243 243 qp = xapian.QueryParser() … … 246 246 qp.set_stemming_strategy(qp.STEM_SOME) 247 247 qp.set_stemmer(xapian.Stem('en')) 248 248 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))") 250 250 251 251 expect_query(qp.parse_query("foo outside", qp.FLAG_PARTIAL), 252 "(Zfoo :(pos=1) AND Zoutsid:(pos=2))")252 "(Zfoo@1 AND Zoutsid@2)") 253 253 254 254 # Test supplying unicode strings 255 255 expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')), 256 256 '(foo OR bar)') 257 257 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)') 261 261 expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'), 262 262 '(foo OR bar)') 263 263 264 264 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)") 266 266 267 267 doc = xapian.Document() 268 268 doc.set_data("Unicode with an acc\xe9nt") 269 269 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().term272 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") 273 273 274 274 # Check simple stopper 275 275 stop = xapian.SimpleStopper() 276 276 qp.set_stopper(stop) 277 277 expect(stop('a'), False) 278 278 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)") 280 280 281 281 stop.add('a') 282 282 expect(stop('a'), True) 283 283 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)") 285 285 286 286 # Feature test for custom Stopper 287 287 class my_b_stopper(xapian.Stopper): … … 296 296 qp.set_stopper(stop) 297 297 expect(stop('a'), False) 298 298 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)") 300 300 301 301 expect(stop('b'), True) 302 302 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)") 304 304 305 305 # Test TermGenerator 306 306 termgen = xapian.TermGenerator() … … 316 316 vrpdate = xapian.DateValueRangeProcessor(1, 1, 1960) 317 317 qp.add_valuerangeprocessor(vrpdate) 318 318 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)') 320 320 321 321 # Regression test for bug#193, fixed in 1.0.3. 322 322 context("running regression test for bug#193") … … 377 377 parser = xapian.QueryParser() 378 378 parser.set_stemmer(xapian.Stem(MyStemmer())) 379 379 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)') 381 381 382 382 def test_zz9_check_leaks(): 383 383 import gc -
xapian-bindings/python/testsuite3.py
89 89 """Check that the description of a query is as expected. 90 90 91 91 """ 92 expected = ' Xapian::Query(' + expected + ')'92 expected = 'Query(' + expected + ')' 93 93 desc = str(query) 94 94 if self._verbose > 2: 95 95 self._out.start_line() -
xapian-bindings/python/util.i
29 29 30 30 /* Wrap get_description() methods as str(). */ 31 31 %rename(__str__) get_description; 32 %rename(__next__) next; 32 33 33 34 /* Hide "unsafe" C++ iterator methods. */ 34 35 %rename(_allterms_begin) Xapian::Database::allterms_begin; … … 166 167 PyList_SET_ITEM(retval, idx++, t); 167 168 168 169 #if PY_VERSION_HEX >= 0x03000000 169 PyObject * str = Py Bytes_FromStringAndSize((*i).data(), (*i).size());170 PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size()); 170 171 #else 171 172 PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size()); 172 173 #endif … … 279 280 } 280 281 } 281 282 282 %fragment("XapianSWIG_anystring_as_ptr", "header", fragment="SWIG_AsPtr_std_string") { 283 %fragment("XapianBytes_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") { 284 SWIGINTERN int 285 XapianBytes_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") { 360 SWIGINTERN int 361 XapianBytes_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") { 283 392 /* Utility function which works like SWIG_AsPtr_std_string, but 284 393 * converts unicode strings to UTF-8 simple strings first. */ 285 394 static int 286 395 XapianSWIG_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") { 408 PyObject * 409 XapianBytes_FromCharPtrAndSize(const char* carray, size_t size) 287 410 { 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(); 294 416 } 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 296 422 } 423 } else { 424 return SWIG_Py_Void(); 425 } 297 426 } 298 427 } 299 428 429 %inline %{ 430 typedef 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 %{ 440 namespace Xapian { 441 pybytes wrap_sortable_serialise(double value) { 442 return Xapian::sortable_serialise(value); 443 } 444 } 445 %} 446 300 447 /* These typemaps depends somewhat heavily on the internals of SWIG, so 301 448 * might break with future versions of SWIG. 302 449 */ … … 357 504 %typemap(directorin,noblock=1) std::string & { 358 505 $input = SWIG_From_std_string(static_cast< std::string >($1_name)); 359 506 } 507 360 508 %typemap(directorout,noblock=1) Xapian::valueno { 361 509 if (!PyTuple_Check($input)) { 362 510 %dirout_fail(SWIG_TypeError, "($type, std::string, std::string)"); … … 459 607 460 608 for (size_t i = 0; i != num_tags; ++i) { 461 609 %#if PY_VERSION_HEX >= 0x03000000 462 PyObject * str = Py Bytes_FromStringAndSize(tags[i].data(), tags[i].size());610 PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size()); 463 611 %#else 464 612 PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size()); 465 613 %#endif -
xapian-bindings/python/python.i
195 195 196 196 // Unicode object. 197 197 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); 201 202 if (!s) goto fail; 202 203 Xapian::Query result = str_obj_to_query(s); 203 204 Py_DECREF(s); -
xapian-bindings/python/Makefile.am
31 31 32 32 # Install as _DATA rather than _SCRIPTS because we don't want to make these 33 33 # executable (they don't have a #! line). 34 pkgpylib_DATA = xapian/__init__.py xapian/__ init__.pyc xapian/__init__.pyo34 pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo 35 35 36 36 pkgpylib_LTLIBRARIES = _xapian.la 37 37 … … 67 67 68 68 # We "import _xapian" first so that if we fail to import the glue library 69 69 # we don't generate a broken __init__.pyc or __init__.pyo. 70 xapian/__ init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO)70 xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 71 71 PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian" 72 72 PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian" 73 73 74 xapian/__ init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO)74 xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 75 75 PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian" 76 76 PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian" 77 77