[Checkins] SVN: zope.sendmail/trunk/ Use simple vocabulary factory function instead of custom `UtilityTerm` and `UtilityVocabulary` classes, copied from ``zope.app.component`` in the previous release.

Dan Korostelev nadako at gmail.com
Mon Mar 16 17:56:33 EDT 2009


Log message for revision 98165:
  Use simple vocabulary factory function instead of custom `UtilityTerm` and `UtilityVocabulary` classes, copied from ``zope.app.component`` in the previous release.
  
  Depend on the ``transaction`` package instead of ``ZODB3``.
  
  Remove zcml slugs and zpkg-related files.
  

Changed:
  _U  zope.sendmail/trunk/
  U   zope.sendmail/trunk/CHANGES.txt
  U   zope.sendmail/trunk/setup.py
  D   zope.sendmail/trunk/src/zope/sendmail/SETUP.cfg
  D   zope.sendmail/trunk/src/zope/sendmail/sendmail-configure.zcml
  D   zope.sendmail/trunk/src/zope/sendmail/sendmail-meta.zcml
  U   zope.sendmail/trunk/src/zope/sendmail/vocabulary.py

-=-

Property changes on: zope.sendmail/trunk
___________________________________________________________________
Modified: svn:ignore
   - bin
build
dist
lib
develop-eggs
eggs
parts
.installed.cfg

   + bin
build
dist
lib
develop-eggs
eggs
parts
.installed.cfg
coverage


Modified: zope.sendmail/trunk/CHANGES.txt
===================================================================
--- zope.sendmail/trunk/CHANGES.txt	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/CHANGES.txt	2009-03-16 21:56:33 UTC (rev 98165)
@@ -1,10 +1,18 @@
-Change history
-~~~~~~~~~~~~~~
+=======
+CHANGES
+=======
 
-3.5.2 (unreleased)
+3.6.0 (unreleased)
 ------------------
 
+- Use simple vocabulary factory function instead of custom `UtilityTerm`
+  and `UtilityVocabulary` classes, copied from ``zope.app.component`` in
+  the previous release.
 
+- Depend on the ``transaction`` package instead of ``ZODB3``.
+
+- Remove zcml slugs and zpkg-related files.
+
 3.5.1 (2009-01-26)
 ------------------
 

