nti.schema.schema¶
Helpers for writing code that implements schemas.
This module contains code based on code originally from dm.zope.schema.
-
class
PermissiveSchemaConfigured
(**kwargs)[source]¶ Bases:
nti.schema.schema.SchemaConfigured
A mixin subclass of
SchemaConfigured
that allows for extra keywords (those not defined in the schema) to silently be ignored. This is an aid to evolution of code and can be helpful in testing.To allow for one-by-one conversions and updates, this class defines an attribute
SC_PERMISSIVE
, defaulting to True, that controls this behaviour.-
SC_PERMISSIVE
= True¶
-
-
class
SchemaConfigured
(**kw)[source]¶ Bases:
object
Mixin class to provide configuration by the provided schema components.
This class is fastest if most of the attributes are represented by
FieldProperty
objects.Changed in version 1.15: Special case
FieldProperty
instances found in the type when checking whether a value has been provided. We now assume that if there is no matching item in the dict with the same name, no value was provided. Note that if the schema field contained in theFieldProperty
did something funky in itsbind()
method to this object, that will no longer happen at construction time. This can be turned of by settingSC_OPTIMIZE_FIELD_PROPERTY
to false.If you add a FieldProperty to a
SchemaConfigured
class after an instance has been created, you must callsc_changed
.-
SC_OPTIMIZE_FIELD_PROPERTY
= True¶
-
SC_SCHEMAS
= None¶
-
classmethod
sc_changed
(orig_changed=None)[source]¶ Call this method if you assign a fieldproperty to this class after creation.
-
sc_schema_spec
()[source]¶ the schema specification which determines the data schema.
This is determined by
SC_SCHEMAS
and defaults toprovidedBy(self)
.
-
-
schemadict
(spec) → dict[source]¶ The schema part (fields) of interface specification spec as map from name to field.
The return value must be treated as immutable.
spec can be:
- A single Interface;
- An object implementing
zope.interfaces.interfaces.ISpecification
, such as that returned byprovidedBy(instance)
orimplementedBy(factory)
(an Interface is a special case of this). - A list, tuple, or iterable of Interfaces.
In the first two cases, the results will be cached using the usual interface caching rules. That means that changes to interface bases, or changes to what an object or class provides or implements, will be properly detected. However, if you simply assign a new field to an existing interface, it may not be detected (things like
Interface.get()
also fail in that case) unless you callInterface.changed()
.Changed in version 1.15.0: Added caching and re-implemented the schemadict algorithm for speed. The return value must now be treated as immutable.