pytilities.aop.aspect — Pytilities v1.0.0 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Pytilities v1.0.0 documentation »
- API documentation »
- pytilities »
- pytilities.aop »

# pytilities.aop.aspect

class `pytilities.aop.aspect.` `Aspect`

  Handy base class for aspects.

  You don’t have to use this base class for your aspects, but you’ll probably find it helpful to do so.

  Aspects should adhere to this interface.

  Aspects can be applied at most once to the same object.

  `__init__`()

    Create the aspect

  `_advise`()

    Add advice to give.

    The order in which advise is given is important. Last added advise is called first. Put differently, added advise wraps previous advise of given members.

    A special member of ‘*’ is allowed as well for advising classes with metaclass=AOPMeta. This applies the advice to any member of obj. This advice preceeds other advice (though instance * advice is still preceded by any class advice).

    - advice precedes all other advice.

    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

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

  `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)

    Get iter of 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
    Returns: | advice funcs, the left is the first advice to give (i.e. the last advice given; the most outer advice)
    Return type: | iter([advice, generator]...)

  `is_applied`(obj)

    Get if this aspect is currently applied to an object.

    Parameters: | obj (class, instance or module) – the object to advise
    Returns: | True if advice is currently applied to 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 or module) – the object to advise
    Returns: | True if advice is currently enabled for obj, False otherwise

  `unapply`(obj)

    Unapply the advice to the object

    If advice wasn’t applied, do nothing

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

  `__weakref__`

    list of weak references to the object (if defined)

### Navigation

- index
- modules |
- next |
- previous |
- Pytilities v1.0.0 documentation »
- API documentation »
- pytilities »
- pytilities.aop »