pytilities.aop.aspect

class pytilities.aop.aspect.Aspect

Base class for aspects

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

_advice_mappings

Mappings of (access, attribute_name) to advice to give or None, where access is either ‘get’, ‘set’, ‘delete’ or ‘call’. Default value is {}.

Check Advisor.is_advisable for rules on valid attribute_name’s

_undefined_keys

Boolean that indicates whether or not advice mappings has a sensible result for keys(). Default is False.

Some mappings do not support keys because their set of keys is infinite or hard to determine. (FunctionMap is an example of such Mappings)

If set to True, the aspect can only be applied to objects with AOPMeta as metaclass.

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(attribute, access, obj)

Get advice for attribute of obj.

Internal function

Parameters:
  • attribute (str) – name of attribute to advise
  • 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(attribute, access, obj)

Get advice for attribute of obj.

Internal function

Parameters:
  • attribute (str) – name of attribute to advise
  • 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