dictrack.utils package#

Submodules#

dictrack.utils.errors module#

exception dictrack.utils.errors.ConflictingNameError(group_id, name)#

Bases: KeyError

exception dictrack.utils.errors.DataStoreOperationError#

Bases: OSError

exception dictrack.utils.errors.GroupIdAlreadySetError(old, new)#

Bases: ValueError

exception dictrack.utils.errors.GroupIdDuplicateSetError(group_id)#

Bases: ValueError

exception dictrack.utils.errors.GroupIdLookupError(group_id)#

Bases: KeyError

exception dictrack.utils.errors.NameLookupError(name)#

Bases: KeyError

exception dictrack.utils.errors.RedisOperationError(message)#

Bases: DataStoreOperationError

exception dictrack.utils.errors.TrackerAlreadyCompletedError(group_id, name)#

Bases: ValueError

exception dictrack.utils.errors.TrackerAlreadyRemovedError(group_id, name)#

Bases: ValueError

exception dictrack.utils.errors.TrackerLookupError(group_id, name)#

Bases: KeyError

dictrack.utils.logger module#

dictrack.utils.utils module#

dictrack.utils.utils.numeric(value, allow_empty=False)#

Coerce the value to a numeric form, or raise an error if the coercion fails.

Parameters:
  • value (object) – The value to be coerced.

  • allow_empty (bool, optional) – Flag indicating whether None is allowed as a valid value. Defaults to False.

Raises:

ValueError – If the value is None and allow_empty is False, or if it cannot be coerced into a numeric form, or if it is not a valid numeric type.

Returns:

The coerced numeric value.

Return type:

int or float

dictrack.utils.utils.str_to_operator(ref)#

Return the operator corresponding to the given string reference.

Parameters:

ref (str) – The string reference of an operator.

Raises:
  • TypeError – If ref is not a string.

  • ValueError – If ref does not correspond to a valid operator.

Returns:

The operator corresponding to ref.

Return type:

callable

dictrack.utils.utils.typecheck(type_definitions={'b_tracker': <class 'bytes'>, 'data': <class 'dict'>, 'data_cache': <class 'dictrack.data_caches.base.BaseDataCache'>, 'data_store': <class 'dictrack.data_stores.base.BaseDataStore'>, 'group_id': (<class 'str'>, ), 'limiter': <class 'dictrack.limiters.base.BaseLimiter'>, 'tracker': <class 'dictrack.trackers.base.BaseTracker'>}, allow_empty=False)#

Decorator that checks and validates the types of method arguments based on a type definition table.

Parameters:
  • type_definitions (dict, optional) – A dictionary mapping argument names to their expected types, which can be a type or a tuple/list of types. Defaults to GLOBAL_DEFINES if not provided.

  • allow_empty (bool, optional) – If True, allows arguments to be None even if their type is defined in type_definitions. Defaults to False.

Returns:

A decorated function that checks argument types before execution.

Return type:

callable

dictrack.utils.utils.valid_callable(obj)#

Validate if the given object is callable.

Parameters:

obj (object) – The object to be validated.

Raises:

TypeError – If obj is not callable.

dictrack.utils.utils.valid_elements_obj(obj, expected_objs, allow_empty=False)#

Validate if all elements in an iterable match the expected objects.

Parameters:
  • obj (list or set or tuple) – An iterable whose elements will be validated.

  • expected_objs (object or tuple or list of objects) – The expected object(s) that each element in obj should match.

  • allow_empty (bool, optional) – If set to True, allows elements in obj to be None. Defaults to False.

Raises:
  • TypeError – If obj is not a list, set, or tuple.

  • ValueError – If any element in obj does not match expected_objs.

dictrack.utils.utils.valid_elements_type(obj, expected_types, allow_empty=False)#

Validate if all elements in an iterable match the expected types.

Parameters:
  • obj (list or set or tuple) – An iterable whose elements will be validated.

  • expected_types (type or tuple of types) – The expected type(s) that each element in obj should match.

  • allow_empty (bool, optional) – If set to True, allows elements in obj to be None. Defaults to False.

Raises:

TypeError – If obj is not a list, set, or tuple, or if any element does not match expected_types.

dictrack.utils.utils.valid_obj(obj, expected_objs, allow_empty=False)#

Validate if the given object is one of the expected objects.

Parameters:
  • obj (object) – The object to be validated.

  • expected_objs (tuple or list) – A single object or a tuple/list of expected objects that obj should match.

  • allow_empty (bool, optional) – If set to True, allows obj to be None. Defaults to False.

Raises:

ValueError – If obj is not in expected_objs.

dictrack.utils.utils.valid_type(obj, expected_types, allow_empty=False)#

Validate if the object matches the expected types.

Parameters:
  • obj (object) – The object to be validated.

  • expected_types (type or tuple or list of types) – A type or a tuple/list of types that obj is expected to match.

  • allow_empty (bool, optional) – If set to True, allows obj to be None. Defaults to False.

Raises:

TypeError – If obj is not an instance of expected_types.

Module contents#