Ticket #346: sabrina-python3-git-trunk.patch
File sabrina-python3-git-trunk.patch, 9.5 KB (added by , 13 years ago) |
---|
-
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 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__.pyo 34 #pkgpylib_DATA = xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo 35 pkgpylib_DATA = xapian/__init__.py xapian/__pycache__/__init__.cpython-32.pyc xapian/__pycache__/__init__.cpython-32.pyo 35 36 36 37 pkgpylib_LTLIBRARIES = _xapian.la 37 38 … … xapian/__init__.py: modern/xapian.py 67 68 68 69 # We "import _xapian" first so that if we fail to import the glue library 69 70 # 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) 72 xapian/__pycache__/__init__.cpython-32.pyc: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 71 73 PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -c "import _xapian" 72 74 PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -c "import xapian" 73 75 74 xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 76 #xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 77 xapian/__pycache__/__init__.cpython-32.pyo: xapian/__init__.py xapian/_xapian$(PYTHON_SO) 75 78 PYTHONPATH="xapian:$$PYTHONPATH" $(PYTHON) -O -c "import _xapian" 76 79 PYTHONPATH=".:$$PYTHONPATH" $(PYTHON) -O -c "import xapian" 77 80 -
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(): 261 261 expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')), 262 262 '(foo OR bar)') 263 263 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)') 267 267 expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'), 268 268 '(foo OR bar)') 269 269 270 270 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)") 272 272 273 273 doc = xapian.Document() 274 274 doc.set_data("Unicode with an acc\xe9nt") 275 275 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().term278 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") 279 279 280 280 # Check simple stopper 281 281 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 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; … … PyObject *Xapian_ESet_items_get(Xapian::ESet *eset) 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 … … namespace Xapian { 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) 287 396 { 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") { 407 PyObject * 408 XapianBytes_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(); 294 415 } 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 296 421 } 422 } else { 423 return SWIG_Py_Void(); 424 } 297 425 } 298 426 } 299 427 428 %inline %{ 429 typedef 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 %{ 439 namespace Xapian { 440 pybytes wrap_sortable_serialise(double value) { 441 return Xapian::sortable_serialise(value); 442 } 443 } 444 %} 445 300 446 /* These typemaps depends somewhat heavily on the internals of SWIG, so 301 447 * might break with future versions of SWIG. 302 448 */ … … XapianSWIG_anystring_as_ptr(PyObject ** obj, std::string **val) 459 605 460 606 for (size_t i = 0; i != num_tags; ++i) { 461 607 %#if PY_VERSION_HEX >= 0x03000000 462 PyObject * str = Py Bytes_FromStringAndSize(tags[i].data(), tags[i].size());608 PyObject * str = PyUnicode_FromStringAndSize(tags[i].data(), tags[i].size()); 463 609 %#else 464 610 PyObject * str = PyString_FromStringAndSize(tags[i].data(), tags[i].size()); 465 611 %#endif