[Zope3-checkins] CVS: Zope3/src/zope/configuration - config.py:1.16 interfaces.py:1.5 xmlconfig.py:1.20

Marius Gedminas marius at pov.lt
Mon Mar 1 08:26:20 EST 2004


Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv15998/src/zope/configuration

Modified Files:
	config.py interfaces.py xmlconfig.py 
Log Message:
Detect ZCML files that are imported more than once and produce a brief and
clear error message about it.  Without this duplicate imports cause a (large)
number of conflict errors, and reading 1000+ line error messages is not fun for
the end user.



=== Zope3/src/zope/configuration/config.py 1.15 => 1.16 ===
--- Zope3/src/zope/configuration/config.py:1.15	Fri Jan 23 11:59:38 2004
+++ Zope3/src/zope/configuration/config.py	Mon Mar  1 08:25:47 2004
@@ -20,6 +20,7 @@
 
 import os.path
 import sys
+import sets
 
 import zope.schema
 
@@ -88,6 +89,10 @@
 
     """
 
+    def __init__(self):
+        super(ConfigurationContext, self).__init__()
+        self._seen_files = sets.Set()
+
     def resolve(self, dottedname):
         """Resolve a dotted name to an object
 
@@ -237,6 +242,39 @@
 
         return os.path.join(basepath, filename)
 
+    def checkDuplicate(self, filename):
+        """Check for duplicate imports of the same file.
+
+        Raises an exception if this file had been processed before.  This
+        is better than an unlimited number of conflict errors.
+
+        >>> c = ConfigurationContext()
+        >>> c.checkDuplicate('/foo.zcml')
+        >>> c.checkDuplicate('/foo.zcml')
+        Traceback (most recent call last):
+        ...
+        ConfigurationError: '/foo.zcml' included more than once
+
+        You may use different ways to refer to the same file:
+
+        >>> import zope.configuration
+        >>> c.package = zope.configuration
+        >>> import os
+        >>> d = os.path.split(zope.configuration.__file__)[0]
+        >>> c.checkDuplicate('bar.zcml')
+        >>> try:
+        ...   c.checkDuplicate(d + os.path.normpath('/bar.zcml'))
+        ... except ConfigurationError, e:
+        ...   str(e).endswith("bar.zcml' included more than once")
+        ...
+        True
+
+        """
+        path = self.path(filename)
+        if path in self._seen_files:
+            raise ConfigurationError('%r included more than once' % path)
+        self._seen_files.add(path)
+
     def action(self, discriminator, callable=None, args=(), kw={}):
         """Add an action with the given discriminator, callable and arguments
 
@@ -333,6 +371,7 @@
 
 
     def __init__(self):
+        super(ConfigurationAdapterRegistry, self).__init__()
         self._registry = {}
         # Stores tuples of form: (namespace, name), schema, usedIn, info, parent
         self._docRegistry = []


=== Zope3/src/zope/configuration/interfaces.py 1.4 => 1.5 ===
--- Zope3/src/zope/configuration/interfaces.py:1.4	Fri Jan 23 11:59:38 2004
+++ Zope3/src/zope/configuration/interfaces.py	Mon Mar  1 08:25:47 2004
@@ -60,6 +60,13 @@
         file name is returned.
         """
 
+    def checkDuplicate(filename):
+        """Check for duplicate imports of the same file.
+
+        Raises an exception if this file had been processed before.  This
+        is better than an unlimited number of conflict errors.
+        """
+
     def action(self, discriminator, callable, args=(), kw={}):
         """Record a configuration action
 


=== Zope3/src/zope/configuration/xmlconfig.py 1.19 => 1.20 ===
--- Zope3/src/zope/configuration/xmlconfig.py:1.19	Tue Feb 24 09:07:58 2004
+++ Zope3/src/zope/configuration/xmlconfig.py	Mon Mar  1 08:25:47 2004
@@ -319,12 +319,13 @@
 
     logger.debug("include %s" % file)
 
-    # This is a tad tricky. We want to behave a a grouping directive.
+    # This is a tad tricky. We want to behave as a grouping directive.
     context = config.GroupingContextDecorator(_context)
     if package is not None:
         context.package = package
         context.basepath = None
     path = context.path(file)
+    context.checkDuplicate(path)
     f = openInOrPlain(path)
 
     logger.debug("include %s" % f.name)




More information about the Zope3-Checkins mailing list