Skip to main content

A way to hijack python methods and functions and attach callbacks or alter functionality.

Project description

The pyjack contains two basic functions – pyjack.connect and pyjack.disconnect – which allow you to connect to other functions and methods. This can be used to:

  • attach observers or callbacks to functions/methods: Connect a callback ‘observer’ functions to be called whenever the pyjacked function is called. The callback is called with both the original arguments and the pyjacked function.

  • filter function/method arguments: A filter function can be provided which is used to alter the arguments passed to the function.

  • entirely replace existing function/method with your own function/method: pyjack allows you to ‘block’ the original function being called. In essence, this allows you to use pyjack to replace a function with your own callback (or filter) function.

Simple Example: Adding Callbacks To Functions

pyjack can be used to connect callbacks to functions:

import pyjack

def max_callback(input, pyjack_org_fn):
    print 'Someone is trying to max ' + str(input)
    print 'Also got some pyjack_org_fn ' + str(pyjack_org_fn)

pyjack.connect(max, callback = max_callback, filter = None, block = False)

print max([10, 20])

# When you are done, disconnect and everything is back to normal ...
pyjack.disconnect(max, callback = max_callback, filter = None, block = False)

More Uses

For more information …

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyjack-0.0.1.zip (9.6 kB view hashes)

Uploaded Source

Built Distributions

pyjack-0.0.1.win32-py2.6.exe (201.6 kB view hashes)

Uploaded Source

pyjack-0.0.1.win32-py2.5.exe (67.0 kB view hashes)

Uploaded Source

pyjack-0.0.1.win32-py2.4.exe (67.0 kB view hashes)

Uploaded Source

pyjack-0.0.1-py2.6.egg (5.3 kB view hashes)

Uploaded Source

pyjack-0.0.1-py2.5.egg (5.3 kB view hashes)

Uploaded Source

pyjack-0.0.1-py2.4.egg (5.3 kB view hashes)

Uploaded Source

Supported by

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