[Checkins] SVN: zope.sendmail/trunk/ Removed dependency on ``zope.security``.

Fabio Tranchitella kobold at kobold.it
Fri Dec 18 15:27:54 EST 2009


Log message for revision 106772:
  Removed dependency on ``zope.security``.
  
  The security support is optional, and only available if the ``zope.security``
  package is available. This change is similar to the optional security support
  introduced in ``zope.component`` 3.8.0, and in fact it uses the same helpers.
  
  
  

Changed:
  U   zope.sendmail/trunk/CHANGES.txt
  U   zope.sendmail/trunk/buildout.cfg
  U   zope.sendmail/trunk/setup.py
  U   zope.sendmail/trunk/src/zope/sendmail/tests/test_vocabulary.py
  U   zope.sendmail/trunk/src/zope/sendmail/zcml.py

-=-
Modified: zope.sendmail/trunk/CHANGES.txt
===================================================================
--- zope.sendmail/trunk/CHANGES.txt	2009-12-18 20:20:51 UTC (rev 106771)
+++ zope.sendmail/trunk/CHANGES.txt	2009-12-18 20:27:54 UTC (rev 106772)
@@ -5,7 +5,10 @@
 3.6.2 (unreleased)
 ------------------
 
-- ...
+- Removed dependency on ``zope.security``: the security support is optional,
+  and only available if the ``zope.security`` package is available. This change
+  is similar to the optional security support introduced in ``zope.component``
+  3.8.0, and in fact it uses the same helpers.
 
 3.6.1 (2009-11-16)
 ------------------

Modified: zope.sendmail/trunk/buildout.cfg
===================================================================
--- zope.sendmail/trunk/buildout.cfg	2009-12-18 20:20:51 UTC (rev 106771)
+++ zope.sendmail/trunk/buildout.cfg	2009-12-18 20:27:54 UTC (rev 106772)
@@ -4,7 +4,7 @@
 
 [test]
 recipe = zc.recipe.testrunner
-eggs = zope.sendmail
+eggs = zope.sendmail [test]
 
 [coverage-test]
 recipe = zc.recipe.testrunner

Modified: zope.sendmail/trunk/setup.py
===================================================================
--- zope.sendmail/trunk/setup.py	2009-12-18 20:20:51 UTC (rev 106771)
+++ zope.sendmail/trunk/setup.py	2009-12-18 20:27:54 UTC (rev 106772)
@@ -34,28 +34,23 @@
           open('README.txt').read(),
           open('CHANGES.txt').read(),
           ]),
-
       packages=find_packages('src'),
-      package_dir = {'': 'src'},
-
+      package_dir={'': 'src'},
       namespace_packages=['zope',],
-      tests_require = ['zope.testing'],
+      tests_require=['zope.security',
+                     'zope.testing',
+                    ],
+      extras_require=dict(test=['zope.security',
+                                'zope.testing']),
       install_requires=['setuptools',
                         '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>=3.8.0',
-
                         # these are only needed for zcml
                         'zope.configuration',
-                        'zope.security',
-
                        ],
       include_package_data = True,
       zip_safe = False,

Modified: zope.sendmail/trunk/src/zope/sendmail/tests/test_vocabulary.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/tests/test_vocabulary.py	2009-12-18 20:20:51 UTC (rev 106771)
+++ zope.sendmail/trunk/src/zope/sendmail/tests/test_vocabulary.py	2009-12-18 20:27:54 UTC (rev 106772)
@@ -16,7 +16,7 @@
 $Id$
 """
 import unittest
-from zope.testing.doctestunit import DocTestSuite
+from zope.testing.doctest import DocTestSuite
 from zope.component.testing import setUp, tearDown
 
 def test_suite():

Modified: zope.sendmail/trunk/src/zope/sendmail/zcml.py
===================================================================
--- zope.sendmail/trunk/src/zope/sendmail/zcml.py	2009-12-18 20:20:51 UTC (rev 106771)
+++ zope.sendmail/trunk/src/zope/sendmail/zcml.py	2009-12-18 20:27:54 UTC (rev 106772)
@@ -18,22 +18,33 @@
 __docformat__ = 'restructuredtext'
 
 from zope.component import queryUtility
-from zope.component.zcml import handler, proxify
+from zope.component.zcml import handler
 from zope.configuration.fields import Path
 from zope.configuration.exceptions import ConfigurationError
 from zope.interface import Interface
 from zope.schema import TextLine, BytesLine, Int
-from zope.security.checker import InterfaceChecker, CheckerPublic
-from zope.security.zcml import Permission
 
 from zope.sendmail.delivery import QueuedMailDelivery, DirectMailDelivery
 from zope.sendmail.delivery import QueueProcessorThread
 from zope.sendmail.interfaces import IMailer, IMailDelivery
 from zope.sendmail.mailer import SMTPMailer
 
+try:
+    from zope.component.security import proxify
+    from zope.security.zcml import Permission
+except ImportError:
+    SECURITY_SUPPORT = False
+    from zope.schema import TextLine as Permission
+else:
+    SECURITY_SUPPORT = True
+
 def _assertPermission(permission, interfaces, component):
+    if not SECURITY_SUPPORT:
+        raise ConfigurationError("security proxied components are not "
+            "supported because zope.security is not available")
     return proxify(component, provides=interfaces, permission=permission)
 
+
 class IDeliveryDirective(Interface):
     """This abstract directive describes a generic mail delivery utility
     registration."""
@@ -45,17 +56,17 @@
         default=u"Mail",
         required=False)
 
-    permission = Permission(
-        title=u"Permission",
-        description=u"Defines the permission needed to use this service.",
-        required=True)
-
     mailer = TextLine(
         title=u"Mailer",
         description=u"Defines the mailer to be used for sending mail.",
         required=True)
 
+    permission = Permission(
+        title=u"Permission",
+        description=u"Defines the permission needed to use this service.",
+        required=False)
 
+
 class IQueuedDeliveryDirective(IDeliveryDirective):
     """This directive creates and registers a global queued mail utility. It
     should be only called once during startup."""
@@ -65,11 +76,12 @@
         description=u"Defines the path for the queue directory.",
         required=True)
 
-def queuedDelivery(_context, permission, queuePath, mailer, name="Mail"):
+def queuedDelivery(_context, queuePath, mailer, permission=None, name="Mail"):
 
     def createQueuedDelivery():
         delivery = QueuedMailDelivery(queuePath)
-        delivery = _assertPermission(permission, IMailDelivery, delivery)
+        if permission is not None:
+            delivery = _assertPermission(permission, IMailDelivery, delivery)
 
         handler('registerUtility', delivery, IMailDelivery, name)
 
@@ -91,7 +103,7 @@
     """This directive creates and registers a global direct mail utility. It
     should be only called once during startup."""
 
-def directDelivery(_context, permission, mailer, name="Mail"):
+def directDelivery(_context, mailer, permission=None, name="Mail"):
 
     def createDirectDelivery():
         mailerObject = queryUtility(IMailer, mailer)
@@ -99,7 +111,8 @@
             raise ConfigurationError("Mailer %r is not defined" %mailer)
 
         delivery = DirectMailDelivery(mailerObject)
-        delivery = _assertPermission(permission, IMailDelivery, delivery)
+        if permission is not None:
+            delivery = _assertPermission(permission, IMailDelivery, delivery)
 
         handler('registerUtility', delivery, IMailDelivery, name)
 



More information about the checkins mailing list