Commits

Matt Chaput committed 55efc66

Change ArrayValues to take the array type as an argument.

  • Participants
  • Parent commits 3404559

Comments (0)

Files changed (2)

src/whoosh/support/dawg.py

     """Stores array.array objects in an FST.
     """
 
-    @staticmethod
-    def is_valid(v):
-        return isinstance(v, array)
+    def __init__(self, typecode):
+        self.typecode = typecode
+        self.itemsize = array(self.typecode).itemsize
+
+    def is_valid(self, v):
+        return isinstance(v, array) and v.typecode == self.typecode
 
     @staticmethod
     def write(dbfile, v):
         dbfile.write_int(len(v))
         dbfile.write_array(v)
 
-    @staticmethod
-    def read(dbfile):
+    def read(self, dbfile):
         typecode = u(dbfile.read(1))
         length = dbfile.read_int()
-        return dbfile.read_array(typecode, length)
+        return dbfile.read_array(self.typecode, length)
 
-    @staticmethod
-    def skip(dbfile):
-        typecode = u(dbfile.read(1))
+    def skip(self, dbfile):
         length = dbfile.read_int()
-        a = array(typecode)
-        dbfile.seek(length * a.itemsize, 1)
+        dbfile.seek(length * self.itemsize, 1)
 
     @staticmethod
     def to_bytes(v):

tests/test_dawg.py

 
     types = ((dawg.IntValues, 100, 0),
              (dawg.BytesValues, b('abc'), b('')),
-             (dawg.ArrayValues, array("i", [0, 123, 42]), array("i")),
+             (dawg.ArrayValues("i"), array("i", [0, 123, 42]), array("i")),
              (dawg.IntListValues, [0, 6, 97], []))
 
     for t, v, z in types:
               (b("110"), array("i", [894, 9, 101, 11])),
               (b("111"), array("i", [1030, 200, 1000, 2000])),
               ]
-    _fst_roundtrip(domain, dawg.ArrayValues)
+    _fst_roundtrip(domain, dawg.ArrayValues("i"))
 
 def test_fst_intlist():
     domain = [(b("000"), [1, 2, 3, 4]),