Utilities and Miscellaneous#
- exception UserReportableError[source]#
Bases:
RuntimeError
An error reportable to the end user
Exceptions of this class or derived classes are able to be reported to the end user. Many exceptions should only be viewable by an administrator as they may leak implementation details or other sensitive information. Errors of this class are safe to report to all kinds of non-admin users.
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception UserManagementError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception AuthenticationFailure[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception AuthorizationFailure[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidUsernameError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidRolenameError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidGroupnameError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InconsistentUpdateError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception SecurityNotEnabledError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidPasswordError[source]#
Bases:
UserManagementError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception MissingDataError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception CorruptDataError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception AlreadyExistsError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception LimitExceededError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidUpdateError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception ComputeManagerError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception InvalidArgumentsError[source]#
Bases:
UserReportableError
- add_note()#
Exception.add_note(note) – add a note to the exception
- args#
- with_traceback()#
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class CompressionEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
str
,Enum
How data is compressed (compression method only, ie lzma, zstd)
- none = 'none'#
- lzma = 'lzma'#
- zstd = 'zstd'#
- compress(input_data, compression_type=CompressionEnum.zstd, compression_level=None)[source]#
Serializes and compresses data given a compression scheme and level
If compression_level is None, but a compression_type is specified, an appropriate default level is chosen
Returns a tuple containing the compressed data, applied compression type, and compression level (which may be different from the provided arguments)
- Parameters:
input_data (Any)
compression_type (CompressionEnum)
compression_level (int | None)
- Return type:
Tuple[bytes, CompressionEnum, int]
- decompress(compressed_data, compression_type)[source]#
Decompresses and deserializes data into python objects
- Parameters:
compressed_data (bytes)
compression_type (CompressionEnum)
- Return type:
Any
- encode_to_json(obj, encoder=None)[source]#
Takes an object and turns it into plain python that can be encoded to JSON.
This does not actually turn the object into JSON (string), just prepares it to be done. This is useful for turning various objects into something that can be put into a JSON(B) column in the database
- Parameters:
obj (Any)
encoder (JSONEncoder | None)
- Return type:
Any
- make_list(obj)[source]#
Returns a list containing obj if obj is not a list or other iterable type object
This will also work with sets
- Parameters:
obj (_T | Sequence[_T] | Set[_T] | None)
- Return type:
List[_T] | None
- chunk_iterable(it, chunk_size)[source]#
Split an iterable (such as a list) into batches/chunks
- Parameters:
it (Iterable[_T])
chunk_size (int)
- Return type:
Generator[List[_T], None, None]
- chunk_iterable_time(it, chunk_time, max_chunk_size, initial_chunk_size)[source]#
Split an iterable into chunks, trying to keep a constant time per chunk
This function keeps track of the time it takes to process each chunk and tries to keep the time per chunk as close to ‘chunk_time’ as possible, increasing or decreasing the chunk size as needed (up to ‘max_chunk_size’)
The first chunk will be of size ‘initial_chunk_size’ (assuming there is enough elements in the iterable to fill it).
- Parameters:
it (Iterable[_T])
chunk_time (float)
max_chunk_size (int)
initial_chunk_size (int)
- Return type:
Generator[List[_T], None, None]
- process_chunk_iterable(fn, it, chunk_time, max_chunk_size, initial_chunk_size, max_workers=1, *, keep_order=False)[source]#
Process an iterable in chunks, trying to keep a constant time per chunk
This function keeps track of the time it takes to process each chunk and tries to keep the time per chunk as close to ‘chunk_time’ as possible, increasing or decreasing the chunk size as needed (up to ‘max_chunk_size’)
The first chunk will be of size ‘initial_chunk_size’ (assuming there is enough elements in the iterable to fill it).
This function returns the results as chunks (lists) of the original iterable. If ‘keep_order’ is True, the results will be returned in the same order as the original iterable. If ‘keep_order’ is False, the results will be returned in the order they are completed.
- Parameters:
fn (Callable[[Iterable[_T]], Any])
it (Iterable[_T])
chunk_time (float)
max_chunk_size (int)
initial_chunk_size (int)
max_workers (int)
keep_order (bool)
- Return type:
Generator[List[_T], None, None]
- process_iterable(fn, it, chunk_time, max_chunk_size, initial_chunk_size, max_workers=1, *, keep_order=False)[source]#
Similar to process_chunk_iterable, but returns individual elements ranther than chunks
- Parameters:
fn (Callable[[Iterable[_T]], Any])
it (Iterable[_T])
chunk_time (float)
max_chunk_size (int)
initial_chunk_size (int)
max_workers (int)
keep_order (bool)
- Return type:
Generator[List[_T], None, None]
- seconds_to_hms(seconds)[source]#
Converts a number of seconds (as an integer) to a string representing hh:mm:ss
- Parameters:
seconds (float | int)
- Return type:
str
- duration_to_seconds(s)[source]#
Parses a string in dd:hh:mm:ss or 1d2h3m4s to an integer number of seconds
- Parameters:
s (int | str | float)
- Return type:
int
- recursive_normalizer(value, digits=10, lowercase=True)[source]#
Prepare a structure for hashing by lowercasing all values and round all floats
- Parameters:
value (Any)
digits (int)
lowercase (bool)
- Return type:
Any
- calculate_limit(max_limit, given_limit)[source]#
Get the allowed limit on results to return for a particular or type of object
If ‘given_limit’ is given (ie, by the user), this will return min(limit, max_limit) where max_limit is the set value for the table/type of object
- Parameters:
max_limit (int)
given_limit (int | None)
- Return type:
int
- capture_all_output(top_logger)[source]#
Captures all output, including stdout, stderr, and logging
- Parameters:
top_logger (str)
- now_at_utc()[source]#
Get the current time as a timezone-aware datetime object
- Return type:
datetime