Miscellaneous modules¶
utils – utilities¶
Utility functions and classes.
-
summer.utils.locate_file(path_to_module: str, filename: str) → str[source]¶ Tries to locate the file in module path. Starts the search in current directory and goes up in directory structure until file is found or module namespace is left.
Parameters: - path_to_module (str) – directory path, ususally just pass in
__file__built-in - filename (str) – file to look for
FIXME martin.slouf – now it only checks 3 levels up, instead of end of module namespace.
- path_to_module (str) – directory path, ususally just pass in
-
summer.utils.chunks(col: collections.abc.Iterable, chunk_size: int)[source]¶ Yield successive n-sized chunks from iterable.
Thanks to: http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python
Parameters: - col (collections.Iterable) – collection to be chunked
- chunk_size (int) – chunk size
Returns: - generator over collection of chunks
(collection of original elements split into several smaller collections of chunk_size length)
Return type: types.GeneratorType
-
class
summer.utils.Printable[source]¶ Bases:
objectTries to pretty print object properties into a unicode string.
Suitable for multi-inheritance, see
summer.model.Domain.-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.utils.FileReader(fin: io.IOBase, enc: str)[source]¶ Bases:
objectSimple & handy class for reading text file line by line with specified encoding. Converts line read to unicode. Counts line read. Does no file manipulation (opening, closing) except for reading. If used, you should delegate all reading to this simple class.
-
__init__(fin: io.IOBase, enc: str)[source]¶ Creates the
FileReaderinstance.Parameters: - fin (io.IOBase) – file-like object to be read
- enc (str) – file encoding
-
readline() → str[source]¶ Read single line from a file.
Returns: line as unicode string. Return type: str
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.utils.ThreadSafeCounter(initial_value=0)[source]¶ Bases:
objectThread safe counter.
-
__init__(initial_value=0)[source]¶ Creates
ThreadSafeCounterinstance.Parameters: initial_value (int) – initial value
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.utils.IdGenerator[source]¶ Bases:
objectThread safe id generator.
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
summer.utils.Singleton[source]¶ Bases:
typeMetaclass that makes the class producing singleton instance.
-
class
summer.utils.ConfigValue[source]¶ Bases:
objectConfiguration class that defines a default value while checking the os environment
os.environfor a possible override.-
convert_value_str(value_str: str, target_class: type) → object[source]¶ Utility method that converts a string value to proper type
Parameters: - value_str (str) – value to be converted
- target_class (type) – required target type
Returns: Converted value or original one, if no conversion found.
Return type: object
-
__weakref__¶ list of weak references to the object (if defined)
-
stringutils – string utilities¶
Utility string functions that should be probably part of Python stdlib.
EMPTY_STRING defines an empty string (ie. “”)
This module is not imported into public summer namespace, so you should import it directly:
from summer import stringutils
-
summer.stringutils.has_text(obj: object, strip: bool = True) → bool[source]¶ Check for text in string.
Parameters: - obj (object) – object to be tested
- strip (bool) – if
Trueobj is stripped before checking
Returns: Trueif obj is string and contains some non-whitecharacters;
Falseotherwise.
Return type: bool
-
summer.stringutils.to_unicode(obj: object, encoding: str) → str[source]¶ Return unicode representation of an object.
Returns: unicoce string object representation Return type: str
-
summer.stringutils.wrap(text: str, width: int) → str[source]¶ A word-wrap function that preserves existing line breaks and most spaces in the text. Expects that existing line breaks are posix newlines (\n).
Taken from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061/index_txt
Parameters: - text (str) – text to be wrapped
- width (int) – max number of characters in single line
Returns: wrapped original text
Return type: str
ipythonutils – ipython debugging support¶
Support for embedded IPython invocation.
This module is not imported into public summer namespace, so you should import it directly:
from summer import ipythonutils
-
summer.ipythonutils.run_ipshell(banner: str = None, local_variables: dict = None)[source]¶ Runs an embedded IPython interpretter at the place of your call.
To invoke the interpreter at the place of your choice:
from summer.ipythonutils import run_ipshell run_ipshell()
Parameters: - banner (str) – banner (greeting) to be used
- local_variables (dict) – dictionary of variables accessible through
lvariable in invoked shell, defaults to currentlocals()
ass – assert¶
Provides various pre-implemented simple tests (ie. asserts) suitable for input argument testing.
This module is not imported into public summer namespace, so you should import it directly:
from summer import ass
-
exception
summer.ass.AssertException(message: str = None, **kwargs)[source]¶ Bases:
summer.ex.ApplicationExceptionRaised when some of the assertions methods in this module fails.
-
summer.ass.is_none(obj: object, msg: str = None, **kwargs) → bool[source]¶ Parameters: - obj (object) – object instance to be tested
- msg (str) – message in exception if test fails
- kwargs – arguments forwarded to exceptions (usually context values that are presented in stacktrace alongside the message.
Returns: Trueif obj isNone,Falseotherwise.Return type: bool
-
summer.ass.is_not_none(obj: object, msg: str = None, **kwargs) → bool[source]¶ Parameters: - obj (object) – object instance to be tested
- msg (str) – message in exception if test fails
- kwargs – arguments forwarded to exceptions (usually context values that are presented in stacktrace alongside the message.
Returns: Trueif obj is notNone,Falseotherwise.Return type: bool
-
summer.ass.is_true(expr: bool, msg: str = None, **kwargs) → bool[source]¶ Parameters: - expr (bool) – object instance to be tested
- msg (str) – message in exception if test fails
- kwargs – arguments forwarded to exceptions (usually context values that are presented in stacktrace alongside the message.
Returns: Trueif expr isTrue,Falseotherwise.Return type: bool
-
summer.ass.is_false(expr: bool, msg: str = None, **kwargs) → bool[source]¶ Parameters: - expr (bool) – object instance to be tested
- msg (str) – message in exception if test fails
- kwargs – arguments forwarded to exceptions (usually context values that are presented in stacktrace alongside the message.
Returns: Trueif expr isFalse,Falseotherwise.Return type: bool
-
summer.ass.has_text(obj: str, msg: str = None, **kwargs) → bool[source]¶ Parameters: - obj (str) – object instance to be tested
- msg (str) – message in exception if test fails
- kwargs – arguments forwarded to exceptions (usually context values that are presented in stacktrace alongside the message.
Returns: Trueif obj isstrand is not empty,Falseotherwise.Return type: bool
lod – list of dictionaries¶
List of dictionaries (lod) – simple yet powerfull in memory data structure, ie. grid.
This module is not imported into public summer namespace, so you should import it directly:
from summer import lod
-
summer.lod.lod_populate(lod: list, fin: io.IOBase)[source]¶ Populate lod using CSV file.
Parameters: - lod (list) – list to be extended with data
- fin (io.IOBase) – file-like object in CSV format