Tools to reversibly replace functions / objects with proxy functions / objects for debug, testing, monkey-patching.
Project description
pyjack is a debug/test/monkey-patching toolset that allows you to reversibly replace all references to a function or object in memory with a proxy function or object. pyjack has two major functions:
function “connect” can connect a ‘proxy’ function to almost any python function/method. This proxy function is called instead of the original function. However, the original function is passed to the proxy function along with all args, kwargs so you can do things like:
Modify the args, kwargs first, print a debug message, then call the original function
Not call the function, rather just log it and print a debug message
etc. etc. – it’s all up to you.
function “replace_all_refs” can be used to replace all references to a object with references to another object. This replaces all references in the _entire_ memory space. You get one final reference to the original reference, so it is possible to call this function again to restore the memory state back to it’s original state.
“connect” function
>>> import pyjack >>> >>> def fakeimport(orgopen, *args, **kwargs): ... print 'Trying to import %s' % args[0] ... return 'MODULE_%s' % args[0] ... >>> pyjack.connect(__import__, proxyfn=fakeimport) <..._PyjackFuncBuiltin object at 0x...> >>> >>> import time Trying to import time >>> print time MODULE_time >>> >>> __import__.restore() >>> >>> import time >>> print time <module 'time' (built-in)>
“replace_all_refs” function
Setup an ‘item’ reference and put it in a few places:
>>> item = (100, 'one hundred') >>> data = {item: True, 'itemdata': item} >>> >>> class Foobar(object): ... the_item = item ... >>> def outer(datum): ... def inner(): ... return ("Here is the datum:", datum,) ... ... return inner ... >>> inner = outer(item) >>> >>> print item (100, 'one hundred') >>> print data {'itemdata': (100, 'one hundred'), (100, 'one hundred'): True} >>> print Foobar.the_item (100, 'one hundred') >>> print inner() ('Here is the datum:', (100, 'one hundred'))
Then replace them:
>>> new = (101, 'one hundred and one') >>> org_item = pyjack.replace_all_refs(item, new) >>> >>> print item (101, 'one hundred and one') >>> print data {'itemdata': (101, 'one hundred and one'), (101, 'one hundred and one'): True} >>> print Foobar.the_item (101, 'one hundred and one') >>> print inner() ('Here is the datum:', (101, 'one hundred and one'))
But you still have one final reference to the org data:
>>> print org_item (100, 'one hundred')
So the process is reversible:
>>> new = pyjack.replace_all_refs(new, org_item) >>> >>> print item (100, 'one hundred') >>> print data {'itemdata': (100, 'one hundred'), (100, 'one hundred'): True} >>> print Foobar.the_item (100, 'one hundred') >>> print inner() ('Here is the datum:', (100, 'one hundred'))
Other References
For full documentation and several examples please visit:
The git repo is here:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file pyjack-0.3.2.zip
.
File metadata
- Download URL: pyjack-0.3.2.zip
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b3d54b0c9900e4cbd688161ba8a93c6073258d2a2140b76c1a6c868415c1441 |
|
MD5 | 04c9b86dbc81e49297bba508fe739489 |
|
BLAKE2b-256 | 5812632d618f2c33611e6d34a47bfdfc8567d83ae08c7d3dd640a0b48dd0a241 |
File details
Details for the file pyjack-0.3.2.tar.gz
.
File metadata
- Download URL: pyjack-0.3.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c0e55c66f69c89edcc7f24ad806d7712e702fb10adc1868285ec25971c5bf3b |
|
MD5 | 45b431fb3219e0e5988f0bf109b00e8e |
|
BLAKE2b-256 | 1a8fb51bba149c353b55a5ccea1d7c3040be22913d2d5bb9057f992e1e87784e |
File details
Details for the file pyjack-0.3.2.win-amd64-py2.7.exe
.
File metadata
- Download URL: pyjack-0.3.2.win-amd64-py2.7.exe
- Upload date:
- Size: 233.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23951d9acea8562639ab83cbf2f17fa9d5c5a0d08d88d60afcc25ad0ee5cd07b |
|
MD5 | 8638c74a35268ef9d242938464332799 |
|
BLAKE2b-256 | 3460b87a31e4725ce3dd9035897caa03e7a08c85d54f351940a6c8eb2e99076b |
File details
Details for the file pyjack-0.3.2.win-amd64-py2.6.exe
.
File metadata
- Download URL: pyjack-0.3.2.win-amd64-py2.6.exe
- Upload date:
- Size: 233.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b8cc3499bd517e81911e65fb86b15faa97132550101efc0b3126a76514309b6 |
|
MD5 | 49c6b0cbe3a7838a7eb877d096267627 |
|
BLAKE2b-256 | bbeace77c3c54c7593104adc362419b08365a63853dec4f1caea142c61d5a6e8 |
File details
Details for the file pyjack-0.3.2.win32-py2.7.exe
.
File metadata
- Download URL: pyjack-0.3.2.win32-py2.7.exe
- Upload date:
- Size: 205.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab1faa47750ed7c4c6c9c2267e3b8fd2682e2e7f873fecddc734cb86abaec50a |
|
MD5 | 7651f5660981abdd4f65f8a5a908b147 |
|
BLAKE2b-256 | 96db84579ebf91af55dcf668f7dbf75c640e1d0596fc34da623aaf906bb1b949 |
File details
Details for the file pyjack-0.3.2.win32-py2.6.exe
.
File metadata
- Download URL: pyjack-0.3.2.win32-py2.6.exe
- Upload date:
- Size: 75.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3690ede6974f405ec92c8409da4b79f7760f5a25bc43373f271d6bfa136bafe |
|
MD5 | af4a26721dee57d2fe86d30fa6c0a8dd |
|
BLAKE2b-256 | 6906ad6b38bf65f221a8b490998892349921edc7cde61cb6afdf5c1dfd66547f |
File details
Details for the file pyjack-0.3.2.win32-py2.5.exe
.
File metadata
- Download URL: pyjack-0.3.2.win32-py2.5.exe
- Upload date:
- Size: 71.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 928dd25ef5479575d1233c89a1355a907ffda6962531a205393c46e8fec2c92c |
|
MD5 | fb63a3e6987c4fa3c49f46d1a3b3cfc1 |
|
BLAKE2b-256 | 8d5fb63046ece1abdbc04169495b11ac9f032815d34fcd7b8998b5c7a10a4bc7 |
File details
Details for the file pyjack-0.3.2.win32-py2.4.exe
.
File metadata
- Download URL: pyjack-0.3.2.win32-py2.4.exe
- Upload date:
- Size: 71.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02d16aac42066397cc06c9b014d7b0333b73c9b3336f336ca75fae58986d9352 |
|
MD5 | 12c25df358642dce4d3462d45323944f |
|
BLAKE2b-256 | 4081e73561409d9b7cae33a58e37027d38cd5f8143d1a0ca9d49b8c7a2893893 |
File details
Details for the file pyjack-0.3.2-py2.7.egg
.
File metadata
- Download URL: pyjack-0.3.2-py2.7.egg
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 979db3afdd182763ccd4e7b9734b2cd0d1cc3a7df5c15e532e19ffce89b08e0d |
|
MD5 | 77cf81f6a5652bd2e812f4933437a279 |
|
BLAKE2b-256 | 812b55092919b048afd6c41126faafc82b53d34d4a2ab0bc4b2ed9471cc7a588 |
File details
Details for the file pyjack-0.3.2-py2.6.egg
.
File metadata
- Download URL: pyjack-0.3.2-py2.6.egg
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f827766a7344fa0c5a86d4a95041cd3d038ccc15b27385d7be001a77ab16ffb2 |
|
MD5 | 7ea69282f65b0ddb45827b2a03cf4e2d |
|
BLAKE2b-256 | ba8212c5b08ae3a0c73528f4e89d0526ebc8bf9b2e210d724e3e42bf560dd0ee |
File details
Details for the file pyjack-0.3.2-py2.5.egg
.
File metadata
- Download URL: pyjack-0.3.2-py2.5.egg
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f3b14b670c7a38002fcc312f9482774ee0ac7f80c8865a1dd70a7559fe49886 |
|
MD5 | 0e95c76365f213ac73271db036787ba3 |
|
BLAKE2b-256 | 90a39f22991ea3c3205076a13f51cb78f63c94f1235ac051181eed6b544f5830 |
File details
Details for the file pyjack-0.3.2-py2.4.egg
.
File metadata
- Download URL: pyjack-0.3.2-py2.4.egg
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02ccdc3661b7af9b846feae78fc06ca5dcf23f947a0b8d2566c5300a14606357 |
|
MD5 | 53988b1a221b30b622edf8f69a449c17 |
|
BLAKE2b-256 | faab5c36438099aaa003eaf0a66f1143fc6df0a0dc1161e7f484a9584d2416d0 |