pypz.core.commons.utils module

class pypz.core.commons.utils.InterruptableTimer

Bases: object

This is a utility timer that can be interrupted in thread safe manner. Note that this should not be used in cases, where accuracy matters.

interrupt()
sleep(seconds: float)
class pypz.core.commons.utils.SynchronizedReference(reference: ReferenceType)

Bases: Generic[ReferenceType]

This class realizes a synchronized reference i.e., it locks the object during read and write to avoid race conditions. This class is intended to safeguard for the time after the Global Interpreter Lock (GIL) has been removed. Note that only access through the object of this class guarantees a synchronized access.

Parameters:

reference – The reference to the object with the generic type ReferenceType.

get() ReferenceType | int | float | str | bytes | frozenset | tuple

Retrieves the referred object in a synchronized manner i.e., no reads or other writes will happen during this process. Notice that, if the object is mutable, then a deep copy shall be made to make sure that the consumer’s copy is not changed by any set operation.

Returns:

referenced object

set(reference: ReferenceType) None

Sets the referenced object in a synchronized manner i.e., no reads or other writes will happen during this process.

Parameters:

reference – reference to the object

class pypz.core.commons.utils.TemplateResolver(left_template_boundary: str, right_template_boundary: str)

Bases: object

This class realizes the logic to resolve templates in strings. As of 02/2024 only environment variables can be resolved.

Parameters:
  • left_template_boundary – the start of the template

  • right_template_boundary – the end of the template

m_envVarPattern

Regex to find the env var specifier pattern in the template pattern

m_templatePattern

Regex to find the template pattern

resolve(lookup_object)

This method attempts to recursively resolve template strings in either a Map or Collection or a normal String.

Parameters:

lookup_object – input object, where the resolution shall take place

Returns:

the modified object

pypz.core.commons.utils.convert_to_dict(obj: Any) Any

This method attempts to convert an object recursively to a dictionary.

Parameters:

obj – any object that can be converted to dict

Returns:

resulted dict or the object, if no valid conversion available (necessary due to the recursion)

pypz.core.commons.utils.current_time_millis() int
pypz.core.commons.utils.ensure_type(value, expected_type: type)

Convenience method to ensure that the value has the expected type.

Parameters:
  • value – value to check

  • expected_type – expected type

Raises:

TypeError

pypz.core.commons.utils.is_type_allowed(obj, allowed_types: tuple) bool

This convenience function checks if the type of the provided object is allowed given the tuple of allowed types provided as argument.

Parameters:
  • obj – object to check

  • allowed_types – allowed types

Returns:

True if allowed, False otherwise