Package: zope.schema
zope.schemaSchemas extend the notion of interfaces to detailed descriptions of
Attributes (but not methods).  Every schema is an interface and
specifies the public fields of an object.  Afieldroughly
corresponds to an attribute of a Python object.  But a Field provides
space for at least a title and a description.  It can also constrain
its value and provide a validation method.  Besides you can optionally
specify characteristics such as its value being read-only or not
required.Seehttps://zopeschema.readthedocs.io/for more information.Changes7.0.1 (2023-01-02)Fix fallback whenzope.i18nmessageidis not installed (regression
introduced in 7.0.0).7.0.0 (2023-01-01)Add support for Python 3.11.Drop support for Python 2.7, 3.5, 3.6.Dropzope.schema._compatmodule.Fix test deprecation warning on Python 3.11.
(#112)6.2.1 (2022-09-14)Fix outsized integer test values that break tests on newer Python versions.
(#115)6.2.0 (2021-10-18)Add support for Python 3.10.6.1.1 (2021-10-13)Fix incompatibility introduced in 6.1.0:
TheBoolfield constructor implicitly set required to False if not given.
While this is the desired behavior in most common cases,
it broke special cases.
Seeissue 104(scroll down, it is around thereopen).6.1.0 (2021-02-09)FixIField.requiredto not be required by default.
Seeissue 104.6.0.1 (2021-01-25)Bring branch coverage to 100%.Add support for Python 3.9.Fix FieldUpdateEvent implementation by having anobjectattribute as theIFieldUpdatedEventinterfaces claims there should be.6.0.0 (2020-03-21)Require zope.interface 5.0.Ensure the resolution orders of all fields are consistent and make
sense. In particular,Boolfields now correctly implementIBoolbeforeIFromUnicode. Seeissue 80.Add support for Python 3.8.Drop support for Python 3.4.5.0.1 (2020-03-06)Fix: addText.unicode_normalization = 'NFC'as default, because some are
persisting schema fields. Setting that attribute only in__init__breaks loading old objects.5.0 (2020-03-06)SetIDecimalattributesmin,maxanddefaultasDecimaltype instead ofNumber.
Seeissue 88.Enable unicode normalization forTextfields.
The default is NFC normalization. Valid forms are ‘NFC’, ‘NFKC’, ‘NFD’, and
‘NFKD’. To disable normalization, setunicode_normalizationtoFalseorNonewhen calling__init__of theTextfield.
Seeissue 86.4.9.3 (2018-10-12)Fix a ReST error in getDoc() results when having “subfields”
with titles.4.9.2 (2018-10-11)Make sure that the title forIObject.validate_invariantsis a unicode
string.4.9.1 (2018-10-05)FixSimpleTermtoken for non-ASCII bytes values.4.9.0 (2018-09-24)MakeNativeStringandNativeStringLinedistinct types that
implement the newly-distinct interfacesINativeStringandINativeStringLine. Previously these were just aliases for eitherText(on Python 3) orBytes(on Python 2).FixField.getDoc()whenvalue_typeorkey_typeis
present. Previously it could produce ReST that generated Sphinx
warnings. Seeissue 76.MakeDottedNameaccept leading underscores for each segment.AddPythonIdentifier, which accepts one segment of a dotted
name, e.g., a python variable or class.4.8.0 (2018-09-19)Add the interfaceIFromBytes, which is implemented by the
numeric and bytes fields, as well asURI,DottedName, andId.Fix passingNoneas the description to a field constructor. Seeissue 69.4.7.0 (2018-09-11)MakeWrongTypehave anexpected_typefield.AddNotAnInterface, an exception derived fromWrongTypeandSchemaNotProvidedand raised by the constructor ofObjectand when validation fails forInterfaceField.GiveSchemaNotProvidedaschemafield.GiveWrongContainedTypeanerrorslist.GiveTooShort,TooLong,TooBigandTooSmallaboundfield and the common superclassesLenOutOfBounds,OrderableOutOfBounds, respectively, both of which inherit fromOutOfBounds.4.6.2 (2018-09-10)Fix checking a field’s constraint to set thefieldandvalueproperties if the constraint raises aValidationError. Seeissue 66.4.6.1 (2018-09-10)Fix theFieldconstructor to again allowMessageIDvalues
for thedescription. This was a regression introduced with the
fix forissue 60. Seeissue 63.4.6.0 (2018-09-07)Add support for Python 3.7.Objectinstances call their schema’svalidateInvariantsmethod by default to collect errors from functions decorated with@invariantwhen validating. This can be disabled by passingvalidate_invariants=Falseto theObjectconstructor. Seeissue 10.ValidationErrorcan be sorted on Python 3.DottedNameandIdconsistently handle non-ASCII unicode
values on Python 2 and 3 by raisingInvalidDottedNameandInvalidIdinfromUnicoderespectively. Previously, aUnicodeEncodeErrorwould be raised on Python 2 while Python 3
would raise the descriptive exception.Fieldinstances are hashable on Python 3, and use a defined
hashing algorithm that matches what equality does on all versions of
Python. Previously, on Python 2, fields were hashed based on their
identity. This violated the rule that equal objects should have
equal hashes, and now they do. Since having equal hashes does not
imply that the objects are equal, this is not expected to be a
compatibility problem. Seeissue 36.Fieldinstances are only equal when their.interfaceis
equal. In practice, this means that two otherwise identical fields
of separate schemas are not equal, do not hash the same, and can
both be members of the samedictorset. Prior to this
release, when hashing was identity based but only worked on Python
2, that was the typical behaviour. (Field objects that arenotmembers of a schema continue to compare and hash equal if they have
the same attributes and interfaces.) Seeissue 40.Orderable fields, includingInt,Float,Decimal,Timedelta,DateandTime, can now have amissing_valuewithout needing to specify concreteminandmaxvalues (they must still specify adefaultvalue). Seeissue 9.Choice,SimpleVocabularyandSimpleTermall gracefully
handle using Unicode token values with non-ASCII characters by encoding
them with thebackslashreplaceerror handler. Seeissue 15andPR
6.All instances ofValidationErrorhave afieldandvalueattribute that is set to the field that raised the exception and the
value that failed validation.Float,IntandDecimalfields raiseValidationErrorsubclasses for literals that cannot be parsed. These subclasses also
subclassValueErrorfor backwards compatibility.Add a new exceptionSchemaNotCorrectlyImplemented, a subclass ofWrongContainedTypethat is raised by theObjectfield. It
has a dictionary (schema_errors) mapping invalid schema
attributes to their corresponding exception, and a list
(invariant_errors) containing the exceptions raised by
validating invariants. Seeissue 16.Add new fieldsMappingandMutableMapping, corresponding to
the collections ABCs of the same name;Dictnow extends and
specializesMutableMappingto only accept instances ofdict.Add new fieldsSequenceandMutableSequence, corresponding
to the collections ABCs of the same name;Tuplenow extendsSequenceandListnow extendsMutableSequence.Add new fieldCollection, implementingICollection. This is
the base class ofSequence. Previously this was known asAbstractCollectionand was not public. It can be subclassed to
addvalue_type,_typeanduniqueattributes at the class
level, enabling a simpler constructor call. Seeissue 23.MakeObjectrespect aschemaattribute defined by a
subclass, enabling a simpler constructor call. Seeissue 23.Add fields and interfaces representing Python’s numeric tower. In
descending order of generality these areNumber,Complex,Real,RationalandIntegral. TheIntclass extendsIntegral, theFloatclass extendsReal, and theDecimalclass extendsNumber. Seeissue 49.MakeIterableandContainerproperly implementIIterableandIContainer, respectively.MakeSimpleVocabulary.fromItemsaccept triples to allow
specifying the title of terms. Seeissue 18.MakeTreeVocabulary.fromDictonly createITitledTokenizedTermswhen a title is actually provided.MakeChoicefields reliably raise aValidationErrorwhen a
named vocabulary cannot be found; for backwards compatibility this
is also aValueError. Previously this only worked when the
defaultVocabularyRegistrywas in use, not when it was replaced
withzope.vocabularyregistry. Seeissue 55.MakeSimpleVocabularyandSimpleTermhave value-based
equality and hashing methods.All fields of the schema of anObjectfield are bound to the
top-level value being validated before attempting validation of
their particular attribute. Previously onlyIChoicefields were
bound. Seeissue 17.Share the internal logic ofObjectfield validation andzope.schema.getValidationErrors. Seeissue 57.MakeField.getDoc()return more information about the properties
of the field, such as its required and readonly status. Subclasses
can add more information using the new methodField.getExtraDocLines(). This is used to generate Sphinx
documentation when usingrepoze.sphinx.autointerface. Seeissue 60.4.5.0 (2017-07-10)Drop support for Python 2.6, 3.2, and 3.3.Add support for Python 3.5 and 3.6.Drop support for ‘setup.py test’. Use zope.testrunner instead.4.4.2 (2014-09-04)Fix description of min max field: max value is included, not excluded.4.4.1 (2014-03-19)Add support for Python 3.4.4.4.0 (2014-01-22)Add an event on field properties to notify that a field has been updated.
This event enables definition of subscribers based on an event, a context
and a field. The event contains also the old value and the new value.
(also see packagezope.schemaeventthat define a field event handler)4.3.3 (2014-01-06)PEP 8 cleanup.Don’t raise RequiredMissing if a field’s defaultFactory returns the field’s
missing_value.Updateboostrap.pyto version 2.2.Add the ability to swallow ValueErrors when rendering a SimpleVocabulary,
allowing for cases where vocabulary items may be duplicated (e.g., due to
user input).Include the field name inConstraintNotSatisfied.4.3.2 (2013-02-24)Fix Python 2.6 support. (Forgot to run tox with all environments before last
release.)4.3.1 (2013-02-24)Make sure that we do not fail during bytes decoding of term token when
generated from a bytes value by ignoring all errors. (Another option would
have been to hexlify the value, but that would break way too many tests.)4.3.0 (2013-02-24)Fix a bug where bytes values were turned into tokens inproperly in
Python 3.Addzope.schema.fieldproperty.createFieldProperties()function which
maps schema fields intoFieldPropertyinstances.4.2.2 (2012-11-21)Add support for Python 3.3.4.2.1 (2012-11-09)Fix the default property of fields that have no defaultFactory attribute.4.2.0 (2012-05-12)Automate build of Sphinx HTML docs and running doctest snippets via tox.Drop explicit support for Python 3.1.Introduce NativeString and NativeStringLine which are equal to Bytes and
BytesLine on Python 2 and Text and TextLine on Python 3.Change IURI from a Bytes string to a “native” string. This is a backwards
incompatibility which only affects Python 3.Bring unit test coverage to 100%.Move doctests from the package and wired up as normal Sphinx documentation.Add explicit support for PyPy.Add support for continuous integration usingtoxandjenkins.Drop the externalsixdependency in favor of a much-trimmedzope.schema._compatmodule.Ensure tests pass when run undernose.Addsetup.py devalias (runssetup.py developplus installsnoseandcoverage).Addsetup.py docsalias (installsSphinxand dependencies).4.1.1 (2012-03-23)Remove trailing slash in MANIFEST.in, it causes Winbot to crash.4.1.0 (2012-03-23)Add TreeVocabulary for nested tree-like vocabularies.Fix broken Object field validation where the schema contains a Choice with
ICountextSourceBinder source. In this case the vocabulary was not iterable
because the field was not bound and the source binder didn’t return the
real vocabulary. Added simple test for IContextSourceBinder validation. But a
test with an Object field with a schema using a Choice with
IContextSourceBinder is still missing.4.0.1 (2011-11-14)Fix bug infromUnicodemethod ofDottedNamewhich would fail
validation on being given unicode. Introduced in 4.0.0.4.0.0 (2011-11-09)Fix deprecated unittest methods.Port to Python 3. This adds a dependency on six and removes support for
Python 2.5.3.8.1 (2011-09-23)Fix broken Object field validation. Previous version was using a volatile
property on object field values which ends in a ForbiddenAttribute error
on security proxied objects.3.8.0 (2011-03-18)Implement adefaultFactoryattribute for all fields. It is a callable
that can be used to compute default values. The simplest case is:Date(defaultFactory=datetime.date.today)If the factory needs a context to compute a sensible default value, then it
must provideIContextAwareDefaultFactory, which can be used as follows:@provider(IContextAwareDefaultFactory)
def today(context):
    return context.today()

Date(defaultFactory=today)3.7.1 (2010-12-25)Rename the validation token, used in the validation of schema with Object
Field to avoid infinite recursion:__schema_being_validatedbecame_v_schema_being_validated,
a volatile attribute, to avoid persistency and therefore,
read/write conflicts.Don’t allow “[]^`” in DottedName.https://bugs.launchpad.net/zope.schema/+bug/1912363.7.0 (2010-09-12)Improve error messages when term tokens or values are duplicates.Fix the buildout so the tests run.3.6.4 (2010-06-08)fix validation of schema with Object Field that specify Interface schema.3.6.3 (2010-04-30)Prefer the standard libraries doctest module to the one from zope.testing.3.6.2 (2010-04-30)Avoid maximum recursion when validating Object field that points to cyclesMake the dependency onzope.i18nmessageidoptional.3.6.1 (2010-01-05)Allow “setup.py test” to run at least a subset of the tests runnable
viabin/test(227 forsetup.py testvs. 258. forbin/test)Makezope.schema._bootstrapfields.ValidatedPropertydescriptor
work under Jython.Make “setup.py test” tests pass on Jython.3.6.0 (2009-12-22)Prefer zope.testing.doctest over doctestunit.Extend validation error to hold the field name.Add FieldProperty class that uses Field.get and Field.set methods
instead of storing directly on the instance __dict__.3.5.4 (2009-03-25)Don’t fail trying to validate default value for Choice fields with
IContextSourceBinder object given as a source. Seehttps://bugs.launchpad.net/zope3/+bug/340416.Add an interface forDottedNamefield.AddvocabularyNameattribute to theIChoiceinterface, change
“vocabulary” attribute description to be more sensible, making itzope.schema.Fieldinstead of plainzope.interface.Attribute.Make IBool interface of Bool more important than IFromUnicode so adapters
registered for IBool take precendence over adapters registered for
IFromUnicode.3.5.3 (2009-03-10)Make Choice and Bool fields implement IFromUnicode interface, because
they do provide thefromUnicodemethod.Change package’s mailing list address to zope-dev at zope.org, as
zope3-dev at zope.org is now retired.Fix package’s documentation formatting. Change package’s description.Add buildout part that builds Sphinx-generated documentation.Remove zpkg-related file.3.5.2 (2009-02-04)Made validation tests compatible with Python 2.5 again (hopefully not
breaking Python 2.4)Add an __all__ package attribute to expose documentation.3.5.1 (2009-01-31)Stop using the old old set type.Make tests compatible and silent with Python 2.4.Fix __cmp__ method in ValidationError. Show some side effects based on the
existing __cmp__ implementation. See validation.txtMake ‘repr’ of the ValidationError and its subclasses more sensible. This
may require you to adapt your doctests for the new style, but now it makes
much more sense for debugging for developers.3.5.0a2 (2008-12-11)Move zope.testing to “test” extras_require, as it is not needed
for zope.schema itself.Change the order of classes in SET_TYPES tuple, introduced in
previous release to one that was in 3.4 (SetType, set), because
third-party code could be dependent on that order. The one
example is z3c.form’s converter.3.5.0a1 (2008-10-10)Add the doctests to the long description.Remove use of deprecated ‘sets’ module when running under Python 2.6.Remove spurious doctest failure when running under Python 2.6.Add support to bootstrap on Jython.Add helper methods for schema validation:getValidationErrorsandgetSchemaValidationErrors.zope.schema now works on Python2.53.4.0 (2007-09-28)Add BeforeObjectAssignedEvent that is triggered before the object
field sets a value.3.3.0 (2007-03-15)Corresponds to the version of the zope.schema package shipped as part of
the Zope 3.3.0 release.3.2.1 (2006-03-26)Corresponds to the version of the zope.schema package shipped as part of
the Zope 3.2.1 release.Fix missing import of ‘VocabularyRegistryError’.  Seehttp://www.zope.org/Collectors/Zope3-dev/544.3.2.0 (2006-01-05)Corresponds to the version of the zope.schema package shipped as part of
the Zope 3.2.0 release.Add “iterable” sources to replace vocabularies, which are now deprecated
and scheduled for removal in Zope 3.3.3.1.0 (2005-10-03)Corresponds to the version of the zope.schema package shipped as part of
the Zope 3.1.0 release.Allow ‘Choice’ fields to take either a ‘vocabulary’ or a ‘source’
argument (sources are a simpler implementation).Add ‘TimeDelta’ and ‘ASCIILine’ field types.3.0.0 (2004-11-07)Corresponds to the version of the zope.schema package shipped as part of
the Zope X3.0.0 release.