owmeta_core.contextualize module

class owmeta_core.contextualize.AbstractBaseContextualizable[source]

Bases: ABC

Abstract base class for contextualizables

Any class with an attribute contextualize with a Function value is recognized as a subclass

class owmeta_core.contextualize.BaseContextualizable(*args, **kwargs)[source]

Bases: object

Helper base-class for contextualizable objects. Caches contextualized objects returned from contextualize_augment

add_contextualization(context, contextualization)[source]

Manually add a contextualized object to the cache

Parameters
contextContext

The context of the object

contextualizationobject

The contextualized version of the object

contextualize(context)[source]

Return an object with the given context. If the provided context is None, then self MUST be returned unmodified. Prefer to override contextualize_agument which will be called from this method.

It is generally not correct to set a field on the object and return the same object as this would change the context for other users of the object. Also, returning a copy of the object is usually inappropriate for mutable objects. Immutable objects may maintain a ‘context’ property and return a copy of themselves with that property set to the provided context argument.

contextualize_augment(context)[source]

For sub-classes to override: Return an object with the given context. If the provided context is None, then self MUST be returned unmodified.

Returns
object

the contextualized object

decontextualize()[source]

Return the object with all contexts removed. Sub-classes should override.

class owmeta_core.contextualize.Contextualizable(*args, **kwargs)[source]

Bases: BaseContextualizable

A BaseContextualizable with the addition of a default behavior of setting the context from the class’s ‘context’ attribute. This generally requires that for the metaclass of the Contextualizable that a ‘context’ data property is defined. For example:

>>> class AMeta(ContextualizableClass):
...     @property
...     def context(self):
...         return self.__context
...
...     @context.setter
...     def context(self, ctx):
...         self.__context = ctx

>>> class A(six.with_metaclass(Contextualizable)):
...     pass
class owmeta_core.contextualize.ContextualizableClass(name, typ, dct)[source]

Bases: type

A super-type for contextualizable classes

Attributes
context_carriestuple of str

When defining a specialized contextualizable class, you may want to define some attribute on the class that is only set if it’s declared directly in the class body (e.g., by using property and name mangling). However, by default, contextualization creates a subclass and you may want your property to be “carried” into the new context. You can achieve this by declaring context_carries with the names of attributes that should be carried through a contextualization.

owmeta_core.contextualize.contextualize_helper(context, obj, noneok=False)[source]

Does some extra stuff to make access to the type of a ContextualizingProxy work more-or-less like access to the the wrapped object

owmeta_core.contextualize.decontextualize_helper(obj)[source]

Removes contexts from a ContextualizingProxy