Module Expr Str Import alias ClassDef bases NameLoad body Expr Str decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Expr Call NameLoad NameLoad NameLoad NameLoad NameLoad decorator_list Assign NameStore Str Assign NameStore Str Assign NameStore Str Assign NameStore Str FunctionDef arguments args NameParam NameParam NameParam defaults body Expr Str Assign NameStore BinOpMod NameLoad TupleLoad Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Str Str AttributeLoad NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Return Call NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Expr Call NameLoad NameLoad NameLoad If UnaryOpNot Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad ListLoad Assign NameStore Call NameLoad NameLoad Call NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad NameLoad If UnaryOpNot Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Raise Call NameLoad Str Assign NameStore Call NameLoad NameLoad Call NameLoad NameLoad NameLoad TryExcept body Expr Call AttributeLoad NameLoad attr NameLoad handlers ExceptHandler type NameLoad body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad If BoolOpAnd UnaryOpNot Call NameLoad NameLoad Call NameLoad NameLoad NameLoad UnaryOpNot Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Expr Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Return FunctionDef arguments args defaults vararg kwarg body For NameStore Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Expr Call NameLoad NameLoad NameLoad TryFinally body Return Call Call NameLoad NameLoad Call NameLoad NameLoad NameLoad NameLoad NameLoad finalbody For NameStore Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Expr Call NameLoad NameLoad NameLoad decorator_list TryExcept body Assign AttributeStore NameLoad attr NameLoad handlers ExceptHandler type NameLoad body Pass Assign NameStore AttributeLoad Call NameLoad NameLoad NameLoad attr Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad NameLoad Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad ListLoad Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad ListLoad Expr Call NameLoad NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str If UnaryOpNot Call NameLoad NameLoad Call NameLoad NameLoad NameLoad body Raise Call NameLoad Str Expr Call NameLoad NameLoad NameLoad Call NameLoad NameLoad Call NameLoad NameLoad NameLoad Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad Expr Call NameLoad NameLoad Call NameLoad NameLoad NameLoad decorator_list
N/A N/A 
I define support for hookable instance methods.

These are methods which you can register pre-call and post-call external
functions to augment their functionality.  People familiar with more esoteric
languages may think of these as "method combinations".

This could be used to add optional preconditions, user-extensible callbacks
(a-la emacs) or a thread-safety mechanism.

The four exported calls are:

   - L{addPre}
   - L{addPost}
   - L{removePre}
   - L{removePost}

All have the signature (class, methodName, callable), and the callable they
take must always have the signature (instance, *args, **kw) unless the
particular signature of the method they hook is known.

Hooks should typically not throw exceptions, however, no effort will be made by
this module to prevent them from doing so.  Pre-hooks will always be called,
but post-hooks will only be called if the pre-hooks do not raise any exceptions
(they will still be called if the main method raises an exception).  The return
values and exception status of the main method will be propogated (assuming
none of the hooks raise an exception).  Hooks will be executed in the order in
which they are added.

 N/A string HookError N/A Exception N/A N/A An error which will fire when an invariant is violated. N/A addPre N/A N/A klass name func N/A N/A N/A hook.addPre(klass, name, func) -> None

    Add a function to be called before the method klass.name is invoked.
     N/A N/A _addHook klass name PRE func N/A addPost N/A N/A klass name func N/A N/A N/A hook.addPost(klass, name, func) -> None

    Add a function to be called after the method klass.name is invoked.
     N/A N/A _addHook klass name POST func N/A removePre N/A N/A klass name func N/A N/A N/A hook.removePre(klass, name, func) -> None

    Remove a function (previously registered with addPre) so that it
    is no longer executed before klass.name.
     N/A N/A _removeHook klass name PRE func N/A removePost N/A N/A klass name func N/A N/A N/A hook.removePre(klass, name, func) -> None

    Remove a function (previously registered with addPost) so that it
    is no longer executed after klass.name.
     N/A N/A _removeHook klass name POST func N/A N/A hooked_func 

import %(module)s

def %(name)s(*args, **kw):
    klazz = %(module)s.%(klass)s
    for preMethod in klazz.%(preName)s:
        preMethod(*args, **kw)
    try:
        return klazz.%(originalName)s(*args, **kw)
    finally:
        for postMethod in klazz.%(postName)s:
            postMethod(*args, **kw)
 N/A _PRE __hook_pre_%s_%s_%s__ N/A _POST __hook_post_%s_%s_%s__ N/A _ORIG __hook_orig_%s_%s_%s__ _XXX N/A N/A k n s N/A N/A N/A string manipulation garbage N/A x N/A s N/A N/A N/A string replace N/A k __module__ . _ N/A k __name__ n N/A x N/A PRE N/A N/A k n N/A N/A N/A (private) munging to turn a method name into a pre-hook-method-name N/A N/A _XXX k n _PRE N/A POST N/A N/A k n N/A N/A N/A (private) munging to turn a method name into a post-hook-method-name N/A N/A _XXX k n _POST N/A ORIG N/A N/A k n N/A N/A N/A (private) munging to turn a method name into an `original' identifier N/A N/A _XXX k n _ORIG N/A _addHook N/A N/A klass name phase func N/A N/A N/A (private) adds a hook to a method on a class N/A N/A _enhook klass name N/A N/A N/A hasattr klass N/A phase klass name N/A N/A N/A setattr klass N/A phase klass name N/A N/A phaselist N/A getattr klass N/A phase klass name N/A N/A N/A phaselist append func N/A _removeHook N/A N/A klass name phase func N/A N/A N/A (private) removes a hook from a method on a class N/A phaselistname N/A phase klass name N/A N/A N/A hasattr klass N/A ORIG klass name N/A N/A N/A HookError no hooks present! N/A phaselist N/A getattr klass N/A phase klass name N/A N/A N/A N/A N/A phaselist remove func N/A N/A N/A ValueError N/A N/A N/A HookError N/A hook %s not found in removal list for %s N/A name klass N/A N/A N/A N/A getattr klass N/A PRE klass name N/A N/A getattr klass N/A POST klass name N/A N/A N/A _dehook klass name N/A _enhook N/A N/A klass name N/A N/A N/A (private) causes a certain method name to be hooked on a class N/A N/A hasattr klass N/A ORIG klass name N/A N/A newfunc N/A N/A N/A args kw N/A N/A preMethod N/A getattr klass N/A PRE klass name N/A N/A N/A preMethod args kw N/A N/A N/A N/A N/A getattr klass N/A ORIG klass name args kw N/A N/A postMethod N/A getattr klass N/A POST klass name N/A N/A N/A postMethod args kw N/A N/A N/A N/A N/A newfunc func_name name N/A N/A N/A TypeError N/A N/A N/A oldfunc N/A N/A getattr klass name im_func N/A N/A setattr klass N/A ORIG klass name oldfunc N/A N/A setattr klass N/A PRE klass name N/A N/A N/A setattr klass N/A POST klass name N/A N/A N/A setattr klass name newfunc N/A _dehook N/A N/A klass name N/A N/A N/A (private) causes a certain method name no longer to be hooked on a class N/A N/A N/A hasattr klass N/A ORIG klass name N/A N/A N/A HookError Cannot unhook! N/A N/A setattr klass name N/A getattr klass N/A ORIG klass name N/A N/A delattr klass N/A PRE klass name N/A N/A delattr klass N/A POST klass name N/A N/A delattr klass N/A ORIG klass name N/A