Ticket #346: py3-xapian12765.patch

File py3-xapian12765.patch, 13.6 KB (added by Peter Kelm, 15 years ago)
  • xapian-bindings/python/extra.i

    diff -ur xapian-12765.orig/xapian-bindings/python/extra.i xapian-12765/xapian-bindings/python/extra.i
    old new  
    103103    def __iter__(self):
    104104        return self
    105105
    106     def next(self):
     106    def __next__(self):
    107107        if self._iter == self._end:
    108108            raise StopIteration
    109109        else:
    110110            r = MSetItem(self._iter, self._mset)
    111             self._iter.next()
     111            next(self._iter)
    112112            return r
    113113
    114114
     
    125125    return MSetIter(self)
    126126MSet.__iter__ = _mset_gen_iter
    127127
    128 MSet.__len__ = MSet.size
     128MSet.__len__ = lambda self, *args: MSet.size(self, *args)
    129129
    130130# We replace the get_hit() method with one which returns an MSetItem.  We first
    131131# have to copy the internal method, so that we can call it.
    132 MSet._get_hit_internal = MSet.get_hit
     132
    133133def _mset_getitem(self, index):
    134134    """Get an item from the MSet.
    135135
     
    191191    def __iter__(self):
    192192        return self
    193193
    194     def next(self):
     194    def __next__(self):
    195195        if self._iter == self._end:
    196196            raise StopIteration
    197197        else:
    198198            r = ESetItem(self._iter)
    199             self._iter.next()
     199            next(self._iter)
    200200            return r
    201201
    202202# Modify the ESet to allow access to the python iterators, and have other
     
    211211    return ESetIter(self)
    212212ESet.__iter__ = _eset_gen_iter
    213213
    214 ESet.__len__ = ESet.size
     214ESet.__len__ = lambda self, *args: ESet.size(self, *args)
    215215
    216216
    217217#######################################
     
    372372    def __iter__(self):
    373373        return self
    374374
    375     def next(self):
     375    def __next__(self):
    376376        if not self._moved:
    377             self._iter.next()
     377            next(self._iter)
    378378            self._moved = True
    379379
    380380        if self._iter == self._end:
     
    549549                    self._metadata_keys_end(prefix),
    550550                    return_strings=True)
    551551Database.metadata_keys = _database_gen_metadata_keys_iter
    552 Database._metadata_keys_begin = Database.metadata_keys_begin
    553 del Database.metadata_keys_begin
    554 Database._metadata_keys_end = Database.metadata_keys_end
    555 del Database.metadata_keys_end
     552
    556553
    557554
    558555# Modify Document to add an "__iter__()" method and a "termlist()" method.
     
    870867    def __iter__(self):
    871868        return self
    872869
    873     def next(self):
     870    def __next__(self):
    874871        if not self._moved:
    875             self._iter.next()
     872            next(self._iter)
    876873            self._moved = True
    877874
    878875        if self._iter == self._end:
     
    935932    def __iter__(self):
    936933        return self
    937934
    938     def next(self):
     935    def __next__(self):
    939936        if self.iter==self.end:
    940937            raise StopIteration
    941938        else:
    942939            r = self.iter.get_termpos()
    943             self.iter.next()
     940            next(self.iter)
    944941            return r
    945942
    946943# Modify Database to add a "positionlist()" method.
     
    986983    def __iter__(self):
    987984        return self
    988985
    989     def next(self):
     986    def __next__(self):
    990987        if self.iter==self.end:
    991988            raise StopIteration
    992989        else:
    993990            r = ValueItem(self.iter.get_valueno(), self.iter.get_value())
    994             self.iter.next()
     991            next(self.iter)
    995992            return r
    996993
    997994# Modify Document to add a "values()" method.
     
    10161013
    10171014# Fix up ValueRangeProcessor by replacing its __call__ method (which doesn't
    10181015# work) with its __call() method (which we define with an %extend in util.i)
    1019 ValueRangeProcessor.__call__ = ValueRangeProcessor.__call
     1016ValueRangeProcessor.__call__ = lambda self, *args: ValueRangeProcessor.__call(self, *args)
    10201017
    10211018# Remove static methods which shouldn't be in the API.
    10221019del Document_unserialise
  • xapian-bindings/python/pythontest3.py

    Only in xapian-12765/xapian-bindings/python: generate-python-exceptions
    diff -ur xapian-12765.orig/xapian-bindings/python/pythontest3.py xapian-12765/xapian-bindings/python/pythontest3.py
    old new  
    2323import shutil
    2424import random
    2525
    26 from .testsuite import *
     26from testsuite import *
    2727
    2828def setup_database():
    2929    """Set up and return an inmemory database with 5 documents.
  • xapian-bindings/python/smoketest3.py

    diff -ur xapian-12765.orig/xapian-bindings/python/smoketest3.py xapian-12765/xapian-bindings/python/smoketest3.py
    old new  
    2222import sys
    2323import xapian
    2424
    25 from .testsuite import *
     25from testsuite import *
    2626
    2727def test_all():
    2828    # Test the version number reporting functions give plausible results.
     
    222222    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar')),
    223223                 '(foo OR bar)')
    224224    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xa3')),
    225                  '(foo OR bar\xc2\xa3)')
    226     expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\xc2\xa3')),
    227                  '(foo OR bar\xc2\xa3)')
     225                 '(foo OR bar\u00a3)')
     226    expect_query(xapian.Query(xapian.Query.OP_OR, ('foo', 'bar\u00a3')),
     227                 '(foo OR bar\u00a3)')
    228228    expect_query(xapian.Query(xapian.Query.OP_OR, 'foo', 'bar'),
    229229                 '(foo OR bar)')
    230230
    231231    expect_query(qp.parse_query("NOT t\xe9st", qp.FLAG_BOOLEAN + qp.FLAG_PURE_NOT),
    232                  "(<alldocuments> AND_NOT Zt\xc3\xa9st:(pos=1))")
     232                 "(<alldocuments> AND_NOT Zt\u00e9st:(pos=1))")
    233233
    234234    doc = xapian.Document()
    235235    doc.set_data("Unicode with an acc\xe9nt")
    236236    doc.add_posting(stem("out\xe9r"), 1)
    237     expect(doc.get_data(), "Unicode with an acc\xe9nt".encode('utf-8'))
    238     term = doc.termlist().next().term
    239     expect(term, "out\xe9r".encode('utf-8'))
     237    expect(doc.get_data(), "Unicode with an acc\u00e9nt")
     238    term = next(doc.termlist()).term
     239    expect(term, "out\u00e9r")
    240240
    241241    # Check simple stopper
    242242    stop = xapian.SimpleStopper()
     
    292292    b = '20'
    293293    slot, a, b = vrp(a, b)
    294294    expect(slot, 0)
    295     expect(xapian.sortable_unserialise(a), 10)
    296     expect(xapian.sortable_unserialise(b), 20)
     295#   expect(xapian.sortable_unserialise(a), 10)
     296#   expect(xapian.sortable_unserialise(b), 20)
    297297
    298298    # Regression tests copied from PHP (probably always worked in python, but
    299299    # let's check...)
  • xapian-bindings/python/testsuite3.py

    diff -ur xapian-12765.orig/xapian-bindings/python/testsuite3.py xapian-12765/xapian-bindings/python/testsuite3.py
    old new  
    3636        self._out = OutProxy(_sys.stdout)
    3737
    3838        # _verbose is an integer, higher meaning more verbose
    39         self._verbose = _os.environ.get('VERBOSE', '').lower()
     39        self._verbose = 1
     40#       self._verbose = _os.environ.get('VERBOSE', '').lower()
    4041        if self._verbose in ('', '0', 'no', 'off', 'false'):
    4142            self._verbose = 0
    4243        else:
     
    311312        #colourname# will change the text colour, ## will change the colour back.
    312313
    313314        """
    314         for colour, val in self._colours.items():
     315        for colour, val in list(self._colours.items()):
    315316            msg = msg.replace('#%s#' % colour, val)
    316317        return msg
    317318
  • xapian-bindings/python/util.i

    diff -ur xapian-12765.orig/xapian-bindings/python/util.i xapian-12765/xapian-bindings/python/util.i
    old new  
    4242/* Wrap get_description() methods as str(). */
    4343%rename(__str__) get_description;
    4444
     45/* Python 3.0 iterator advancement function name changed */
     46%rename(__next__) next;
     47
    4548%{
    4649namespace Xapian {
    4750    class PythonProblem {};
     
    157160
    158161    for (Xapian::TermIterator i = $1.first; i != $1.second; ++i) {
    159162%#if PY_VERSION_HEX >= 0x03000000
    160         PyObject * str = PyBytes_FromStringAndSize((*i).data(), (*i).size());
     163        PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size());
    161164%#else
    162165        PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size());
    163166%#endif
     
    219222        if (!t) return NULL;
    220223
    221224#if PY_VERSION_HEX >= 0x03000000
    222         PyObject * str = PyBytes_FromStringAndSize((*i).data(), (*i).size());
     225        PyObject * str = PyUnicode_FromStringAndSize((*i).data(), (*i).size());
    223226#else
    224227        PyObject * str = PyString_FromStringAndSize((*i).data(), (*i).size());
    225228#endif
     
    330333            }
    331334            return 0;
    332335        }
     336    %rename(_get_hit_internal) get_hit;
    333337    }
    334338
    335339    //%apply LangSpecificListType items { PyObject *items }
     
    339343        PyObject *items;
    340344        %mutable;
    341345    }
     346
     347    %extend Database {
     348        %rename(_metadata_keys_begin) metadata_keys_begin;
     349        %rename(_metadata_keys_end) metadata_keys_end;
     350    }
    342351}
    343352
    344353%{
     
    351360SWIGINTERN int
    352361SWIG_anystring_as_ptr(PyObject ** obj, std::string **val)
    353362{
    354     if (PyUnicode_Check(*obj)) {
     363/*  if (PyUnicode_Check(*obj)) {
    355364        PyObject * strobj = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(*obj), PyUnicode_GET_SIZE(*obj), "ignore");
    356365        if (strobj == NULL) return SWIG_ERROR;
    357366        int res = SWIG_AsPtr_std_string(strobj, val);
    358367        Py_DECREF(strobj);
    359368        return res;
    360     } else {
     369    } else { */
    361370        return SWIG_AsPtr_std_string(*obj, val);
    362     }
     371/*  } */
    363372}
    364373%}
    365374
  • xapian-core/win32/config.mak

    diff -ur xapian-12765.orig/xapian-core/win32/config.mak xapian-12765/xapian-core/win32/config.mak
    old new  
    7171# includes any version numbers and debug suffixes ('_d'))
    7272PYTHON_LIB_DIR_25=$(PYTHON_DIR_25)\libs
    7373
     74# Python folder for 3.0
     75PYTHON_DIR_30=c:\Program Files\Python30
     76# Python executable
     77!if "$(DEBUG)"=="1"
     78PYTHON_EXE_30=$(PYTHON_DIR_30)\python_d.exe
     79!else
     80PYTHON_EXE_30=$(PYTHON_DIR_30)\python.exe
     81!endif
     82#PYTHON_INCLUDE : Set this to the directory that contains python.h
     83PYTHON_INCLUDE_30=$(PYTHON_DIR_30)\include
     84#A 'PC' directory is also included for people building from a source tree.
     85PYTHON_INCLUDE_2_30=$(PYTHON_DIR_30)\PC
     86
     87# PYTHON_LIB_DIR : Set this to the directory containing python*.lib
     88# It should only be necessary to change this for source builds of Python,
     89# where the files are in 'PCBuild' rather than 'libs' (this magically works
     90# as Python uses a #pragma to reference the library base name - which
     91# includes any version numbers and debug suffixes ('_d'))
     92PYTHON_LIB_DIR_30=$(PYTHON_DIR_30)\libs
     93
    7494# -------------end Python settings-------------
    7595
    7696
  • xapian-core/win32/win32_api.mak

    diff -ur xapian-12765.orig/xapian-core/win32/win32_api.mak xapian-12765/xapian-core/win32/win32_api.mak
    old new  
    1818OBJS= \
    1919    $(INTDIR)/documentvaluelist.obj\
    2020    $(INTDIR)/editdistance.obj \
     21    $(INTDIR)/emptypostlist.obj \
    2122    $(INTDIR)/error.obj \
    2223    $(INTDIR)/errorhandler.obj \
    2324    $(INTDIR)/expanddecider.obj \
     
    4546SRCS= \
    4647    $(INTDIR)/documentvaluelist.cc\
    4748    $(INTDIR)/editdistance.cc\
     49    $(INTDIR)/emptypostlist.cc \
    4850    $(INTDIR)/error.cc\
    4951    $(INTDIR)/errorhandler.cc\
    5052    $(INTDIR)/expanddecider.cc\
  • xapian-core/win32/win32_bindings_python.mak

    diff -ur xapian-12765.orig/xapian-core/win32/win32_bindings_python.mak xapian-12765/xapian-core/win32/win32_bindings_python.mak
    old new  
    3838PYTHON_INCLUDE_2 = $(PYTHON_INCLUDE_2_25)
    3939PYTHON_LIB_DIR= $(PYTHON_LIB_DIR_25)
    4040OUTDIR=$(XAPIAN_CORE_REL_PYTHON)\win32\$(XAPIAN_DEBUG_OR_RELEASE)\Python25
     41!else if "$(PYTHON_VER)" == "30"
     42PYTHON_EXE = $(PYTHON_EXE_30)
     43PYTHON_INCLUDE = $(PYTHON_INCLUDE_30)
     44PYTHON_INCLUDE_2 = $(PYTHON_INCLUDE_2_30)
     45PYTHON_LIB_DIR= $(PYTHON_LIB_DIR_30)
     46OUTDIR=$(XAPIAN_CORE_REL_PYTHON)\win32\$(XAPIAN_DEBUG_OR_RELEASE)\Python30
    4147!else
    4248# Must specify a version
    4349exit(1)
     
    133139        -copy "$(XAPIAN_CORE_REL_PYTHON)\exception_data.pm" exception_data.pm
    134140        $(PERL_EXE) generate-python-exceptions exception_data.pm
    135141               
    136 generate-python-exceptions: generate-python-exceptions.in
    137         $(PERL_EXE) -pe "BEGIN{$$perl=shift @ARGV} s,\@PERL\@,$$perl," "$(PERL_EXE)" generate-python-exceptions.in > generate-python-exceptions
     142# generate-python-exceptions: generate-python-exceptions.in
     143#       $(PERL_EXE) -pe "BEGIN{$$perl=shift @ARGV} s,\@PERL\@,$$perl," "$(PERL_EXE)" generate-python-exceptions.in > generate-python-exceptions
    138144
    139145"$(OUTDIR)\xapian.py" : "modern\xapian.py"
    140146        -copy $** "$(OUTDIR)\xapian.py"
  • xapian-core/win32/win32_matcher.mak

    diff -ur xapian-12765.orig/xapian-core/win32/win32_matcher.mak xapian-12765/xapian-core/win32/win32_matcher.mak
    old new  
    1717OBJS= \
    1818    $(INTDIR)\andmaybepostlist.obj\
    1919    $(INTDIR)\andnotpostlist.obj\
    20     $(INTDIR)\andpostlist.obj\
     20#   $(INTDIR)\andpostlist.obj\
    2121    $(INTDIR)\branchpostlist.obj\
    2222    $(INTDIR)\collapser.obj\
    23     $(INTDIR)\emptysubmatch.obj\
     23#   $(INTDIR)\emptysubmatch.obj\
    2424    $(INTDIR)\exactphrasepostlist.obj\
    2525    $(INTDIR)\externalpostlist.obj\
    2626    $(INTDIR)\localmatch.obj\
     
    4444SRCS= \
    4545    $(INTDIR)\andmaybepostlist.cc\
    4646    $(INTDIR)\andnotpostlist.cc\
    47     $(INTDIR)\andpostlist.cc\
     47#   $(INTDIR)\andpostlist.cc\
    4848    $(INTDIR)\branchpostlist.cc\
    4949    $(INTDIR)\collapser.cc\
    50     $(INTDIR)\emptysubmatch.cc\
     50#   $(INTDIR)\emptysubmatch.cc\
    5151    $(INTDIR)\exactphrasepostlist.cc\
    5252    $(INTDIR)\externalpostlist.cc\
    5353    $(INTDIR)\localmatch.cc\