[Zope3-checkins] SVN: Zope3/trunk/src/zope/configuration/ Changed
the include directive so that it can be used multiple times
Jim Fulton
jim at zope.com
Sat May 15 22:08:08 EDT 2004
Log message for revision 24733:
Changed the include directive so that it can be used multiple times
for the same file. This allows a package to include configurations it
depends on from other files.
-=-
Modified: Zope3/trunk/src/zope/configuration/config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/config.py 2004-05-16 01:58:37 UTC (rev 24732)
+++ Zope3/trunk/src/zope/configuration/config.py 2004-05-16 02:08:07 UTC (rev 24733)
@@ -291,6 +291,40 @@
raise ConfigurationError('%r included more than once' % path)
self._seen_files.add(path)
+ def processFile(self, filename):
+ """Check whether a file needs to be processed
+
+ Return True if processing is needed and False otherwise. If
+ the file needs to be processed, it will be marked as
+ processed, assuming that the caller will procces the file if
+ it needs to be procssed.
+
+ >>> c = ConfigurationContext()
+ >>> c.processFile('/foo.zcml')
+ True
+ >>> c.processFile('/foo.zcml')
+ False
+
+ 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.processFile('bar.zcml')
+ True
+ >>> c.processFile('bar.zcml')
+ False
+
+ """ #' <-- bow to font-lock
+ path = self.path(filename)
+ if path in self._seen_files:
+ return False
+ self._seen_files.add(path)
+ return True
+
+
+
def action(self, discriminator, callable=None, args=(), kw={}):
"""Add an action with the given discriminator, callable and arguments
Modified: Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py 2004-05-16 01:58:37 UTC (rev 24732)
+++ Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py 2004-05-16 02:08:07 UTC (rev 24733)
@@ -229,17 +229,19 @@
>>> [clean_path(p) for p in data.includepath]
['tests/samplepackage/configure.zcml']
- Including the same file more than once produces an error:
- >>> try:
- ... xmlconfig.include(context, 'configure.zcml', package)
- ... except xmlconfig.ConfigurationError, e:
- ... 'OK'
- ...
- 'OK'
-
"""
+# Not any more
+## Including the same file more than once produces an error:
+
+## >>> try:
+## ... xmlconfig.include(context, 'configure.zcml', package)
+## ... except xmlconfig.ConfigurationError, e:
+## ... 'OK'
+## ...
+## 'OK'
+
def test_include_by_file():
"""
>>> context = config.ConfigurationMachine()
Modified: Zope3/trunk/src/zope/configuration/xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/xmlconfig.py 2004-05-16 01:58:37 UTC (rev 24732)
+++ Zope3/trunk/src/zope/configuration/xmlconfig.py 2004-05-16 02:08:07 UTC (rev 24733)
@@ -357,20 +357,19 @@
paths = [context.path(file)]
for path in paths:
- context.checkDuplicate(path)
+ if context.processFile(path):
+ f = openInOrPlain(path)
+ logger.debug("include %s" % f.name)
- f = openInOrPlain(path)
- logger.debug("include %s" % f.name)
+ context.basepath = os.path.split(path)[0]
+ context.includepath = _context.includepath + (f.name, )
+ _context.stack.append(config.GroupingStackItem(context))
- context.basepath = os.path.split(path)[0]
- context.includepath = _context.includepath + (f.name, )
- _context.stack.append(config.GroupingStackItem(context))
+ processxmlfile(f, context)
+ f.close()
+ assert _context.stack[-1].context is context
+ _context.stack.pop()
- processxmlfile(f, context)
- f.close()
- assert _context.stack[-1].context is context
- _context.stack.pop()
-
def includeOverrides(_context, file, package=None):
"""Include zcml file containing overrides
More information about the Zope3-Checkins
mailing list