[Zope-Checkins] CVS: Zope3/lib/python/Zope/Configuration - xmlconfig.py:1.4

Steve Alexander steve@cat-box.net
Tue, 18 Jun 2002 09:07:30 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Configuration
In directory cvs.zope.org:/tmp/cvs-serv10827/lib/python/Zope/Configuration

Modified Files:
	xmlconfig.py 
Log Message:
fixed the include directive to use the package of the zcml file it was
included from.
This doesn't apply to "root" zcml files (such as site.zcml), where no
package has been defined.


=== Zope3/lib/python/Zope/Configuration/xmlconfig.py 1.3 => 1.4 ===
         and% at line %s column %s of %s
         """ % ((self.des,) + self.l1 + self.l2)
-
+        
+_unset = object()
 class Context:
-    def __init__(self, stack, module=None):
+    def __init__(self, stack, module=_unset):
         self.__stackcopy = tuple(stack)
-        if module is None:
+        if module is _unset:
+            self.__package = None
+        elif module is None:
             self.__package = 'ZopeProducts'
         else:
             self.__package = module.__name__
@@ -195,7 +198,12 @@
         else:
             raise TypeError, "Unrecognized config file attribute: %s" % name
 
-
+    def packageWasSet(self):
+        return self.__package is not None
+        
+    def package(self):
+        return self.__package
+        
 def xmlconfig(file, actions=None, context=None, directives=None,
               testing=0):
     if context is None:
@@ -259,6 +267,8 @@
         f.close()
 
     def include(self, _context, file='configure.zcml', package=None):
+        if package is None and _context.packageWasSet():
+            package = _context.package()
         if package is not None:
             try:
                 package = _context.resolve(package)
@@ -277,7 +287,7 @@
                                  % (package, `v`))
         else:
             prefix = os.path.dirname(self._stack[-1])
-            
+
         file_name = os.path.join(prefix, file)
 
         f = open(file_name)