Miscellaneous utility functions and classes.
Mix-in for classes with a close() method to allow them to be used as a context manager.
Decodes a floating point number stored in a single byte.
Least-recently-used cache decorator.
This function duplicates (more-or-less) the protocol of the functools.lru_cache decorator in the Python 3.2 standard library, but uses the clock face LRU algorithm instead of an ordered dictionary.
If maxsize is set to None, the LRU features are disabled and the cache can grow without bound.
Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.
Zig-zag decodes an integer value.
Returns the nth value in the Fibonacci sequence.
Imports and returns an object given a fully qualified name.
>>> find_object("whoosh.analysis.StopFilter")
<class 'whoosh.analysis.StopFilter'>
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.
Encodes a floating point number in a single byte.
Double-barrel least-recently-used cache decorator. This is a simple LRU algorithm that keeps a primary and secondary dict. Keys are checked in the primary dict, and then the secondary. Once the primary dict fills up, the secondary dict is cleared and the two dicts are swapped.
This function duplicates (more-or-less) the protocol of the functools.lru_cache decorator in the Python 3.2 standard library.
Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.
Takes a function/class that takes two positional arguments and a list of arguments and returns a binary tree of results/instances.
>>> make_binary_tree(UnionMatcher, [matcher1, matcher2, matcher3])
UnionMatcher(matcher1, UnionMatcher(matcher2, matcher3))
Any keyword arguments given to this function are passed to the class initializer.
Takes a function/class that takes two positional arguments and a list of (weight, argument) tuples and returns a huffman-like weighted tree of results/instances.
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.
Parameters: | s – the str/unicode string to convert. |
---|---|
Return type: | tuple |
S.pack(v1, v2, ...) -> string
Return a string containing values v1, v2, ... packed according to this Struct’s format. See struct.__doc__ for more on format strings.
S.pack(v1, v2, ...) -> string
Return a string containing values v1, v2, ... packed according to this Struct’s format. See struct.__doc__ for more on format strings.
Decompresses a list of strings compressed by prefix_encode().
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.
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.
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.
A wrapper for re.compile that checks whether “pattern” is a regex object or a string to be compiled, and automatically adds the re.UNICODE flag.
Reads a variable-length encoded integer.
Parameters: | readfn – a callable that reads a given number of bytes, like file.read(). |
---|
Zig-zag encodes a signed integer into a varint.
Decorator for storage-access methods, which synchronizes on a threading lock. The parent object must have ‘is_closed’ and ‘_sync_lock’ attributes.
Caching decorator with an unbounded cache size.
S.unpack(str) -> (v1, v2, ...)
Return tuple containing values unpacked according to this Struct’s format. Requires len(str) == self.size. See struct.__doc__ for more on format strings.
S.unpack(str) -> (v1, v2, ...)
Return tuple containing values unpacked according to this Struct’s format. Requires len(str) == self.size. See struct.__doc__ for more on format strings.
Encodes the given integer into a string of the minimum number of bytes.