util module

Miscellaneous utility functions and classes.

class whoosh.util.ClosableMixin
Mix-in for classes with a close() method to allow them to be used as a context manager.
whoosh.util.byte_to_float(b, mantissabits=5, zeroexp=2)
Decodes a floating point number stored in a single byte.
whoosh.util.fib(n)
Returns the nth value in the Fibonacci sequence.
whoosh.util.first_diff(a, b)
Returns the position of the first differing character in the strings a and b. For example, first_diff(‘render’, ‘rending’) == 4. This function limits the return value to 255 so the difference can be encoded in a single byte.
whoosh.util.float_to_byte(value, mantissabits=5, zeroexp=2)
Encodes a floating point number in a single byte.
whoosh.util.lru_cache(size)

Decorator that adds a least-recently-accessed cache to a method.

Parameter:size – the maximum number of items to keep in the cache.
whoosh.util.natural_key(s)

Converts string s into a tuple that will sort “naturally” (i.e., name5 will come before name10 and 1 will come before A). This function is designed to be used as the key argument to sorting functions.

Parameter:s – the str/unicode string to convert.
Return type:tuple
whoosh.util.prefix_decode_all(ls)
Decompresses a list of strings compressed by prefix_encode().
whoosh.util.prefix_encode(a, b)
Compresses string b as an integer (encoded in a byte) representing the prefix it shares with a, followed by the suffix encoded as UTF-8.
whoosh.util.prefix_encode_all(ls)
Compresses the given list of (unicode) strings by storing each string (except the first one) as an integer (encoded in a byte) representing the prefix it shares with its predecessor, followed by the suffix encoded as UTF-8.
whoosh.util.protected(func)
Decorator for storage-access methods. This decorator (a) checks if the object has already been closed, and (b) synchronizes on a threading lock. The parent object must have ‘is_closed’ and ‘_sync_lock’ attributes.
whoosh.util.read_varint(readfn)

Reads a variable-length encoded integer.

Parameter:readfn – a callable that reads a given number of bytes, like file.read().
whoosh.util.varint(i)
Encodes the given integer into a string of the minimum number of bytes.

Previous topic

support.levenshtein module

Next topic

writing module

This Page