API¶
This document describes the low-level API of the interfaces and classes provided by this package. The narrative documentation is a better guide to the intended usage.
Interfaces¶
- interface zope.schema.interfaces.IField[source]¶
Extends:
zope.schema._bootstrapinterfaces.IValidatable
Basic Schema Field Interface.
Fields are used for Interface specifications. They at least provide a title, description and a default value. You can also specify if they are required and/or readonly.
The Field Interface is also used for validation and specifying constraints.
We want to make it possible for a IField to not only work on its value but also on the object this value is bound to. This enables a Field implementation to perform validation against an object which also marks a certain place.
Note that many fields need information about the object containing a field. For example, when validating a value to be set as an object attribute, it may be necessary for the field to introspect the object’s state. This means that the field needs to have access to the object when performing validation:
bound = field.bind(object) bound.validate(value)
- interface zope.schema.interfaces.IChoice[source]¶
Extends:
zope.schema.interfaces.IField
Field whose value is contained in a predefined set
Only one, values or vocabulary, may be specified for a given choice.
- interface zope.schema.interfaces.IContextAwareDefaultFactory[source]¶
A default factory that requires a context.
The context is the field context. If the field is not bound, context may be
None
.
- interface zope.schema.interfaces.IOrderable[source]¶
Extends:
zope.schema.interfaces.IField
Field requiring its value to be orderable.
The set of value needs support a complete ordering; the implementation mechanism is not constrained. Either
__cmp__()
or ‘rich comparison’ methods may be used.
- interface zope.schema.interfaces.ILen[source]¶
Extends:
zope.schema.interfaces.IField
A Field requiring its value to have a length.
The value needs to have a conventional __len__ method.
- interface zope.schema.interfaces.IMinMax[source]¶
Extends:
zope.schema.interfaces.IOrderable
Field requiring its value to be between min and max.
This implies that the value needs to support the IOrderable interface.
- interface zope.schema.interfaces.IMinMaxLen[source]¶
Extends:
zope.schema.interfaces.ILen
Field requiring the length of its value to be within a range
- interface zope.schema.interfaces.IInterfaceField[source]¶
Extends:
zope.schema.interfaces.IField
Fields with a value that is an interface (implementing zope.interface.Interface).
- interface zope.schema.interfaces.IBool[source]¶
Extends:
zope.schema.interfaces.IField
Boolean Field.
- interface zope.schema.interfaces.IObject[source]¶
Extends:
zope.schema.interfaces.IField
Field containing an Object value.
Changed in version 4.6.0: Add the validate_invariants attribute.
Conversions¶
Strings¶
- interface zope.schema.interfaces.IBytes[source]¶
Extends:
zope.schema.interfaces.IMinMaxLen
,zope.schema.interfaces.IIterable
,zope.schema.interfaces.IField
Field containing a byte string (like the python str).
The value might be constrained to be with length limits.
- interface zope.schema.interfaces.IBytesLine[source]¶
Extends:
zope.schema.interfaces.IBytes
Field containing a byte string without newlines.
- interface zope.schema.interfaces.IText[source]¶
Extends:
zope.schema.interfaces.IMinMaxLen
,zope.schema.interfaces.IIterable
,zope.schema.interfaces.IField
Field containing a unicode string.
- interface zope.schema.interfaces.ITextLine[source]¶
Extends:
zope.schema.interfaces.IText
Field containing a unicode string without newlines.
- interface zope.schema.interfaces.IASCII[source]¶
Extends:
zope.schema.interfaces.INativeString
Field containing a 7-bit ASCII string. No characters > DEL (chr(127)) are allowed
The value might be constrained to be with length limits.
- interface zope.schema.interfaces.IASCIILine[source]¶
Extends:
zope.schema.interfaces.IASCII
Field containing a 7-bit ASCII string without newlines.
- interface zope.schema.interfaces.INativeString[source]¶
Extends:
zope.schema.interfaces.IText
A field that always contains the native
str
type.
- interface zope.schema.interfaces.INativeStringLine[source]¶
Extends:
zope.schema.interfaces.ITextLine
A field that always contains the native
str
type, without any newlines.Changed in version 4.9.0: This is now a distinct type instead of an alias for either
ITextLine
orIBytesLine
, depending on the platform.
- interface zope.schema.interfaces.IPassword[source]¶
Extends:
zope.schema.interfaces.ITextLine
Field containing a unicode password string without newlines.
- interface zope.schema.interfaces.IURI[source]¶
Extends:
zope.schema.interfaces.INativeStringLine
A field containing an absolute URI
- interface zope.schema.interfaces.IId[source]¶
Extends:
zope.schema.interfaces.INativeStringLine
A field containing a unique identifier
A unique identifier is either an absolute URI or a dotted name. If it’s a dotted name, it should have a module/package name as a prefix.
- interface zope.schema.interfaces.IPythonIdentifier[source]¶
Extends:
zope.schema.interfaces.INativeStringLine
A single Python identifier, such as a variable name.
New in version 4.9.0.
- interface zope.schema.interfaces.IDottedName[source]¶
Extends:
zope.schema.interfaces.INativeStringLine
Dotted name field.
Values of DottedName fields must be Python-style dotted names.
Numbers¶
- interface zope.schema.interfaces.INumber[source]¶
Extends:
zope.schema.interfaces.IMinMax
,zope.schema.interfaces.IField
Field containing a generic number:
numbers.Number
.See also
New in version 4.6.0.
- interface zope.schema.interfaces.IComplex[source]¶
Extends:
zope.schema.interfaces.INumber
Field containing a complex number:
numbers.Complex
.See also
New in version 4.6.0.
- interface zope.schema.interfaces.IReal[source]¶
Extends:
zope.schema.interfaces.IComplex
Field containing a real number:
numbers.IReal
.See also
New in version 4.6.0.
- interface zope.schema.interfaces.IRational[source]¶
Extends:
zope.schema.interfaces.IReal
Field containing a rational number:
numbers.IRational
.See also
New in version 4.6.0.
- interface zope.schema.interfaces.IIntegral[source]¶
Extends:
zope.schema.interfaces.IRational
Field containing an integral number: class:
numbers.Integral
.See also
New in version 4.6.0.
- interface zope.schema.interfaces.IInt[source]¶
Extends:
zope.schema.interfaces.IIntegral
Field containing exactly the native class
int
.See also
- interface zope.schema.interfaces.IFloat[source]¶
Extends:
zope.schema.interfaces.IReal
Field containing exactly the native class
float
.IReal
is a more general interface, allowing all of floats, ints, and fractions.See also
- interface zope.schema.interfaces.IDecimal[source]¶
Extends:
zope.schema.interfaces.INumber
Field containing a
decimal.Decimal
Date/Time¶
- interface zope.schema.interfaces.IDatetime[source]¶
Extends:
zope.schema.interfaces.IMinMax
,zope.schema.interfaces.IField
Field containing a datetime.
- interface zope.schema.interfaces.IDate[source]¶
Extends:
zope.schema.interfaces.IMinMax
,zope.schema.interfaces.IField
Field containing a date.
- interface zope.schema.interfaces.ITimedelta[source]¶
Extends:
zope.schema.interfaces.IMinMax
,zope.schema.interfaces.IField
Field containing a timedelta.
- interface zope.schema.interfaces.ITime[source]¶
Extends:
zope.schema.interfaces.IMinMax
,zope.schema.interfaces.IField
Field containing a time.
Collections¶
- interface zope.schema.interfaces.IIterable[source]¶
Extends:
zope.schema.interfaces.IField
Fields with a value that can be iterated over.
The value needs to support iteration; the implementation mechanism is not constrained. (Either
__iter__()
or__getitem__()
may be used.)
- interface zope.schema.interfaces.IContainer[source]¶
Extends:
zope.schema.interfaces.IField
Fields whose value allows an
x in value
check.The value needs to support the
in
operator, but is not constrained in how it does so (whether it defines__contains__()
or__getitem__()
is immaterial).
- interface zope.schema.interfaces.ICollection[source]¶
Extends:
zope.schema.interfaces.IMinMaxLen
,zope.schema.interfaces.IIterable
,zope.schema.interfaces.IContainer
Abstract interface containing a collection value.
The Value must be iterable and may have a min_length/max_length.
- interface zope.schema.interfaces.ISequence[source]¶
Extends:
zope.schema.interfaces.ICollection
Abstract interface specifying that the value is ordered
- interface zope.schema.interfaces.IMutableSequence[source]¶
Extends:
zope.schema.interfaces.ISequence
Abstract interface specifying that the value is ordered and mutable.
New in version 4.6.0.
- interface zope.schema.interfaces.IUnorderedCollection[source]¶
Extends:
zope.schema.interfaces.ICollection
Abstract interface specifying that the value cannot be ordered
- interface zope.schema.interfaces.IAbstractSet[source]¶
Extends:
zope.schema.interfaces.IUnorderedCollection
An unordered collection of unique values.
- interface zope.schema.interfaces.IAbstractBag[source]¶
Extends:
zope.schema.interfaces.IUnorderedCollection
An unordered collection of values, with no limitations on whether members are unique
- interface zope.schema.interfaces.ITuple[source]¶
Extends:
zope.schema.interfaces.ISequence
Field containing a value that implements the API of a conventional Python tuple.
- interface zope.schema.interfaces.IList[source]¶
Extends:
zope.schema.interfaces.IMutableSequence
Field containing a value that implements the API of a conventional Python list.
- interface zope.schema.interfaces.ISet[source]¶
Extends:
zope.schema.interfaces.IAbstractSet
Field containing a value that implements the API of a Python2.4+ set.
- interface zope.schema.interfaces.IFrozenSet[source]¶
Extends:
zope.schema.interfaces.IAbstractSet
Field containing a value that implements the API of a conventional Python 2.4+ frozenset.
Mappings¶
- interface zope.schema.interfaces.IMapping[source]¶
Extends:
zope.schema.interfaces.IMinMaxLen
,zope.schema.interfaces.IIterable
,zope.schema.interfaces.IContainer
Field containing an instance of
collections.Mapping
.The key_type and value_type fields allow specification of restrictions for keys and values contained in the dict.
- interface zope.schema.interfaces.IMutableMapping[source]¶
Extends:
zope.schema.interfaces.IMapping
Field containing an instance of
collections.MutableMapping
.
- interface zope.schema.interfaces.IDict[source]¶
Extends:
zope.schema.interfaces.IMutableMapping
Field containing a conventional dict.
Events¶
- interface zope.schema.interfaces.IBeforeObjectAssignedEvent[source]¶
An object is going to be assigned to an attribute on another object.
Subscribers to this event can change the object on this event to change what object is going to be assigned. This is useful, e.g. for wrapping or replacing objects before they get assigned to conform to application policy.
- interface zope.schema.interfaces.IFieldUpdatedEvent[source]¶
Extends:
zope.schema.interfaces.IFieldEvent
A field has been modified
Subscribers will get the old and the new value together with the field
Vocabularies¶
- interface zope.schema.interfaces.ITokenizedTerm[source]¶
Extends:
zope.schema.interfaces.ITerm
Object representing a single value in a tokenized vocabulary.
- interface zope.schema.interfaces.ITitledTokenizedTerm[source]¶
Extends:
zope.schema.interfaces.ITokenizedTerm
A tokenized term that includes a title.
- interface zope.schema.interfaces.ISource[source]¶
A set of values from which to choose
Sources represent sets of values. They are used to specify the source for choice fields.
Sources can be large (even infinite), in which case, they need to be queried to find out what their values are.
- interface zope.schema.interfaces.ISourceQueriables[source]¶
A collection of objects for querying sources
- interface zope.schema.interfaces.IBaseVocabulary[source]¶
Extends:
zope.schema.interfaces.ISource
Representation of a vocabulary.
At this most basic level, a vocabulary only need to support a test for containment. This can be implemented either by __contains__() or by sequence __getitem__() (the later only being useful for vocabularies which are intrinsically ordered).
- interface zope.schema.interfaces.IIterableVocabulary[source]¶
Vocabulary which supports iteration over allowed values.
The objects iteration provides must conform to the ITerm interface.
- interface zope.schema.interfaces.IIterableSource[source]¶
Extends:
zope.schema.interfaces.ISource
Source which supports iteration over allowed values.
The objects iteration provides must be values from the source.
- interface zope.schema.interfaces.IVocabulary[source]¶
Extends:
zope.schema.interfaces.IIterableVocabulary
,zope.schema.interfaces.IBaseVocabulary
Vocabulary which is iterable.
- interface zope.schema.interfaces.IVocabularyTokenized[source]¶
Extends:
zope.schema.interfaces.IVocabulary
Vocabulary that provides support for tokenized representation.
Terms returned from getTerm() and provided by iteration must conform to ITokenizedTerm.
- interface zope.schema.interfaces.ITreeVocabulary[source]¶
Extends:
zope.schema.interfaces.IVocabularyTokenized
,zope.interface.common.mapping.IEnumerableMapping
A tokenized vocabulary with a tree-like structure.
The tree is implemented as dictionary, with keys being ITokenizedTerm terms and the values being similar dictionaries. Leaf values are empty dictionaries.
- interface zope.schema.interfaces.IVocabularyRegistry[source]¶
Registry that provides
IBaseVocabulary
objects for specific fields.The fields of this package use the vocabulary registry that is returned from
getVocabularyRegistry()
. This is a hook function; by default it returns an instance ofVocabularyRegistry
, but the functionsetVocabularyRegistry()
can be used to change this.In particular, the package zope.vocabularyregistry can be used to install a vocabulary registry that uses the
zope.component
architecture.
- interface zope.schema.interfaces.IVocabularyFactory[source]¶
An object that can create
IBaseVocabulary
.Objects that implement this interface can be registered with the default
VocabularyRegistry
provided by this package.Alternatively, zope.vocabularyregistry can be used to install a
IVocabularyRegistry
that looks for named utilities usingzope.component.getUtility()
which provide this interface.
Exceptions¶
- exception zope.schema._bootstrapinterfaces.ValidationError[source]¶
Raised if the Validation process fails.
- exception zope.schema.ValidationError¶
The preferred alias for
zope.schema._bootstrapinterfaces.ValidationError
.
- exception zope.schema.interfaces.StopValidation[source]¶
Raised if the validation is completed early.
Note that this exception should be always caught, since it is just a way for the validator to save time.
- exception zope.schema.interfaces.WrongType(value, expected_type, name)[source]¶
Object is of wrong type.
Changed in version 4.7.0: Added named arguments to the constructor and the
expected_type
field.
- exception zope.schema.interfaces.NotAnInterface(value, expected_type, name)[source]¶
Object is not an interface.
This is a
WrongType
exception for backwards compatibility with existingexcept
clauses, but it is raised whenIInterface.providedBy
is not true, so it’s also aSchemaNotProvided
. Theexpected_type
field is filled in asIInterface
; this is not actually atype
, andisinstance(thing, IInterface)
is always false.New in version 4.7.0.
Changed in version 4.7.0: Added named arguments to the constructor and the
expected_type
field.
Bounds¶
- exception zope.schema.interfaces.OutOfBounds(value, bound)[source]¶
A value was out of the allowed bounds.
This is the common superclass for
OrderableOutOfBounds
andLenOutOfBounds
, which in turn are the superclasses forTooBig
andTooSmall
, andTooLong
andTooShort
, respectively.New in version 4.7.0.
- exception zope.schema.interfaces.OrderableOutOfBounds(value, bound)[source]¶
A value was too big or too small in comparison to another value.
New in version 4.7.0.
- exception zope.schema.interfaces.LenOutOfBounds(value, bound)[source]¶
The length of the value was out of bounds.
New in version 4.7.0.
- exception zope.schema.interfaces.WrongContainedType(errors, name)[source]¶
Wrong contained type
Changed in version 4.7.0: Added named arguments to the constructor, and the
errors
property.
Schema APIs¶
- zope.schema.getFieldsInOrder(schema, _field_key=<function <lambda>>)[source]¶
Return a list of (name, value) tuples in native schema order.
- zope.schema.getFieldNamesInOrder(schema)[source]¶
Return a list of all the Field names in a schema in schema order.
- zope.schema.getValidationErrors(schema, value)[source]
Validate that value conforms to the schema interface schema.
This includes checking for any schema validation errors (using
getSchemaValidationErrors
). If that succeeds, then we proceed to check for any declared invariants.Note that this does not include a check to see if the value actually provides the given schema.
- Returns:
A sequence of (name,
zope.interface.Invalid
) tuples, where name is None if the error was from an invariant. If the sequence is empty, there were no errors.
- zope.schema.getSchemaValidationErrors(schema, value)[source]
Validate that value conforms to the schema interface schema.
All
zope.schema.interfaces.IField
members of the schema are validated after being bound to value. (Note that we do not check for arbitraryzope.interface.Attribute
members being present.)- Returns:
A sequence of (name,
ValidationError
) tuples. A non-empty sequence indicates validation failed.
Field Implementations¶
- class zope.schema.Field(title='', description='', __name__='', required=True, readonly=False, constraint=None, default=None, defaultFactory=None, missing_value=<Not Given>)[source]¶
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Collection(value_type=<Not Given>, unique=<Not Given>, **kw)[source]¶
A generic collection implementing
zope.schema.interfaces.ICollection
.Subclasses can define the attribute
value_type
to be a field such as anObject
that will be checked for each member of the collection. This can then be omitted from the constructor call.They can also define the attribute
_type
to be a concrete class (or tuple of classes) that the collection itself will be checked to be an instance of. This cannot be set in the constructor.Changed in version 4.6.0: Add the ability for subclasses to specify
value_type
andunique
, and allow eliding them from the constructor.Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- zope.schema._field.AbstractCollection¶
An alternate name for
Collection
.Deprecated since version 4.6.0: Use
Collection
instead.
- class zope.schema.Bool(title='', description='', __name__='', required=True, readonly=False, constraint=None, default=None, defaultFactory=None, missing_value=<Not Given>)[source]¶
A field representing a Bool.
Changed in version 4.8.0: Implement
zope.schema.interfaces.IFromBytes
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Choice(values=None, vocabulary=None, source=None, **kw)[source]¶
Choice fields can have a value found in a constant or dynamic set of values given by the field definition.
Initialize object.
- class zope.schema.Container(title='', description='', __name__='', required=True, readonly=False, constraint=None, default=None, defaultFactory=None, missing_value=<Not Given>)[source]¶
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Date(min=None, max=None, default=None, **kw)[source]¶
Field containing a date.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Datetime(*args, **kw)[source]¶
Field containing a datetime.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Dict(key_type=None, value_type=None, **kw)[source]¶
A field representing a Dict.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.FrozenSet(*args, **kwargs)[source]¶
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Id(*args, **kw)[source]¶
Id field
Values of id fields must be either uris or dotted names.
Changed in version 4.8.0: Implement
zope.schema.interfaces.IFromBytes
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.InterfaceField(title='', description='', __name__='', required=True, readonly=False, constraint=None, default=None, defaultFactory=None, missing_value=<Not Given>)[source]¶
Fields with a value that is an interface (implementing zope.interface.Interface).
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Iterable(title='', description='', __name__='', required=True, readonly=False, constraint=None, default=None, defaultFactory=None, missing_value=<Not Given>)[source]¶
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.List(value_type=<Not Given>, unique=<Not Given>, **kw)[source]¶
A field representing a List.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Mapping(key_type=None, value_type=None, **kw)[source]¶
A field representing a mapping.
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.MutableMapping(key_type=None, value_type=None, **kw)[source]¶
A field representing a mutable mapping.
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.MutableSequence(value_type=<Not Given>, unique=<Not Given>, **kw)[source]¶
A field representing a mutable sequence.
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.MinMaxLen(min_length=0, max_length=None, **kw)[source]¶
Expresses constraints on the length of a field.
MinMaxLen is a mixin used in combination with Field.
- class zope.schema.Object(schema=<Not Given>, *, validate_invariants=True, **kwargs)[source]¶
Implementation of
zope.schema.interfaces.IObject
.Create an
IObject
field. The keyword arguments are as forField
.Changed in version 4.6.0: Add the keyword argument validate_invariants. When true (the default), the schema’s
validateInvariants
method will be invoked to check the@invariant
properties of the schema.Changed in version 4.6.0: The schema argument can be ommitted in a subclass that specifies a
schema
attribute.
- class zope.schema.Orderable(min=None, max=None, default=None, **kw)[source]¶
Values of ordered fields can be sorted.
They can be restricted to a range of values.
Orderable is a mixin used in combination with Field.
- class zope.schema.Set(*args, **kwargs)[source]¶
A field representing a set.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Sequence(value_type=<Not Given>, unique=<Not Given>, **kw)[source]¶
A field representing an ordered sequence.
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Time(min=None, max=None, default=None, **kw)[source]¶
Field containing a time.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Timedelta(min=None, max=None, default=None, **kw)[source]¶
Field containing a timedelta.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Tuple(value_type=<Not Given>, unique=<Not Given>, **kw)[source]¶
A field representing a Tuple.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.URI(*args, **kw)[source]¶
URI schema field.
URIs can be validated from both unicode values and bytes values, producing a native text string in both cases:
>>> from zope.schema import URI >>> field = URI() >>> field.fromUnicode(u' https://example.com ') 'https://example.com' >>> field.fromBytes(b' https://example.com ') 'https://example.com'
Changed in version 4.8.0: Implement
zope.schema.interfaces.IFromBytes
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
Strings¶
- class zope.schema.ASCII(*args, **kw)[source]¶
Field containing a 7-bit ASCII string. No characters > DEL (chr(127)) are allowed
The value might be constrained to be with length limits.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.ASCIILine(*args, **kw)[source]¶
Field containing a 7-bit ASCII string without newlines.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Bytes(min_length=0, max_length=None, **kw)[source]¶
Field containing a byte string (like the python str).
The value might be constrained to be with length limits.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.BytesLine(min_length=0, max_length=None, **kw)[source]¶
A
Bytes
field with no newlines.Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.SourceText(*args, **kw)[source]¶
Field for source text of object.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Text(*args, **kw)[source]¶
A field containing text used for human discourse.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.TextLine(*args, **kw)[source]¶
A text field with no newlines.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.NativeString(*args, **kw)[source]¶
A native string is always the type
str
.In addition to
INativeString
, this implementsIFromUnicode
andIFromBytes
.Changed in version 4.9.0: This is now a distinct type instead of an alias for either
Text
orBytes
, depending on the platform.Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.NativeStringLine(*args, **kw)[source]¶
A native string is always the type
str
; this field excludes newlines.In addition to
INativeStringLine
, this implementsIFromUnicode
andIFromBytes
.Changed in version 4.9.0: This is now a distinct type instead of an alias for either
TextLine
orBytesLine
, depending on the platform.Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Password(*args, **kw)[source]¶
A text field containing a text used as a password.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.DottedName(*args, **kw)[source]¶
Dotted name field.
Values of DottedName fields must be Python-style dotted names.
Dotted names can be validated from both unicode values and bytes values, producing a native text string in both cases:
>>> from zope.schema import DottedName >>> field = DottedName() >>> field.fromUnicode(u'zope.schema') 'zope.schema' >>> field.fromBytes(b'zope.schema') 'zope.schema' >>> field.fromUnicode(u'zope._schema') 'zope._schema'
Changed in version 4.8.0: Implement
zope.schema.interfaces.IFromBytes
Changed in version 4.9.0: Allow leading underscores in each component.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.PythonIdentifier(*args, **kw)[source]¶
This field describes a python identifier, i.e. a variable name.
Empty strings are allowed.
Identifiers can be validated from both unicode values and bytes values, producing a native text string in both cases:
>>> from zope.schema import PythonIdentifier >>> field = PythonIdentifier() >>> field.fromUnicode(u'zope') 'zope' >>> field.fromBytes(b'_zope') '_zope' >>> field.fromUnicode(u' ') ''
New in version 4.9.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
Numbers¶
- class zope.schema.Number(min=None, max=None, default=None, **kw)[source]¶
A field representing a
numbers.Number
and implementingzope.schema.interfaces.INumber
.The
fromUnicode()
method will attempt to use the smallest or strictest possible type to represent incoming strings:>>> from zope.schema._bootstrapfields import Number >>> f = Number() >>> f.fromUnicode(u"1") 1 >>> f.fromUnicode(u"125.6") 125.6 >>> f.fromUnicode(u"1+0j") (1+0j) >>> f.fromUnicode(u"1/2") Fraction(1, 2) >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... Decimal('590...936') >>> f.fromUnicode(u"not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
Similarly,
fromBytes()
will do the same for incoming byte strings:>>> from zope.schema._bootstrapfields import Number >>> f = Number() >>> f.fromBytes(b"1") 1 >>> f.fromBytes(b"125.6") 125.6 >>> f.fromBytes(b"1+0j") (1+0j) >>> f.fromBytes(b"1/2") Fraction(1, 2) >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode('ascii')) ... Decimal('590...936') >>> f.fromBytes(b"not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
New in version 4.6.0.
Changed in version 4.8.0: Implement
zope.schema.interfaces.IFromBytes
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Complex(min=None, max=None, default=None, **kw)[source]¶
A field representing a
numbers.Complex
and implementingzope.schema.interfaces.IComplex
.The
fromUnicode()
method is like that forNumber
, but doesn’t allow Decimals:>>> from zope.schema._bootstrapfields import Complex >>> f = Complex() >>> f.fromUnicode(u"1") 1 >>> f.fromUnicode(u"125.6") 125.6 >>> f.fromUnicode(u"1+0j") (1+0j) >>> f.fromUnicode(u"1/2") Fraction(1, 2) >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... inf >>> f.fromUnicode(u"not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
Similarly for
fromBytes()
:>>> from zope.schema._bootstrapfields import Complex >>> f = Complex() >>> f.fromBytes(b"1") 1 >>> f.fromBytes(b"125.6") 125.6 >>> f.fromBytes(b"1+0j") (1+0j) >>> f.fromBytes(b"1/2") Fraction(1, 2) >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode('ascii')) ... inf >>> f.fromBytes(b"not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Real(min=None, max=None, default=None, **kw)[source]¶
A field representing a
numbers.Real
and implementingzope.schema.interfaces.IReal
.The
fromUnicode()
method is like that forComplex
, but doesn’t allow Decimals or complex numbers:>>> from zope.schema._bootstrapfields import Real >>> f = Real() >>> f.fromUnicode("1") 1 >>> f.fromUnicode("125.6") 125.6 >>> f.fromUnicode("1+0j") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Fraction: '1+0j' >>> f.fromUnicode("1/2") Fraction(1, 2) >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... inf >>> f.fromUnicode("not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Rational(min=None, max=None, default=None, **kw)[source]¶
A field representing a
numbers.Rational
and implementingzope.schema.interfaces.IRational
.The
fromUnicode()
method is like that forReal
, but does not allow arbitrary floating point numbers:>>> from zope.schema._bootstrapfields import Rational >>> f = Rational() >>> f.fromUnicode("1") 1 >>> f.fromUnicode("1/2") Fraction(1, 2) >>> f.fromUnicode("125.6") Fraction(628, 5) >>> f.fromUnicode("1+0j") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Fraction: '1+0j' >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... Fraction(195..., 330...) >>> f.fromUnicode("not a number") Traceback (most recent call last): ... InvalidNumberLiteral: Invalid literal for Decimal: 'not a number'
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Integral(min=None, max=None, default=None, **kw)[source]¶
A field representing a
numbers.Integral
and implementingzope.schema.interfaces.IIntegral
.The
fromUnicode()
method only allows integral values:>>> from zope.schema._bootstrapfields import Integral >>> f = Integral() >>> f.fromUnicode("125") 125 >>> f.fromUnicode("125.6") Traceback (most recent call last): ... InvalidIntLiteral: invalid literal for int(): 125.6
Similarly for
fromBytes()
:>>> from zope.schema._bootstrapfields import Integral >>> f = Integral() >>> f.fromBytes(b"125") 125 >>> f.fromBytes(b"125.6") Traceback (most recent call last): ... InvalidIntLiteral: invalid literal for int(): 125.6
New in version 4.6.0.
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Float(min=None, max=None, default=None, **kw)[source]¶
A field representing a native
float
and implementingzope.schema.interfaces.IFloat
.The class
zope.schema.Real
is a more general version, accepting floats, integers, and fractions.The
fromUnicode()
method only accepts values that can be parsed by thefloat
constructor:>>> from zope.schema._field import Float >>> f = Float() >>> f.fromUnicode("1") 1.0 >>> f.fromUnicode("125.6") 125.6 >>> f.fromUnicode("1+0j") Traceback (most recent call last): ... InvalidFloatLiteral: Invalid literal for float(): 1+0j >>> f.fromUnicode("1/2") Traceback (most recent call last): ... InvalidFloatLiteral: invalid literal for float(): 1/2 >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... inf >>> f.fromUnicode("not a number") Traceback (most recent call last): ... InvalidFloatLiteral: could not convert string to float: not a number
Likewise for
fromBytes()
:>>> from zope.schema._field import Float >>> f = Float() >>> f.fromBytes(b"1") 1.0 >>> f.fromBytes(b"125.6") 125.6 >>> f.fromBytes(b"1+0j") Traceback (most recent call last): ... InvalidFloatLiteral: Invalid literal for float(): 1+0j >>> f.fromBytes(b"1/2") Traceback (most recent call last): ... InvalidFloatLiteral: invalid literal for float(): 1/2 >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode('ascii')) ... inf >>> f.fromBytes(b"not a number") Traceback (most recent call last): ... InvalidFloatLiteral: could not convert string to float: not a number
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Int(min=None, max=None, default=None, **kw)[source]¶
A field representing a native integer type. and implementing
zope.schema.interfaces.IInt
.Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
- class zope.schema.Decimal(min=None, max=None, default=None, **kw)[source]¶
A field representing a native
decimal.Decimal
and implementingzope.schema.interfaces.IDecimal
.The
fromUnicode()
method only accepts values that can be parsed by theDecimal
constructor:>>> from zope.schema._field import Decimal >>> f = Decimal() >>> f.fromUnicode("1") Decimal('1') >>> f.fromUnicode("125.6") Decimal('125.6') >>> f.fromUnicode("1+0j") Traceback (most recent call last): ... InvalidDecimalLiteral: Invalid literal for Decimal(): 1+0j >>> f.fromUnicode("1/2") Traceback (most recent call last): ... InvalidDecimalLiteral: Invalid literal for Decimal(): 1/2 >>> f.fromUnicode(str(2**11234) + '.' + str(2**256)) ... Decimal('5901...936') >>> f.fromUnicode("not a number") Traceback (most recent call last): ... InvalidDecimalLiteral: could not convert string to float: not a number
Likewise for
fromBytes()
:>>> from zope.schema._field import Decimal >>> f = Decimal() >>> f.fromBytes(b"1") Decimal('1') >>> f.fromBytes(b"125.6") Decimal('125.6') >>> f.fromBytes(b"1+0j") Traceback (most recent call last): ... InvalidDecimalLiteral: Invalid literal for Decimal(): 1+0j >>> f.fromBytes(b"1/2") Traceback (most recent call last): ... InvalidDecimalLiteral: Invalid literal for Decimal(): 1/2 >>> f.fromBytes((str(2**11234) + '.' + str(2**256)).encode("ascii")) ... Decimal('5901...936') >>> f.fromBytes(b"not a number") Traceback (most recent call last): ... InvalidDecimalLiteral: could not convert string to float: not a number
Pass in field values as keyword parameters.
Generally, you want to pass either a title and description, or a doc string. If you pass no doc string, it will be computed from the title and description. If you pass a doc string that follows the Python coding style (title line separated from the body by a blank line), the title and description will be computed from the doc string. Unfortunately, the doc string must be passed as a positional argument.
Here are some examples:
>>> from zope.schema._bootstrapfields import Field >>> f = Field() >>> f.__doc__, str(f.title), str(f.description) ('', '', '')
>>> f = Field(title=u'sample') >>> str(f.__doc__), str(f.title), str(f.description) ('sample', 'sample', '')
>>> f = Field(title=u'sample', description=u'blah blah\nblah') >>> str(f.__doc__), str(f.title), str(f.description) ('sample\n\nblah blah\nblah', 'sample', 'blah blah\nblah')
Vocabularies¶
Vocabulary support for schema.
Accessors¶
Field accessors¶
Accessors are used to model methods used to access data defined by fields. Accessors are fields that work by decorating existing fields.
To define accessors in an interface, use the accessors function:
class IMyInterface(Interface):
getFoo, setFoo = accessors(Text(title=u'Foo', ...))
getBar = accessors(TextLine(title=u'Foo', readonly=True, ...)
Normally a read accessor and a write accessor are defined. Only a read accessor is defined for read-only fields.
Read accessors function as access method specifications and as field specifications. Write accessors are solely method specifications.