pytilities.aop.aspect

class pytilities.aop.aspect.Aspect

Base class for aspects

Maps advice to members of a set of applied-to objects

_advise(get, set_, delete, call, *members)

Associate advice to given members

You cannot advise the same member twice for the same type of access, this implies that you cannot give advise to the special ‘*’ member and a regular member at the same for the same type of access.

A special member of ‘*’ is allowed for advising classes with metaclass=AOPMeta. This applies the advice to any member the applied object may have.

Check Advisor.is_advisable for further rules on what can be advised.

Parameters:
  • members (str, ...) – names of members to which to give advice
  • get (parameterless callable that returns a generator) – around advice given to get calls
  • set (parameterless callable that returns a generator) – around advice given to set calls
  • delete (parameterless callable that returns a generator) – around advice given to del calls
  • call (parameterless callable that returns a generator) – around advice given to __call__ calls
apply(obj)

Apply the advice to the object

If already applied, do nothing

When obj is a class, the advice is applied to all instances of that class (and the class itself, for staticmethods and such)

Note: Advice given to a single instance always wraps/preceeds advice given to all instances, no matter what the order of applying was

Parameters:obj (class, instance) – the object to advise. Cannot be a builtin object
disable(obj)

Disable advice for given object

Aspect must have been applied to object, before you can disable.

When this aspect is unapplied to the object, it is automatically reenabled.

If obj was already disabled, do nothing.

Parameters:obj (class, instance) – the object to advise
enable(obj)

Enable advice for given object

Aspect must have been applied to object, before you can enable.

If obj was already enabled, do nothing.

Parameters:obj (class, instance) – the object to advise
get_advice(member, access, obj)

Get advice for member of obj.

Internal function (its interface may change in the future).

Parameters:
  • member (str) – member name of the object
  • access (‘get’, ‘set’, ‘delete’ or ‘call’) – the type of access being done
  • obj (class, instance) – the object to advise
Returns:

advice func or None

is_applied(obj)

Get if this aspect is currently applied to an object.

See advisor.get_applied_aspects

Parameters:obj (class, instance) – the object to advise
Returns:True if aspect is in set of applied aspects of obj, False otherwise
is_enabled(obj)

Get if this aspect is enabled for an object.

An aspect can be applied to an object but currently be disabled. Disabled aspects should not be asked for advice on that obj.

Parameters:obj (class, instance) – the object to advise
Returns:True if advice is currently enabled for and applied to obj, False otherwise
unapply(obj)

Unapply the advice to the object

If advice wasn’t applied, do nothing

When obj is a class, the aspect is unapplied to all instances of that class (and the class itself).

Parameters:obj (class, instance) – the object to advise
class pytilities.aop.aspect.Aspect

Base class for aspects

Maps advice to members of a set of applied-to objects

apply(obj)

Apply the advice to the object

If already applied, do nothing

When obj is a class, the advice is applied to all instances of that class (and the class itself, for staticmethods and such)

Note: Advice given to a single instance always wraps/preceeds advice given to all instances, no matter what the order of applying was

Parameters:obj (class, instance) – the object to advise. Cannot be a builtin object
disable(obj)

Disable advice for given object

Aspect must have been applied to object, before you can disable.

When this aspect is unapplied to the object, it is automatically reenabled.

If obj was already disabled, do nothing.

Parameters:obj (class, instance) – the object to advise
enable(obj)

Enable advice for given object

Aspect must have been applied to object, before you can enable.

If obj was already enabled, do nothing.

Parameters:obj (class, instance) – the object to advise
get_advice(member, access, obj)

Get advice for member of obj.

Internal function (its interface may change in the future).

Parameters:
  • member (str) – member name of the object
  • access (‘get’, ‘set’, ‘delete’ or ‘call’) – the type of access being done
  • obj (class, instance) – the object to advise
Returns:

advice func or None

is_applied(obj)

Get if this aspect is currently applied to an object.

See advisor.get_applied_aspects

Parameters:obj (class, instance) – the object to advise
Returns:True if aspect is in set of applied aspects of obj, False otherwise
is_enabled(obj)

Get if this aspect is enabled for an object.

An aspect can be applied to an object but currently be disabled. Disabled aspects should not be asked for advice on that obj.

Parameters:obj (class, instance) – the object to advise
Returns:True if advice is currently enabled for and applied to obj, False otherwise
unapply(obj)

Unapply the advice to the object

If advice wasn’t applied, do nothing

When obj is a class, the aspect is unapplied to all instances of that class (and the class itself).

Parameters:obj (class, instance) – the object to advise

Previous topic

pytilities.aop.aopmeta

Next topic

pytilities.aop._aopdescriptor

This Page