Table of Contents

Class: advice ./src/peak/util/advice.py
advice(func)
"around advice" wrapper base class

This wrapper is a base class for "around" advice on a method. Just redefine the __call__ method to have the desired semantics. E.g.:

            class loggedMethod(advice):

                __slots__ = ()

                def __call__(self,*__args,**__kw):
                    print "Entering", self._func, __args, __kw
                    self._func(*__args,**__kw)
                    print "Leaving",self._func

            class someObject(object):

                def aMethod(self,foobly):
                    print foobly

                aMethod = loggedMethod(aMethod)

If your advice needs parameters, you'll probably want to override __init__() as well, and add some slots as appropriate. Note that the self parameter to __call__ is the advice object, not the self that will be passed through to the underlying function (which is the first item in __args.

The advice class tries to transparently emulate a normal Python method, and to be indistinguishable from such a method to inspectors like help() and ZPublisher's mapply(). Because of this, if callers of a method need to know that it is being "advised", you should document this in your method's docstring. There isn't any other way someone can tell, apart from reading your source or checking the type() or __class__ of the retrieved method's im_func.

Advice objects can be transparently stacked, so you can do things like aMethod = loggedMethod( lockedMethod(aMethod) ) safely.

Base Classes   
object
Methods   
__call__
__get__
__getattr__
__init__
__repr__
getCallable
getPositionalArgs
  __call__ 
__call__ (
        self,
        *__args,
        *__kw,
        )

  __get__ 
__get__ (
        self,
        ob,
        typ,
        )

  __getattr__ 
__getattr__ ( self,  attr )

  __init__ 
__init__ ( self,  func )

  __repr__ 
__repr__ ( self )

  getCallable 
getCallable ( self )

  getPositionalArgs 
getPositionalArgs ( self )

Return a sequence of positional argument names


Table of Contents

This document was automatically generated on Mon Nov 11 01:11:04 2024 by HappyDoc version 2.1