Modified: zope.sendmail/trunk/setup.py
===================================================================
--- zope.sendmail/trunk/setup.py	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/setup.py	2009-03-16 21:56:33 UTC (rev 98165)
@@ -19,7 +19,7 @@
 
 
 setup(name='zope.sendmail',
-      version = '3.5.2dev',
+      version = '3.6.0dev',
       url='http://pypi.python.org/pypi/zope.sendmail',
       license='ZPL 2.1',
       description='Zope sendmail',
@@ -36,13 +36,21 @@
       namespace_packages=['zope',],
       tests_require = ['zope.testing'],
       install_requires=['setuptools',
-                        'ZODB3',
-                        'zope.component',
-                        'zope.configuration',
+                        'transaction',
                         'zope.i18nmessageid',
                         'zope.interface',
                         'zope.schema',
+
+                        # XXX: maybe the following should moved into
+                        # extras to ease reusability.
+
+                        # it's only needed for vocabulary and zcml
+                        'zope.component',
+
+                        # these are only needed for zcml
+                        'zope.configuration',
                         'zope.security',
+
                        ],
       include_package_data = True,
       zip_safe = False,

Deleted: zope.sendmail/trunk/src/zope/sendmail/SETUP.cfg
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/SETUP.cfg	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/src/zope/sendmail/SETUP.cfg	2009-03-16 21:56:33 UTC (rev 98165)
@@ -1,5 +0,0 @@
-# Tell zpkg how to install the ZCML slugs.
-
-<data-files zopeskel/etc/package-includes>
-  sendmail-*.zcml
-</data-files>

Deleted: zope.sendmail/trunk/src/zope/sendmail/sendmail-configure.zcml
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/sendmail-configure.zcml	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/src/zope/sendmail/sendmail-configure.zcml	2009-03-16 21:56:33 UTC (rev 98165)
@@ -1 +0,0 @@
-<include package="zope.sendmail"/>

Deleted: zope.sendmail/trunk/src/zope/sendmail/sendmail-meta.zcml
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/sendmail-meta.zcml	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/src/zope/sendmail/sendmail-meta.zcml	2009-03-16 21:56:33 UTC (rev 98165)
@@ -1 +0,0 @@
-<include package="zope.sendmail" file="meta.zcml"/>

Modified: zope.sendmail/trunk/src/zope/sendmail/vocabulary.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/vocabulary.py	2009-03-16 21:30:14 UTC (rev 98164)
+++ zope.sendmail/trunk/src/zope/sendmail/vocabulary.py	2009-03-16 21:56:33 UTC (rev 98165)
@@ -18,155 +18,12 @@
 __docformat__ = 'restructuredtext'
 
 import zope.component
-from zope.interface import classProvides
-from zope.interface import implements
-from zope.interface import Interface
-from zope.schema.interfaces import ITokenizedTerm
+from zope.interface import directlyProvides
 from zope.schema.interfaces import IVocabularyFactory
-from zope.schema.interfaces import IVocabularyTokenized
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
 from zope.sendmail.interfaces import IMailDelivery
 
-
-class UtilityTerm(object):
-    """A term representing a utility.
-
-    The token of the term is the name of the utility. Here is a brief example
-    on how the IVocabulary interface is handled in this term as a
-    utility:
-    
-    >>> from zope.interface.verify import verifyObject
-    >>> from zope.schema.interfaces import IVocabulary
-    >>> term = UtilityTerm(IVocabulary, 'zope.schema.interfaces.IVocabulary')
-    >>> verifyObject(ITokenizedTerm, term)
-    True
-
-    >>> term.value
-    <InterfaceClass zope.schema.interfaces.IVocabulary>
-    >>> term.token
-    'zope.schema.interfaces.IVocabulary'
-
-    >>> term
-    <UtilityTerm zope.schema.interfaces.IVocabulary, instance of InterfaceClass>
-    """
-    implements(ITokenizedTerm)
-
-    def __init__(self, value, token):
-        """Create a term for value and token."""
-        self.value = value
-        self.token = token
-
-    def __repr__(self):
-        return '<UtilityTerm %s, instance of %s>' %(
-            self.token, self.value.__class__.__name__)
-
-
-class UtilityVocabulary(object):
-    """Vocabulary that provides utilities of a specified interface.
-
-    Here is a short example of how the vocabulary should work.
-
-    First we need to create a utility interface and some utilities:
-
-    >>> class IObject(Interface):
-    ...     'Simple interface to mark object utilities.'
-
-    >>> class Object(object):
-    ...     implements(IObject)
-    ...     def __init__(self, name):
-    ...         self.name = name
-    ...     def __repr__(self):
-    ...         return '<Object %s>' %self.name
-
-    Now we register some utilities for IObject
-
-    >>> from zope.component import provideUtility
-    >>> object1 = Object('object1')
-    >>> provideUtility(object1, name='object1')
-    >>> object2 = Object('object2')
-    >>> provideUtility(object2, name='object2')
-    >>> object3 = Object('object3')
-    >>> provideUtility(object3, name='object3')
-    >>> object4 = Object('object4')
-
-    We are now ready to create a vocabulary that we can use; in our case
-    everything is global, so the context is None.
-
-    >>> vocab = UtilityVocabulary(None, interface=IObject)
-    >>> import pprint
-    >>> pprint.pprint(vocab._terms.items())
-    [(u'object1', <UtilityTerm object1, instance of Object>),
-     (u'object2', <UtilityTerm object2, instance of Object>),
-     (u'object3', <UtilityTerm object3, instance of Object>)]
-
-    Now let's see how the other methods behave in this context. First we can
-    just use the 'in' opreator to test whether a value is available.
-
-    >>> object1 in vocab
-    True
-    >>> object4 in vocab
-    False
-
-    We can also create a lazy iterator. Note that the utility terms might
-    appear in a different order than the utilities were registered.
-
-    >>> iterator = iter(vocab)
-    >>> terms = list(iterator)
-    >>> names = [term.token for term in terms]
-    >>> names.sort()
-    >>> names
-    [u'object1', u'object2', u'object3']
-
-    Determining the amount of utilities available via the vocabulary is also
-    possible.
-
-    >>> len(vocab)
-    3
-    """
-    implements(IVocabularyTokenized)
-    classProvides(IVocabularyFactory)
-
-    # override these in subclasses
-    interface = Interface
-    nameOnly = False
-
-    def __init__(self, context, **kw):
-        utils = zope.component.getUtilitiesFor(self.interface, context)
-        self._terms = dict(
-            (name, UtilityTerm(self.nameOnly and name or util, name))
-            for name, util in utils)
-
-    def __contains__(self, value):
-        """See zope.schema.interfaces.IBaseVocabulary"""
-        return value in (term.value for term in self._terms.values())
-
-    def getTerm(self, value):
-        """See zope.schema.interfaces.IBaseVocabulary"""
-        try:
-            return [term for name, term in self._terms.items()
-                    if term.value == value][0]
-        except IndexError:
-            raise LookupError(value)
-
-    def getTermByToken(self, token):
-        """See zope.schema.interfaces.IVocabularyTokenized"""
-        try:
-            return self._terms[token]
-        except KeyError:
-            raise LookupError(token)
-
-    def __iter__(self):
-        """See zope.schema.interfaces.IIterableVocabulary"""
-        # Sort the terms by the token (utility name)
-        values = self._terms.values()
-        values.sort(lambda x, y: cmp(x.token, y.token))
-        return iter(values)
-
-    def __len__(self):
-        """See zope.schema.interfaces.IIterableVocabulary"""
-        return len(self._terms)
-
-
-class MailDeliveryNames(UtilityVocabulary):
+def MailDeliveryNames(context=None):
     """Vocabulary with names of mail delivery utilities
 
     Let's provide a few stub utilities:
@@ -192,6 +49,9 @@
       >>> print ' '.join(names)
       and completely different for now something
     """
-    classProvides(IVocabularyFactory)
-    interface = IMailDelivery
-    nameOnly = True
+    
+    utils = zope.component.getUtilitiesFor(IMailDelivery, context)
+    terms = [SimpleTerm(name) for name, util in utils]
+    return SimpleVocabulary(terms)
+
+directlyProvides(MailDeliveryNames, IVocabularyFactory)



More information about the Checkins mailing list