Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install pyjack

How to install pyjack

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install pyjack
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.3.2 Available View build log
0.3.1 Available View build log
0.3.0 Available View build log
0.0.2 Available View build log
Windows (64-bit)
0.3.2 Available View build log
0.3.1 Available View build log
0.3.0 Available View build log
0.0.2 Available View build log
Mac OS X (10.5+)
0.3.2 Available View build log
0.3.1 Available View build log
0.3.0 Available View build log
0.0.2 Available View build log
Linux (32-bit)
0.3.2 Available View build log
0.3.1 Available View build log
0.3.0 Available View build log
0.0.2 Available View build log
Linux (64-bit)
0.3.2 Available View build log
0.3.1 Available View build log
0.3.0 Available View build log
0.0.2 Available View build log
 
Author
License
MIT
Imports
Lastest release
version 0.3.2 on Mar 15th, 2011

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

System Message: WARNING/2 (<string>, line 9)

Bullet list ends without a blank line; unexpected unindent.

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

System Message: WARNING/2 (<string>, line 14)

Bullet list ends without a blank line; unexpected unindent.

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

System Message: WARNING/2 (<string>, line 20)

Bullet list ends without a blank line; unexpected unindent.

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):

System Message: ERROR/3 (<string>, line 57)

Inconsistent literal block quoting.

... 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

System Message: ERROR/3 (<string>, line 82)

Inconsistent literal block quoting.

(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

System Message: ERROR/3 (<string>, line 93)

Inconsistent literal block quoting.

(100, 'one hundred')

So the process is reversible:

>>> new = pyjack.replace_all_refs(new, org_item)
>>>
>>> print item

System Message: ERROR/3 (<string>, line 100)

Inconsistent literal block quoting.

(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:

Subscribe to package updates

Last updated Mar 15th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.