Skip to main content

Intercept function and method calls

Project description

Intercepts

Intercepts allows you to intercept any function call in python and handle it in any manner you choose. For example, you can pre-process the inputs to a function, or apply post-processing on its output. Intercepts also allows you to completely replace a function with a custom implementation.

>>> increment(41)
42
>>> intercepts.register(increment, handler)
>>> increment(41)
40
>>> intercepts.unregister(increment)
>>> intercepts.register(increment, handler2)
>>> increment(41)
'The answer is: 42'
>>> intercepts.unregister_all()

Handler functions receive the intercepted function as their first argument, as well as all of the arguments to the intercepted function.

>>> def handler(func, num):
...  result = func(num)
...  return num - (result - num)
>>> def handler2(func, *args, **kwargs):
...  return 'The answer is: %s' % func(*args, **kwargs)

Installation

Intercepts can be installed using pip.

$ pip install intercepts

Documentation

Sorry, we are in the very early stages of development so documentation is limited. There is some documentation in the docs directory, but for the most up-to-date documentation, use pydoc.

$ pydoc intercepts

This software is in early stages of development and may be unstable.

Project details


Release history Release notifications

This version
History Node

0.1.1

History Node

0.1

History Node

0.1a1

History Node

0.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
intercepts-0.1.1-py2.py3-none-any.whl (4.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Apr 21, 2018
intercepts-0.1.1.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None Apr 21, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page