utils.misc#

Module Contents#

utils.misc.mkdir_if_not_exists(folder)#
utils.misc.expand_url(url)#
utils.misc.getattr_or(o: object, prop: str, default=None)#
class utils.misc.DateTimeEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.JSONEncoder

Extensible JSON <https://json.org> encoder for Python data structures.

Supports the following objects and types by default:

Python

JSON

dict

object

list, tuple

array

str

string

int, float

number

True

true

False

false

None

null

To extend this to recognize other objects, subclass and implement a .default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError).

default(o)#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
utils.misc.dump_payload(p)#
utils.misc.update_nested_dict(dictionary, update_dict)#
utils.misc.random_str(length: int = 32) str#
utils.misc.json_loader(cli_val)#
utils.misc.calculate_file_hash(filename: str, hash_algo=hashlib.sha256, chunksize: int = 16000000) str#
utils.misc.get_current_datetime_iso() str#
utils.misc.get_datetime_from_str(dt_str: str, fmt: str | None = None) datetime.datetime | None#
utils.misc.get_timestamp(ts, utc=True, iso=True) str | datetime.datetime | None#
utils.misc.get_current_timestamp() str#