AccidentallyTheCables Utility Kit
Project description
ATCKit
AccidentallyTheCable's Utility Kit
About
This is a small kit of classes, util functions, etc that I found myself rewriting or reusing frequently, and instead of copying everywhere, they are now here.
How does it work?
Do the needfuls.... do the needful dance
Literally, import whatever you need to use..
Usage
FunctionSubscriber
A Class container for Function callback subscription via +=
or -=
. Functions can be retrieved in order of addition.
subscriber = FunctionSubscriber()
def a():
print("I am a teapot")
def b():
print("I am definitely totally not also a teapot, I swear")
subscriber += a
subscriber += b
for cb in subscriber.functions:
cb()
>> I am a teapot
>> I am definitely totally not also a teapot, I swear
This class uses the typing.Callable
type for function storage. You can extend the FunctionSubscriber
class to define the
callback function parameters, etc.
class MySubscriber(FunctionSubscriber):
"""My Function Subscriber
Callback: (bool) -> None
"""
_functions:list[Callable[[bool],None]]
def __iadd__(self,fn:Callable[[bool],None]) -> Self:
"""Inline Add. Subscribe Function
@param method \c fn Method to Subscribe
"""
return super().__iadd__(fn)
def __isub__(self,fn:Callable[[bool],None]) -> Self:
"""Inline Subtract. Unsubscribe Function
@param method \c fn Method to Unsubscribe
"""
return super().__isub__(fn)
UtilFuncs
A Class containing various static methods:
- dump_sstr: Dump Structured Data (dict) to str of specified format. Accepts JSON, YAML, TOML
- load_sfile: Load Structured Data File, automatically determining data by file extension. Accepts JSON, YAML, TOML
- scan_dir: Search a specified Path, and execute a callback function on discovered files.
- Allows exclusion of Files/Dirs via regex pattern matching
- deep_sort: Sort a Dictionary recursively, including through lists of dicts
- check_pid: Check if a process ID exists (via kill 0)
- register_signals: Register Shutdown / Restart Handlers
- Check for Shutdown via UtilFuncs.shutdown (bool)
- Check for Restart via UtilFuncs.restart (bool)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file atckit-1.3.3.tar.gz
.
File metadata
- Download URL: atckit-1.3.3.tar.gz
- Upload date:
- Size: 81.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13e17854a9fb5f86a2aa9bdb2a904c7a306e47dc5ea77ab47f9239af5983c098 |
|
MD5 | ddee6b923bf66d740587869ad4119405 |
|
BLAKE2b-256 | 4532d8b015fc80865b32e5604926386f343668d53e21e71df292c5ec3b74f599 |
File details
Details for the file atckit-1.3.3-py3-none-any.whl
.
File metadata
- Download URL: atckit-1.3.3-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b07436aee8c04ab79857ff1c0972e78a7b3719f7e620c8956238029708fa54d |
|
MD5 | f0445ff0641ad7ff88a87d19bc5d4383 |
|
BLAKE2b-256 | b2812316ef937ebb0406b665069fbfbaeda1ae5986081b98e8231931c57642c7 |