Skip to main content

Generic Formlib fields

Project description

The dolmen.field package provides additional generic fields to extend zope.schema.

Configuration fields

The configuration fields are used for description and constraints, to impose a consistent schema and data model.

GlobalClass

GlobalClass is a field requiring a valid Interface class. It can be used for factories and other components that need to store an interface with the possibility to check and verify the consistency of the given value:

>>> from zope.interface import Interface
>>> from dolmen.field import GlobalClass, IClassField

>>> class IDummy(Interface):
...     def shall_fail():
...         pass

>>> class Dummy(object):
...     pass

Of course, it must be a valid interface:

>>> field = GlobalClass(
...             title=u'a class field',
...             schema=object
...             )
Traceback (most recent call last):
...
WrongType: <type 'object'> is not a valid Interface

The interface will be used to validate the class:

>>> field = GlobalClass(
...             title=u'a class field',
...             schema=IDummy
...             )

>>> field.schema
<InterfaceClass dolmen.field.tests.IDummy>
>>> IClassField.providedBy(field)
True

We make sure the interface attribute is not touched:

>>> print field.interface
None

In a first time, we make sure the class implements the needed interface:

>>> field._validate(Dummy)
Traceback (most recent call last):
...
ConstraintNotSatisfied: <class 'dolmen.field.tests.Dummy'> does not implement <InterfaceClass dolmen.field.tests.IDummy>

>>> from zope.interface import classImplements
>>> classImplements(Dummy, IDummy)
>>> IDummy.implementedBy(Dummy)
True

Then the interface acts as a strict validator:

>>> field._validate(Dummy)
Traceback (most recent call last):
...
BrokenImplementation: An object has failed to implement interface <InterfaceClass dolmen.field.tests.IDummy>
<BLANKLINE>
The shall_fail attribute was not provided.
<BLANKLINE>

>>> Dummy.shall_fail = lambda x: u'not'
>>> field._validate(Dummy) is None
True

Changelog

0.3 (2009-10-25)

  • Refactored the field to use the ‘schema’ attribute instead of ‘interface’. The attribute name ‘interface’ was conflicting with other fields manipulating packages.

  • Now using a README.txt instead of inline doctests, for more readability.

0.2 (2009-06-09)

  • Initial Pypi release

0.1 (2009-05-03)

  • Internal release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dolmen.field-0.3.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file dolmen.field-0.3.tar.gz.

File metadata

  • Download URL: dolmen.field-0.3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dolmen.field-0.3.tar.gz
Algorithm Hash digest
SHA256 c42446b44628d36be6bfe85cc89a35936d5adccf13ff4f71ed384e3814cb25d6
MD5 548ffc36e7aaaa4a47e7f157559d0e74
BLAKE2b-256 c18a9d35e951bb0fa8601ce4d1ab695812cd07cf3ef3a0e7089e8d10fb3c6590

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page