Python interceptor package

Fritz Bosch uthand at
Thu Jun 17 09:42:53 CEST 2004

Dominic <nomail at> wrote in message news:<cap1fm$cai$1 at>..
> sys.settrace(...)
> (Python interpreter hook), it should do the job.

What I'm looking for is an Interceptor class whose
constructor would interpose its (callable) instance
between a caller and a specified function or method,
and whose 'destroy' method would remove the interposition.

One would typically subclass the Interceptor class to
achieve the required interceptor behaviour.

sys.settrace looks like a possible starting point to create
such a package, allthough it is somewhat indiscriminate for my
purposes (I want to be selective about what I intercept).
Of course the selection can occur inside the trace function,
but the performance penalty may be to large (I need it in
a run-time environment, not only in a development

I have actually started to experiment with an Interceptor
class, whose constructor modifies the __dict__ of a specified
class, to 'wrap' its  (callable) instance around the specified

I wanted to make sure, though, that I'm not re-inventing the
wheel, and perhaps hear whether anyone would be interested in
such a package.

So, comments are invited!


More information about the Python-list mailing list