blockchain.utils package

Submodules

blockchain.utils.constants module

blockchain.utils.errors module

exception blockchain.utils.errors.ChainNotFoundError[source]

Bases: Exception

Error if no local chain could be found.

exception blockchain.utils.errors.ChainNotValidError[source]

Bases: Exception

Error if loaded chain is not valid.

exception blockchain.utils.errors.PortValueError[source]

Bases: ValueError

Error if given port is out af valid range (1 - 65535).

exception blockchain.utils.errors.ProgramKilledError[source]

Bases: Exception

Error if process get killed.

blockchain.utils.utils module

class blockchain.utils.utils.Job(interval: datetime.timedelta, execute, *args, **kwargs)[source]

Bases: threading.Thread

run() → None[source]

Runs the background Job

stop() → None[source]

Stops the background Job.

blockchain.utils.utils.colorize(text: str, color: str) → str[source]
blockchain.utils.utils.create_proper_url_string(host_port: (<class 'str'>, <class 'int'>), path: str) → str[source]

Takes the internal representation of neighbours and a endpoint path to create a proper URL string for requests.

Parameters:
  • host_port (str, int) – Internal representation of IP address/hostname and port combination.
  • path (str) – The endpoint of the API.
Returns:

Correct URL string for address and path.

Return type:

str

blockchain.utils.utils.encode_file_path_properly(file_path: str) → str[source]

Encode each and every input filepath as absolute pathes.

Parameters:file_path (str) – Path to encode properly
Returns:Absolute and properly encoded file_path
Return type:str
blockchain.utils.utils.signal_handler(signum, frame)[source]

Signal handler used to raise special ProgramKilledError.

Raises:ProgramKilledError – To intercept for graceful shutdown.
blockchain.utils.utils.split_url_string(host_port: str) -> (<class 'str'>, <class 'int'>)[source]

Parses the given URL string and returns the IP address/hostname and the port/default port.

Parameters:

host_port (str) – Representation of the miner as URL string, e.g.: 127.0.0.1:12345, miner1:8888, miner, http://localhost, …

Returns:

Tuple of IPv4 Address or hostname string and port number.

Return type:

(str, int)

Raises:
  • PortValueError – Will be raised if given port is out of range.
  • AddressValueError – Will be raised if given address is not a valid IPv4 address or “localhost”.

Module contents