aspectlib

aspectlib.ALL_METHODS Compiled regular expression objects
aspectlib.NORMAL_METHODS Compiled regular expression objects
aspectlib.weave Send a message to a recipient
aspectlib.Rollback When called, rollbacks all the patches and changes the weave() has done.
aspectlib.Aspect Container for the advice yielding generator.
aspectlib.Proceed Instructs the Aspect Calls to call the decorated function. Can be used multiple times.
aspectlib.Return Instructs the Aspect to return a value.
class aspectlib.Aspect(advise_function)[source]

Container for the advice yielding generator. Can be used as a decorator on other function to change behavior according to the advices yielded from the generator.

class aspectlib.Proceed(*args, **kwargs)[source]

Instructs the Aspect Calls to call the decorated function. Can be used multiple times.

If not used as an instance then the default args and kwargs are used.

class aspectlib.Return(value)[source]

Instructs the Aspect to return a value.

class aspectlib.Rollback(rollback=None)[source]

When called, rollbacks all the patches and changes the weave() has done.

__enter__()[source]

Returns self.

__exit__(*_)[source]

Performs the rollback.

rollback(*_)

Alias of __exit__.

__call__(*_)

Alias of __exit__.

aspectlib.ALL_METHODS Weave all magic methods. Can be used as the value for methods argument in weave.

Compiled regular expression objects

aspectlib.NORMAL_METHODS Only weave non-magic methods. Can be used as the value for methods argument in weave.

Compiled regular expression objects

aspectlib.weave(target, aspect[, subclasses=True, methods=NORMAL_METHODS, lazy=False, aliases=True])[source]

Send a message to a recipient

Parameters:
  • target (aspectlib.Aspect, function decorator or list of) – The object to weave.
  • aspects – The aspects to apply to the object.
  • subclasses (bool) – If True, subclasses of target are weaved. Only available for classes
  • aliases (bool) – If True, aliases of target are replaced.
  • lazy (bool) – If True only patch target’s __init__, the rest of the methods are patched after __init__ is called. Only available for classes
  • methods (list or regex or string) – Methods from target to patch. Only available for classes
Returns:

aspectlib.Rollback instance

Raises TypeError:
 

If target is a unacceptable object, or the specified options are not available for that type of object.

Changed in version 0.4.0: Replaced only_methods, skip_methods, skip_magicmethods options with methods. Renamed on_init option to lazy. Added aliases option. Replaced skip_subclasses option with subclasses.