Matt Chaput avatar Matt Chaput committed d47b377

Added base methods to NumberEncoding in util.numlists.
Added timing() context manager to util.testing.
Fixed prefix encoding in util.text.

Comments (0)

Files changed (2)

src/whoosh/util/numlists.py

 # Number list encoding base class
 
 class NumberEncoding(object):
+    maxint = None
+
+    def write_nums(self, f, numbers):
+        raise NotImplementedError
+
+    def read_nums(self, f, n):
+        raise NotImplementedError
+
     def write_deltas(self, f, numbers):
-        return self.write_nums(f, delta_encode(numbers))
+        return self.write_nums(f, list(delta_encode(numbers)))
 
     def read_deltas(self, f, n):
         return delta_decode(self.read_nums(f, n))
 # Fixed width encodings
 
 class FixedEncoding(NumberEncoding):
+    _encode = None
+    _decode = None
+    size = None
+
     def write_nums(self, f, numbers):
         _encode = self._encode
 

src/whoosh/util/testing.py

 # policies, either expressed or implied, of Matt Chaput.
 
 import os.path, random, shutil, sys, tempfile, traceback
-from functools import wraps
+from contextlib import contextmanager
 
 from whoosh.filedb.filestore import FileStorage
 from whoosh.util import now
             if is_abstract_method(oattr):
                 raise Exception("%s.%s not overridden"
                                 % (subclass.__name__, attrname))
+
+
+@contextmanager
+def timing(name=None):
+    t = now()
+    yield
+    t = now() - t
+    print "%s: %0.06f s" % (name or '', t)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.