Package: nti.schema
nti.schemanti.schema includes utilities for working with schema-driven
development usingzope.schema.For complete details and the changelog, see thedocumentation.OverviewSome of the most useful features include:nti.schema.interfaces.find_most_derived_interfacefor finding a
bounded interface.nti.schema.eqhash.EqHashis a class-decorator for creating
efficient, correct implementations of equality and hashing.nti.schema.fieldcontains various schema fields, including aVarianttype and more flexible collection types, all of which
produce better validation errors.nti.schema.fieldpropertycontains field properties that can
adapt to interfaces or decode incoming text. The functioncreateDirectFieldPropertiescan assign just the necessary
properties automatically.Changes1.16.0 (2021-05-08)Add support for Python 3.9.Drop support for Python 3.5.Fix deprecation warnings emitted by using this package, and make the
deprecation warnings it emits more precise. Seeissue 58.Fix constructing aVariantto do some extra validation ofIMappingfields to require that both thekey_typeandvalue_typeare given. Previously, if one or both were leftNone, anAttributeErrorwould be raised when the field was
asked to validate data or itsfromObject()method was called.
Now, aRequiredMissingerror will be raised when theVariantis created. Some other nested uses ofDictfields, such as aSequence, could also have raised theAttributeError; this
may change in the future to raise at construction time as well.Seeissue 59.1.15.1 (2020-07-02)Fix plurality of error message for fields with min length of 1.1.15.0 (2020-05-06)Improve the speed ofSchemaConfiguredsubclasses. Seeissue 54.This involves some caching, so be sure to read the documentation fornti.schema.schemaif you ever mutate classes directly, or mutate
the results ofschemadict.1.14.0 (2020-03-27)Require zope.interface 5.0.0 and related dependencies.Ensure all objects have consistent interface resolution orders.Add support for Python 3.8.1.13.1 (2019-06-11)StrippedValidTextLineshould accept single character lines.1.13.0 (2019-05-22)EnsureStrippedValidTextLinecorrectly recognizes single character values
as stripped. Previously, ‘b’ would have been rejected.1.12.0 (2018-10-10)JSON schemas report the schema forIObjectfields
and the schemas for the possible fields inIVariant.Fields in JSON schemas may specify a JSON-serializable dictionary
to be passed as theapplication_infoschema value. Seeissue 44.JSON schemas now output more constraints automatically. Seeissue
47.1.11.0 (2018-10-10)JSON schemas now include nestedvalue_typeandkey_typefor
collection and mapping fields. Seeissue 42.JSON schemas now include (translated)titleanddescriptionvalues for fields. Seeissue 41.1.10.0 (2018-10-04)Addnti.schema.fieldproperty.field_nameto compensate for the
mangling thatFieldPropertyStoredThroughFielddoes.1.9.2 (2018-10-04)FixVariantand other implementations ofIFromObjectto stop
passing known non-text values tofromUnicodemethods. This only
worked with certain fields (such aszope.schema.Number) that
could accept non-text values, usually by implementation accident,
and could have surprising consequences. Instead, non-text values
will be passed to thevalidatemethod.FixVariantto stop double-validating values. The underlyingfromUnicode,fromBytesorfromObjectmethods were
supposed to already validate.1.9.1 (2018-10-03)MakeVariantValidationErrorandVarianthave more useful
string representations.MakefromObjectmethods more gracefully handle an AttributeError
raised by an underlyingfromUnicodemethod on non-string input
(such as None). This is especially helpful forVariantfields
because they can catch the error and continue to the next field.FixVariant,TupleFromObject,DictFromObject,ListFromObjectandListOrTupleFromObjectto allow themissing_value(which defaults toNone) in theirfromObjectmethods; passing that value in simply returns it
without raising an exception if the field is not required. If the
field is required, aRequiredMissingis raised. Previously the
sequences raised aWrongTypeerror, whileVariantmayormay nothave raised an error, depending on the underlying fields
in use.1.9.0 (2018-10-02)Variantobjects now automatically addfromObjectsupport toICollectionandIMappingfields that do not already provide
it, if theirvalue_type(andkey_type) qualify by being
either anObjectfield, or something that providesIFromObjector can be made to, such as a collection or mapping.1.8.0 (2018-09-28)AddVariantValidationError, an error raised by variant fields
when none of their constituent fields could adapt or validate the
value.1.7.0 (2018-09-19)Add support forIFromBytesin zope.schema 4.8.0.TheVariantandListOrTupleFromObject,TupleFromObject,DictFromObjectfields all have tweaked behaviour infromObject. If the incoming value is a bytestring or text
string, the underlying field’sfromBytesandfromUnicodewill be called in preference to afromObject, if that method is
implemented.ValidSetandUniqueIterablenow implementfromObject.All fields that implementfromObjectnow accept anObjectfield for theirvalue_type(andkey_typein the case ofDictFromObject) and will attempt to adapt objects that do not
provide the schema infromObject.1.6.0 (2018-09-18)Adjust the deprecatedzope.schema.interfaces.InvalidValueto be
a simple alias forzope.schema.interfaces.InvalidValue(while
preserving the constructor) for improved backwards compatibility.1.5.0 (2018-09-11)Add support for zope.schema 4.7.0; drop support for older versions.1.4.2 (2018-09-10)Fix thereprofnti.schema.interfaces.InvalidValue. Seeissue 26.nti.schema.jsonschematurns more abstract field types into
concrete types. Seeissue 29.1.4.1 (2018-09-10)Makenti.schema.interfaces.InvalidValuea class again. It is
deprecated. Seeissue 24.1.4.0 (2018-09-10)Drop support fordm.zope.schemafields, in particular theObjectfield. The validation performed byzope.schema.Objectis much improved.Drop support forzope.schemaolder than 4.6.1.Deprecatenti.schema.field.Number.Add support for Python 3.7.1.3.3 (2018-09-07)Minor fix for changes in zope.schema 4.6.0 (importBeforeObjectAssignedEventfrom its new, but still private, location).1.3.2 (2017-10-24)Depend on zope.deferredimport >= 4.2.1 to be able to generate Sphinx
documentation.Clean up code to match PEP8.1.3.1 (2017-10-18)Fix anUnboundLocalErroron Python 3 in theVariantfield.
Seeissue 14.1.3.0 (2017-07-06)Drop the Python 2 dependency onplone.i18nin favor of the new
librarynti.i18n, which supports Python 3. Ifplone.i18nis
installed, itshould notbe configured (ZCML), but its utility
objects can be looked up by either interface.1.2.0 (2017-05-17)Remove use ofunicode_literals.Add support for Python 3.6.TheSchemaConfiguredconstructor doesn’t hide errors when
checking for properties on Python 2. Seeissue 11.1.1.3 (2017-01-17)Add info to minLength validation message.1.1.2 (2016-09-14)AddAcquisitionandzope.eventas install dependencies.
Previously they were only pulled in via thetestextra.1.1.1 (2016-09-08)Substantial speedups to the hash functions generated byEqHash.Substantial speedups to the equality functions generated byEqHash.1.1.0 (2016-07-29)Add support for Python 3.Notethe countries vocabulary will not
be complete on Python 3.Drop thedolmen.builtinsdependency.Drop thedm.zope.schemadependency.Theplone.i18ndependency is Python 2 only (and can even be
removed).The matchers innti.schema.testinghave been moved tonti.testing.matchers.UsingAdaptingFieldPropertywill now raise the more specificSchemaNotProvidederror instead of aTypeErrorif adapting
the value fails.EqHashhas moved fromnti.schema.schematonti.schema.eqhash. A compatibility shim remains.