Skip to main content

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

pyjack-0.3.1.zip (7.7 kB view details)

Uploaded Source

pyjack-0.3.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyjack-0.3.1.win-amd64-py2.7.exe (231.2 kB view details)

Uploaded Source

pyjack-0.3.1.win-amd64-py2.6.exe (231.2 kB view details)

Uploaded Source

pyjack-0.3.1.win32-py2.7.exe (203.6 kB view details)

Uploaded Source

pyjack-0.3.1.win32-py2.6.exe (73.5 kB view details)

Uploaded Source

pyjack-0.3.1.win32-py2.5.exe (68.9 kB view details)

Uploaded Source

pyjack-0.3.1.win32-py2.4.exe (68.9 kB view details)

Uploaded Source

pyjack-0.3.1-py2.7.egg (8.6 kB view details)

Uploaded Egg

pyjack-0.3.1-py2.6.egg (8.6 kB view details)

Uploaded Egg

pyjack-0.3.1-py2.5.egg (8.6 kB view details)

Uploaded Egg

pyjack-0.3.1-py2.4.egg (8.7 kB view details)

Uploaded Egg

File details

Details for the file pyjack-0.3.1.zip.

File metadata

  • Download URL: pyjack-0.3.1.zip
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1.zip
Algorithm Hash digest
SHA256 cc2d070f8da8d31ab43b9bd9d1a9973dbff804a69bc8a2050e6b92b4e0d7d341
MD5 f06d6627cb77a3c181e2b6b6bed6a245
BLAKE2b-256 ae46c4cf292b1a5e24c7782e6c10b1d493bb4aba8a2d5b319f042ce35205bea5

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.tar.gz.

File metadata

  • Download URL: pyjack-0.3.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1.tar.gz
Algorithm Hash digest
SHA256 970db4820af0bbeb13e72abca381065cc4695a21a410863d518b086b9f3afa4e
MD5 d776388e29003549b35f960098cf1ed2
BLAKE2b-256 2588d3fd058226fd94e7d44d0cb97b1485c422097dee699ba52796cf8809d160

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 e755fcf5942a1bbf0ea69bd6259dbf059aa2e05fefbb15fdfc889dc86dfb6071
MD5 1d40280a517313f749a3692b045a91bd
BLAKE2b-256 b3a7f2ece43ed482c63760d9d26f00141cb9f7a0949b112fc0e7137eabf399f9

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 e567a746479251662d8500c210f92f0a46e7fda792f7f787ec764eabb5da182b
MD5 335180304ea05ba67c7c862ebe5532aa
BLAKE2b-256 2a035b649c9b16f3faf48dcf3ff4cb4c453c41a9213da0d8f51ef483699dd242

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win32-py2.7.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win32-py2.7.exe
Algorithm Hash digest
SHA256 dc7b1844a91b39c4f587ad681ba4261bbe9c54994ffda6d0777b01186a9eb839
MD5 f2a1520a88a0545e5fd67e55a5660561
BLAKE2b-256 55f0eb027fde16b095482f9b24d6642fc35837d57fa10508afcb7c1af703a064

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win32-py2.6.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win32-py2.6.exe
Algorithm Hash digest
SHA256 ebfdc892ad74dc4effdba8cf50acb56942fce91d14d6bbe68ec468f88ebfee97
MD5 4ec9170c215d8b14fd2d52a39358602c
BLAKE2b-256 dfdafe7c4e7c16332065eb45e8b81b9faba58810c7ded973f1c7ad780b683f0d

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win32-py2.5.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win32-py2.5.exe
Algorithm Hash digest
SHA256 26432be327f75b00cceb6a8bbf4eed0b7feede4b21e1e01eb87439b3dd44eef8
MD5 e392970b706eefbdd3c475414fb94541
BLAKE2b-256 99c009ed2fd2eaa418d26820520cb6deb6aaca4d1943dd723bbd0f6f991e65b9

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1.win32-py2.4.exe.

File metadata

File hashes

Hashes for pyjack-0.3.1.win32-py2.4.exe
Algorithm Hash digest
SHA256 a81de9eb3fa7b7d26f8def4d56159b1c0d6928f4dc9dc0f04e50af2cb293c9aa
MD5 817d0dd78b1618bdf28afbc10b9196f3
BLAKE2b-256 1d3a078974e74e7230e7e197122ea01732d8c67bad7c96f7166418633d76d34c

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1-py2.7.egg.

File metadata

  • Download URL: pyjack-0.3.1-py2.7.egg
  • Upload date:
  • Size: 8.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1-py2.7.egg
Algorithm Hash digest
SHA256 0c75a2c2e10a63cf650d4c72e4f59d67d8a3d727ccc46a5786827fcb8f330b40
MD5 c33df54bc825d324a5a3d7a16f36b151
BLAKE2b-256 ad7a545e9a152a753815eb59f0451619e179e653e850d8b4bf1f75dc919d341c

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1-py2.6.egg.

File metadata

  • Download URL: pyjack-0.3.1-py2.6.egg
  • Upload date:
  • Size: 8.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1-py2.6.egg
Algorithm Hash digest
SHA256 60c853bb8409b5de58dfb1635be91336347439cb6814e7c646ac84080c5cdfa6
MD5 f3ef33b8d45c153800c402bea07a424a
BLAKE2b-256 1552f95f8792ee3df7d8d5ab7235dd00563e44c2bcd5afafcb8f826eaf831175

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1-py2.5.egg.

File metadata

  • Download URL: pyjack-0.3.1-py2.5.egg
  • Upload date:
  • Size: 8.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1-py2.5.egg
Algorithm Hash digest
SHA256 d80cdf5c14bf344b21b1c9230a82036ac858aa4dc7c2ed5c36fb607c585eb107
MD5 9f5fd830202ce7a7a2dd35be4d762690
BLAKE2b-256 39840cde73cdf68f686b096d42cef75a169d27e716f56ebea1daed49a24b16d4

See more details on using hashes here.

File details

Details for the file pyjack-0.3.1-py2.4.egg.

File metadata

  • Download URL: pyjack-0.3.1-py2.4.egg
  • Upload date:
  • Size: 8.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyjack-0.3.1-py2.4.egg
Algorithm Hash digest
SHA256 7e1e36229804a90ff4891d11d2b7001ebfe9ddf710a9ff719606001c3ebcf6b6
MD5 95b693d52528205b446d66007b9083f3
BLAKE2b-256 f1cff627cd67d2dabe05330cba24f673ff94a3d2acdda244e1024eb56ff496f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page