Commits

Hideaki Takahashi committed f51f2de

fixing compatibility for Python3

Comments (0)

Files changed (4)

src/whoosh/codec/base.py

                 lasttext = text
                 continue
 
-            if fieldname < lastfn or (fieldname == lastfn and text < lasttext):
+            if (lastfn != None and fieldname < lastfn) or \
+               (fieldname == lastfn and (lasttext != None and text < lasttext)):
                 raise Exception("Postings are out of order: %r:%s .. %r:%s" %
                                 (lastfn, lasttext, fieldname, text))
             if fieldname != lastfn or text != lasttext:
 
 def minimize_weights(weights, compression=0):
     if all(w == 1.0 for w in weights):
-        string = ""
+        string = bytes_type()
     else:
         if not IS_LITTLE:
             weights.byteswap()

src/whoosh/compat.py

 
     xrange = xrange
     zip_ = zip
+    import struct
+    NaN = struct.unpack("<f", '\x00\x00\xc0\xff')[0]
 else:
     PY3 = True
     import collections
     StringIO = io.StringIO
     string_type = str
     text_type = str
-    bytes_tyep = bytes
+    bytes_type = bytes
     unichr = chr
     from urllib.request import urlretrieve
 
 
     xrange = range
     zip_ = lambda * args: list(zip(*args))
+    NaN = float("nan")

src/whoosh/fields.py

                              StandardAnalyzer, NgramAnalyzer, Tokenizer,
                              NgramWordAnalyzer, Analyzer)
 from whoosh.compat import (with_metaclass, itervalues, string_type, u,
-                           integer_types, long_type, text_type, xrange, PY3)
+                           integer_types, long_type, text_type, xrange, PY3,
+                           NaN)
 from whoosh.support.numeric import (int_to_text, text_to_int, long_to_text,
                                     text_to_long, float_to_text, text_to_float,
                                     )
 # fields. There's no "out-of-band" value possible (except for floats, where we
 # use NaN), so we try to be conspicuous at least by using the maximum possible
 # value
-NaN = struct.unpack("<f", '\x00\x00\xc0\xff')[0]
 NUMERIC_DEFAULTS = {"b": 2 ** 7 - 1, "B": 2 ** 8 - 1, "h": 2 ** 15 - 1,
                     "H": 2 ** 16 - 1, "i": 2 ** 31 - 1, "I": 2 ** 32 - 1,
                     "q": 2 ** 63 - 1, "Q": 2 ** 64 - 1, "f": NaN,

src/whoosh/filedb/structfile.py

         return ord(self.file.read(1))
 
     def get_byte(self, position):
-        return ord(self.map[position])
+        return unpack_byte(self.map[position:position+1])[0]
 
     def write_8bitfloat(self, f, mantissabits=5, zeroexp=2):
         """Writes a byte-sized representation of floating point value f to the