owmeta_core.contextualize module¶
- class owmeta_core.contextualize.AbstractBaseContextualizable[source]¶
Bases:
ABCAbstract base class for contextualizables
Any class with an attribute
contextualizewith a Function value is recognized as a subclass
- class owmeta_core.contextualize.BaseContextualizable(*args, **kwargs)[source]¶
Bases:
objectHelper 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
- context
Context The context of the object
- contextualization
object The contextualized version of the object
- context
- contextualize(context)[source]¶
Return an object with the given context. If the provided
contextisNone, thenselfMUST be returned unmodified. Prefer to overridecontextualize_agumentwhich 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
contextargument.
- class owmeta_core.contextualize.Contextualizable(*args, **kwargs)[source]¶
Bases:
BaseContextualizableA
BaseContextualizablewith 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:
typeA super-type for contextualizable classes
- Attributes
- context_carries
tupleofstr 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
propertyand 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 declaringcontext_carrieswith the names of attributes that should be carried through a contextualization.
- context_carries