No project description provided
Project description
Mending
Make Overwrite More flexible In Python
A Lite Package focuses on making project's after-post mending easier and more flexible. Certain Method performs differently in Certain Condition in an event queue. Certainly used for mending or expanding finished Projects without modifying existed Codes.
- No Origin Codes Changes, Injection with Licenses
- None Invasive Embed Way, More Flexible
- ✨Easy to use✨
Installation
Overwrite requires Python 3.6+ to run.
Simply install with one-line pip command.
pip install Mending
How to Use
Core Import
from Mending import Mend
Set a License Any type of Cipher-text is satisfactory. Set int 0 as example.
_license = 0
Defined Function Mending function, used for overwrite previous method.
def func():
return
Register Function to Event queue.
- Register_type (string): Register with the same Event_queue_type will be added to the same event queue (in registration order).
- times (integer): The times this function calling is affected. (if affected forever, set times to -1)
- license (any): Used to identify whether the modification is valid and distinguish between different overwrite events.
- func (function): Mending function, used for overwriting.
Mend = Mend()
Mend.Butler.register('Register_type', times, _license, func)
# Add entrance to function
@Mend.entrance(catalog='Register_type')
def affected_func():
return
Add the License Claim If the license is valid, the registered function affected_func will be modified and completely overwritten by func.
# Claim above the function calling
Mend.claim(_license)
affected_func()
The Performance above is same as:
func()
Features
Complex Overwrite
Mend.Butler.register('Event_queue_type_A', 1, license_A, func_A)
Mend.Butler.register('Event_queue_type_A', 2, license_B, func_B)
Mend.Butler.register('Event_queue_type_B', 1, license_B, func_C)
def func_A():
print('1')
return
def func_B():
print('2')
return
def func_C():
print('3')
return
@Mend.entrance(catalog='Event_queue_type_A')
def affected_func_A():
print('A')
return
@Mend.entrance(catalog='Event_queue_type_B')
def affected_func_B():
print('B')
return
Different license claiming leads to different way of overwriting. After several times calling set before, the performance of modified function will change back to origin again as a result of event queue gets empty. The program works as below:
@Mend.claim(license_B)
affected_func_A() # Output: 2
@Mend.claim(license_A)
affected_func_A() # Output: 1
@Mend.claim(license_B)
affected_func_A() # Output: 2
@Mend.claim(license_A)
affected_func_A() # Output: A
@Mend.claim(license_B)
affected_func_A() # Output: A
@Mend.claim(license_B)
affected_func_B() # Output: 3
@Mend.claim(license_B)
affected_func_B() # Output: B
Get Catalog Name and Available Licenses of Original Function
Mend.Butler.get(affected_func)
-> dict {'catalog_name': str, 'available_license': list[str]}
Browse the Event Queue
Print details for Event Queue:
Mend.Queue.print(catalog: str)
Get length of Event Queue:
Mend.Queue.len(catalog: str)
Get Event Queue as following type:
Mend.Queue.get(catalog: str)
[{'times_left': int, 'license': any, 'function_name': str},
{'times_left': int, 'license': any, 'function_name': str},
{'times_left': int, 'license': any, 'function_name': str},]
Directly manipulate the Event Queue
Class Queue redefined, making it compatible with Pythonic Style Commands as below:
Mend.Queue.append(catalog: str, event: list)
Mend.Queue.pop(catalog: str, index: int)
Mend.Queue.replace(catalog: str, event: list, index: int)
Mend.Queue.clear(catalog: str)
Threading
For multi-threaded function overrides, the event queue is cross-threaded, and the order of event completion depends on the total program time sequence, asynchrony may cause event order confusion. Instantiating Mending for each individual thread is a reasonable solution.
Development
Version: 2021.11.18 (0.0.8)
Author: Zack the White, Qcmcmc
Email Contact: Zack the White Qcmcmc
License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Mending-0.1.2.tar.gz.
File metadata
- Download URL: Mending-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/2.7.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6def230717ac2be8ceec0479fba2d1fe2422f5f3a40b24839a8d8d2e03109826
|
|
| MD5 |
10217f7cfedfe47e46f444cb8df8625a
|
|
| BLAKE2b-256 |
2795b933d693fe12f8f1ce3efcdb1dc48750a55803f66699a5c73f818c0fc043
|
File details
Details for the file Mending-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: Mending-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.1 requests/2.26.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/2.7.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6df55491bdd9fc720e54e5be5fab6a9aa502315de96b34eefa65e2d221ca086d
|
|
| MD5 |
166ec5eb6c39a9ab9b278651b28d018a
|
|
| BLAKE2b-256 |
fd6bb029a3ec5c2b0b22f5c128229120437c83419461ea8c585bb3d2b083f398
|