app.utils
Submodules
app.utils.convertions
This module includes various data-type convertion utilities.
Some functions include representing a string or sequence of bytes as base64-encoded strings or serialization objects into JSON strings.
-
base64_bytelike_obj_to_bytes(obj)[source] Converts a byte-like object to a sequence of bytes.
-
base64_string_to_bytes(string)[source] Converts a base64 string to a sequence of bytes.
-
bytes_to_base64_string(data)[source] Converts a byte sequence or non base64 string to a base64-encoded string.
-
bytes_to_utf8string(data)[source] Converts a sequence of bytes a utf-8 string.
-
class_name_to_obj(module_name, class_name, args)[source] Uses reflection to instanciate a class by name.
- Examples:
The next two code snippets are equivalent:
>>> class_name_to_obj(MASTER_SERVERS, "Master", ["f.jpg", 1, 80])
>>> import app.domain.master_servers as ms >>> h = ms.Master("f.jpg", 1, 80)
- Parameters
- Returns
An object of the named class.
- Raises
AttributeError – When
class_namedoes not exist or whenmodule_nameto be imported causes cyclic import errors.ImportError – When
module_nameis not a valid module.
- Return type
Any
-
json_string_to_obj(json_string)[source] Deserializes a JSON string to a a python object.
- Parameters
json_string (str) – The string to be deserialized into a python object.
- Returns
A python object obtained from the processing
json_string.- Return type
Any
-
obj_to_json_string(obj)[source] Serializes a python object to a JSON string.
- Parameters
obj (Any) – The object to be serialized.
- Returns
A string representation of the
objin JSON format.- Return type
-
str_copy(string)[source] Hard copies a string
- Note:
Python’s builtin copy.deepcopy() does not deep copy strings.
-
truncate_float_value(f, d)[source] Truncates a float value without rounding.
app.utils.crypto
Utility module that includes confidentiality, integrity and authentication functions.
Note
As of current release this module only includes one function
sha256(), but if you need to test a swarm guidance algorithm
that does not assume the communication channels to be secure or
trustworthy you should implement the crypto related functions here.
app.utils.randoms
This module implements some functions related with random number generation.
-
excluding_randrange(start, stop, start_again, stop_again, step=1)[source] Generates a random number within two different intervals.”
- Parameters
start – Number consideration for generation starts from this.
stop – Numbers less than this are generated unless they are bigger or equal than
start_again.start_again – Number consideration for generation starts again from this.
stop_again – Number consideration stops here and does not include the inputed value.
step – Step point of range, this won’t be included.
- Returns
A randomly selected element from in the interval
[start, stop)or in[start_again, stop_again).