Utils¶
A module that provides common tools.
-
class
filers.tools.
KivyQueue
(notify_func, **kwargs)¶ Bases:
Queue.Queue
A Multithread safe class that calls a callback whenever an item is added to the queue. Instead of having to poll or wait, you could wait to get notified of additions.
>>> def callabck(): ... print('Added') >>> q = KivyQueue(notify_func=callabck) >>> q.put('test', 55) Added >>> q.get() ('test', 55)
Parameters: notify_func – The function to call when adding to the queue -
exception
Empty
¶ Bases:
exceptions.Exception
Exception raised by Queue.get(block=0)/get_nowait().
-
KivyQueue.
get
()¶ Returns the next items in the queue, if non-empty, otherwise a
Queue.Empty
exception is raised.
-
KivyQueue.
put
(key, val)¶ Adds a (key, value) tuple to the queue and calls the callback function.
-
exception
-
filers.tools.
str_to_float
(strnum, minval=0, maxval=2147483647L, err_max=True, val_type=<type 'float'>, err_val=None)¶ Returns a integer or float given a string possibly containing a number.
>>> str_to_float('9.578') 9.578 >>> str_to_float('9.a578', err_max=False) 0
Parameters: - strnum – The string containing the number.
- minval – The minimum value that can be returned. Defaults to 0.
- maxval – The maximum value that can be returned. Defaults to 2**31-1.
- err_max – Whether to return the maximum or minimum upon error. If True, the maximum is returned, otherwise the minimum. Defaults to True.
- val_type – The type to return. Can be float or int. Defaults to float.
- err_val – The value to return upon error. If None, either the max or min value is used. Otherwise this is used. Defaults to None.
-
filers.tools.
hashfile
(filename, hasher, blocksize=65536)¶ Returns a hash of the file.
>>> from hashlib import sha256 >>> hashfile('filepath', sha256()) '6Zxvdsfk327*'
Parameters: - filename – The filename of the file to hash.
- hasher – A hasher instance to use for computing the hash.
- blocksize – Splits the file up into blocksizes and reads them piecemeal. Defaults to 65536.
-
filers.tools.
to_bool
(val)¶ Takes anything and converts it to a bool type.
-
filers.tools.
ConfigProperty
(val, name, val_type, section, config_name)¶ Returns the correct partialy-initialized
ConfigParserProperty
class accoridng to the input parameters.Parameters: - val: anything
The default and error value to use for this property instance.
- name: str
The config key to use for this property instance.
- val_type: callable
The val_type callable to use for this property instance.
- section: str
The config section to use for this property instance.
- config_name: str
The config object name to use for this property instance.
Returns: A
ConfigParserProperty
instance.