class IBool(IField): """Boolean Field.""" default = Bool( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""))
class ISchemaWithObjectFieldAsInterface(Interface): obj = Object( schema=Interface, title=_(u"Object"), description=_(u"object description"), required=False)
class IInt(IIntegral): """ Field containing exactly the native class :class:`int` (or, on Python 2, ``long``). .. seealso:: :class:`zope.schema.Int` """ min = Int( title=_("Start of the range"), required=False, default=None ) max = Int( title=_("End of the range (including the value itself)"), required=False, default=None ) default = Int( title=_("Default Value"), description=_("""The field default value may be None or a legal field value""") )
class IMinMaxLen(ILen): """Field requiring the length of its value to be within a range""" min_length = Int( title=_("Minimum length"), description=_(""" Value after whitespace processing cannot have less than `min_length` characters (if a string type) or elements (if another sequence type). If `min_length` is ``None``, there is no minimum. """), required=False, min=0, # needs to be a positive number default=0) max_length = Int( title=_("Maximum length"), description=_(""" Value after whitespace processing cannot have greater or equal than `max_length` characters (if a string type) or elements (if another sequence type). If `max_length` is ``None``, there is no maximum."""), required=False, min=0, # needs to be a positive number default=None)
class IRational(IReal): """ Field containing a rational number: :class:`numbers.IRational`. .. seealso:: :class:`zope.schema.Rational` .. versionadded:: 4.6.0 """ min = Rational( title=_("Start of the range"), required=False, default=None ) max = Rational( title=_("End of the range (including the value itself)"), required=False, default=None ) default = Rational( title=_("Default Value"), description=_("""The field default value may be None or a legal field value""") )
class IPerson(Interface): """A schema that participate to a cycle""" unit = Object( schema=IUnit, title=_(u"Unit"), description=_(u"Unit description"), required=False, )
class IMinMax(IOrderable): """Field requiring its value to be between min and max. This implies that the value needs to support the IOrderable interface. """ min = Field(title=_("Start of the range"), required=False, default=None) max = Field(title=_("End of the range (including the value itself)"), required=False, default=None)
class IBool(IField): """Boolean Field.""" default = Bool( title=_("Default Value"), description=_("""The field default value may be None or a legal field value""")) required = Bool( title=_("Required"), description=(_("Tells whether a field requires its value to exist.")), required=False, default=False)
class IDecimal(INumber): """Field containing a :class:`decimal.Decimal`""" min = Decimal(title=_("Start of the range"), required=False, default=None) max = Decimal(title=_("End of the range (including the value itself)"), required=False, default=None) default = Decimal( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""))
class IInt(IMinMax, IField): """Field containing an Integer Value.""" min = Int(title=_("Start of the range"), required=False, default=None) max = Int(title=_("End of the range (excluding the value itself)"), required=False, default=None) default = Int( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""))
class IDottedName(_IStrLine): """Dotted name field. Values of DottedName fields must be Python-style dotted names. """ min_dots = Int(title=_("Minimum number of dots"), required=True, min=0, default=0) max_dots = Int( title=_("Maximum number of dots (should not be less than min_dots)"), required=False, default=None)
class IDict(IMinMaxLen, IIterable, IContainer): """Field containing a conventional dict. The key_type and value_type fields allow specification of restrictions for keys and values contained in the dict. """ key_type = Attribute( "key_type", _("Field keys must conform to the given type, expressed via a Field.")) value_type = Attribute( "value_type", _("Field values must conform to the given type, expressed " "via a Field."))
class SchemaNotCorrectlyImplemented(WrongContainedType): __doc__ = _("""An object failed schema or invariant validation.""") #: A dictionary mapping failed attribute names of the #: *value* to the underlying exception schema_errors = None #: A list of exceptions from validating the invariants #: of the schema. invariant_errors = () def __init__(self, errors=None, name=None, schema_errors=None, invariant_errors=(), *args): """ SchemaNotCorrectlyImplemented(errors, name, schema_errors, invariant_errors) .. versionchanged:: 4.7.0 Added named arguments to the constructor. """ super(SchemaNotCorrectlyImplemented, self).__init__(errors, name, *args) self.schema_errors = schema_errors self.invariant_errors = invariant_errors
class IUnit(Interface): """A schema that participate to a cycle""" boss = Object( schema=Interface, title=_(u"Boss"), description=_(u"Boss description"), required=False, ) members = List( value_type=Object(schema=Interface), title=_(u"Member List"), description=_(u"Member list description"), required=False, )
class ICollection(IMinMaxLen, IIterable, IContainer): """Abstract interface containing a collection value. The Value must be iterable and may have a min_length/max_length. """ value_type = Field( title=_("Value Type"), description=_("Field value items must conform to the given type, " "expressed via a Field.")) unique = Bool( title=_('Unique Members'), description=_('Specifies whether the members of the collection ' 'must be unique.'), default=False)
class IObject(IField): """Field containing an Object value.""" schema = Attribute( "schema", _("The Interface that defines the Fields comprising the Object.") )
class ITestSchema(Interface): """A test schema""" foo = TextLine( title=_(u"Foo"), description=_(u"Foo description"), default=u"", required=True) bar = TextLine( title=_(u"Bar"), description=_(u"Bar description"), default=u"", required=False) attribute = Attribute("Test attribute, an attribute can't be validated.")
class INumber(IMinMax, IField): """ Field containing a generic number: :class:`numbers.Number`. .. seealso:: :class:`zope.schema.Number` .. versionadded:: 4.6.0 """ min = Number(title=_("Start of the range"), required=False, default=None) max = Number(title=_("End of the range (including the value itself)"), required=False, default=None) default = Number( title=_("Default Value"), description=_("""The field default value may be None or a legal field value"""))
class IMapping(IMinMaxLen, IIterable, IContainer): """ Field containing an instance of :class:`collections.Mapping`. The *key_type* and *value_type* fields allow specification of restrictions for keys and values contained in the dict. """ key_type = Object( IField, description=_("Field keys must conform to the given type, expressed " "via a Field.")) value_type = Object( IField, description=_("Field values must conform to the given type, expressed " "via a Field."))
class IChoice(IField): """Field whose value is contained in a predefined set Only one, values or vocabulary, may be specified for a given choice. """ vocabulary = Field( title=_("Vocabulary or source providing values"), description=_("The ISource, IContextSourceBinder or IBaseVocabulary " "object that provides values for this field."), required=False, default=None) vocabularyName = TextLine( title=_("Vocabulary name"), description=_("Vocabulary name to lookup in the vocabulary registry"), required=False, default=None)
class IObject(IField): """ Field containing an Object value. .. versionchanged:: 4.6.0 Add the *validate_invariants* attribute. """ schema = Object( IInterface, description=_("The Interface that defines the Fields comprising the Object.") ) validate_invariants = Bool( title=_("Validate Invariants"), description=_("A boolean that says whether ``schema.validateInvariants`` " "is called from ``self.validate()``. The default is true."), default=True, )
class SchemaNotProvided(ValidationError): __doc__ = _("""Schema not provided""") #: The interface that the *value* was supposed to provide, #: but does not. schema = None def __init__(self, schema=None, value=None, *args): """ SchemaNotProvided(schema, value) .. versionchanged:: 4.7.0 Added named arguments to the constructor and the `schema` property. """ super(SchemaNotProvided, self).__init__(schema, value, *args) self.schema = schema self.value = value
class WrongContainedType(ValidationError): __doc__ = _("""Wrong contained type""") #: A collection of exceptions raised when validating #: the *value*. #: #: .. versionadded:: 4.7.0 errors = () def __init__(self, errors=None, name=None, *args): """ WrongContainedType(errors, name) .. versionchanged:: 4.7.0 Added named arguments to the constructor, and the `errors` property. """ super(WrongContainedType, self).__init__(errors, name, *args) self.errors = errors
class WrongType(ValidationError): __doc__ = _("""Object is of wrong type.""") #: The type or tuple of types that was expected. #: #: .. versionadded:: 4.7.0 expected_type = None def __init__(self, value=None, expected_type=None, name=None, *args): """ WrongType(value, expected_type, name) .. versionchanged:: 4.7.0 Added named arguments to the constructor and the `expected_type` field. """ ValidationError.__init__(self, value, expected_type, name, *args) self.expected_type = expected_type self.value = value
class NotAnIterator(ValidationError): __doc__ = _("""Not an iterator""")
class NotAContainer(ValidationError): __doc__ = _("""Not a container""")
class ConstraintNotSatisfied(ValidationError): __doc__ = _("""Constraint not satisfied""")
class InvalidValue(ValidationError): __doc__ = _("""Invalid value""")
class TooShort(ValidationError): __doc__ = _("""Value is too short""")
class TooLong(ValidationError): __doc__ = _("""Value is too long""")