[Zope3-checkins] CVS: Zope3/src/zope/schema - interfaces.py:1.15.4.1 vocabulary.py:1.1.2.3
Fred L. Drake, Jr.
fred@zope.com
Wed, 7 May 2003 16:50:52 -0400
Update of /cvs-repository/Zope3/src/zope/schema
In directory cvs.zope.org:/tmp/cvs-serv15457
Modified Files:
Tag: schema-vocabulary-branch
interfaces.py vocabulary.py
Log Message:
Move the vocabulary interfaces to the zope.schema.interfaces module.
=== Zope3/src/zope/schema/interfaces.py 1.15 => 1.15.4.1 ===
--- Zope3/src/zope/schema/interfaces.py:1.15 Fri Apr 25 17:18:31 2003
+++ Zope3/src/zope/schema/interfaces.py Wed May 7 16:50:20 2003
@@ -15,7 +15,7 @@
$Id$
"""
-from zope.interface import Interface
+from zope.interface import Interface, Attribute
from zope.i18n import MessageIDFactory
_ = MessageIDFactory("zope")
@@ -396,3 +396,98 @@
constraint=_fields,
required=False,
)
+
+
+class IAbstractVocabulary(Interface):
+ """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).
+ """
+
+ def getTerm(value):
+ """Return the ITerm object for the term 'value'.
+
+ If 'value' is not a valid term, this method raises LookupError.
+ """
+
+
+class ITerm(Interface):
+ """Object representing a single value in a vocabulary."""
+
+ value = Attribute(
+ "value", "The value used to represent vocabulary term in a field.")
+
+
+class IIterableVocabulary(Interface):
+ """Vocabulary which supports iteration over allowed values.
+
+ The objects iteration provides must conform to the ITerm
+ interface.
+ """
+
+ def __iter__():
+ """Return an iterator which provides the terms from the vocabulary."""
+
+ def __len__():
+ """Return the number of valid terms, or sys.maxint."""
+
+
+class ISubsetVocabulary(Interface):
+ """Vocabulary which represents a subset of another vocabulary."""
+
+ def getMasterVocabulary():
+ """Returns the vocabulary that this is a subset of."""
+
+
+class IVocabulary(IIterableVocabulary, IAbstractVocabulary):
+ """Vocabulary which is iterable."""
+
+
+class IVocabularyFieldMixin(Interface):
+ # Mix-in interface that defines interesting things common to all
+ # vocabulary fields.
+
+ vocabularyName = TextLine(
+ title=u"Vocabulary Name",
+ description=(u"The name of the vocabulary to be used. This name\n"
+ u"is intended to be used by the IVocabularyRegistry's\n"
+ u"get() method."),
+ required=False,
+ default=None)
+
+ vocabulary = Attribute(
+ "vocabulary",
+ ("IAbstractVocabulary to be used, or None.\n"
+ "\n"
+ "If None, the vocabularyName should be used by an\n"
+ "IVocabularyRegistry should be used to locate an appropriate\n"
+ "IAbstractVocabulary object."))
+
+
+class IVocabularyField(IVocabularyFieldMixin, IField):
+ """Field with a vocabulary-supported value.
+
+ The value for fields of this type is a single value from the
+ vocabulary.
+ """
+
+
+class IVocabularyMultiField(IVocabularyFieldMixin, IField):
+ """Field with a value containing selections from a vocabulary..
+
+ The value for fields of this type need to support at least
+ containment checks using 'in' and iteration.
+ """
+
+
+class IVocabularyRegistry(Interface):
+ """Registry that provides IAbstractVocabulary objects for specific fields.
+ """
+
+ def get(object, name):
+ """Return the vocabulary named 'name' for the content object
+ 'object'.
+ """
=== Zope3/src/zope/schema/vocabulary.py 1.1.2.2 => 1.1.2.3 ===
--- Zope3/src/zope/schema/vocabulary.py:1.1.2.2 Fri May 2 11:17:45 2003
+++ Zope3/src/zope/schema/vocabulary.py Wed May 7 16:50:20 2003
@@ -14,10 +14,11 @@
"""Vocabulary support for schema."""
-from zope.interface import Interface, Attribute
-from zope.schema import Field, TextLine
+from zope.schema import Field
from zope.schema import errornames
-from zope.schema.interfaces import IField, ValidationError
+from zope.schema.interfaces import ValidationError
+from zope.schema.interfaces import IAbstractVocabulary, IVocabularyRegistry
+from zope.schema.interfaces import IVocabularyField, IVocabularyMultiField
try:
basestring # new in Python 2.3
@@ -25,103 +26,11 @@
from types import StringTypes as basestring
-class IAbstractVocabulary(Interface):
- """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).
- """
-
- def getTerm(value):
- """Return the ITerm object for the term 'value'.
-
- If 'value' is not a valid term, this method raises LookupError.
- """
-
-
-class ITerm(Interface):
- """Object representing a single value in a vocabulary."""
-
- value = Attribute(
- "value", "The value used to represent vocabulary term in a field.")
-
-
-class IIterableVocabulary(Interface):
- """Vocabulary which supports iteration over allowed values.
-
- The objects iteration provides must conform to the ITerm
- interface.
- """
-
- def __iter__():
- """Return an iterator which provides the terms from the vocabulary."""
-
- def __len__():
- """Return the number of valid terms, or sys.maxint."""
-
-
-class ISubsetVocabulary(Interface):
- """Vocabulary which represents a subset of another vocabulary."""
-
- def getMasterVocabulary():
- """Returns the vocabulary that this is a subset of."""
-
-class IVocabulary(IIterableVocabulary, IAbstractVocabulary):
- """Vocabulary which is iterable."""
-
-
class IExampleQueryableVocabulary(IAbstractVocabulary):
# XXX Example only
def query(pattern):
"""Return ISubsetVocabulary with values that match pattern."""
-
-
-class IVocabularyFieldMixin(Interface):
- # Mix-in interface that defines interesting things common to all
- # vocabulary fields.
-
- vocabularyName = TextLine(
- title=u"Vocabulary Name",
- description=(u"The name of the vocabulary to be used. This name\n"
- u"is intended to be used by the IVocabularyRegistry's\n"
- u"get() method."),
- required=False,
- default=None)
-
- vocabulary = Attribute(
- "vocabulary",
- ("IAbstractVocabulary to be used, or None.\n"
- "\n"
- "If None, the vocabularyName should be used by an\n"
- "IVocabularyRegistry should be used to locate an appropriate\n"
- "IAbstractVocabulary object."))
-
-class IVocabularyField(IVocabularyFieldMixin, IField):
- """Field with a vocabulary-supported value.
-
- The value for fields of this type is a single value from the
- vocabulary.
- """
-
-class IVocabularyMultiField(IVocabularyFieldMixin, IField):
- """Field with a value containing selections from a vocabulary..
-
- The value for fields of this type need to support at least
- containment checks using 'in' and iteration.
- """
-
-
-class IVocabularyRegistry(Interface):
- """Registry that provides IAbstractVocabulary objects for specific fields.
- """
-
- def get(object, name):
- """Return the vocabulary named 'name' for the content object
- 'object'.
- """
class VocabularyField(Field):