[Zope3-dev] "Sub interface"
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Feb 29 03:11:22 EST 2004
On Sunday 29 February 2004 00:27, Terry Hancock wrote:
> A sub-interface inherits from Interface.Attribute, but
> has an extra property specifying the expected interface
> of the attribute.
For this we have fields. I just checked and you cannot specify the interface
of a field, but this can be easily done:
class GeneralField(Field):
def __init__(self, *args, **kwargs):
if "interface" in kwargs:
self._interface = kwargs["interface"]
del kwargs["interface"]
else:
ValueError, "'interface' argument missing."
super(GeneralField, self).__init__(*args, **kwargs)
def _validate(self, value):
try:
verifyObject(value, self._interface)
except Invalid, err:
raise ValidationError("Value does not implement %s"
%self._interface.name())
Regards,
Stephan
--
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
More information about the Zope3-dev
mailing list