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

Jim Fulton jim@zope.com
Thu, 20 Jun 2002 11:54:08 -0400


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

Modified Files:
	xmlconfig.py 
Log Message:
Added the option of passing a module to XMLConfig. This makes it much
easier to use configuration files from test scripts. In addition, it
made it possible to run against a file "as if" it had been included,
which is important to make the shortened dotten names work correctly.


=== Zope3/lib/python/Zope/Configuration/xmlconfig.py 1.4 => 1.5 ===
         """ % ((self.des,) + self.l1 + self.l2)
         
-_unset = object()
 class Context:
-    def __init__(self, stack, module=_unset):
+    def __init__(self, stack, module=None):
         self.__stackcopy = tuple(stack)
-        if module is _unset:
+        if module is None:
             self.__package = None
         elif module is None:
             self.__package = 'ZopeProducts'
@@ -256,14 +255,21 @@
     
 class XMLConfig:
 
-    def __init__(self, file_name):
+    def __init__(self, file_name, module=None):
+        if module is not None:
+            module_dir = os.path.split(module.__file__)[0]
+            file_name = os.path.join(module_dir, file_name)
+
+        
         self._actions = []
         self._directives = {('http://namespaces.zope.org/zope', 'include'):
                             (self.include, {})}
 
         f = open(file_name)
         self._stack = [file_name]
-        xmlconfig(f, self._actions, Context(self._stack), self._directives)
+        xmlconfig(f, self._actions,
+                  Context(self._stack, module=module),
+                  self._directives)
         f.close()
 
     def include(self, _context, file='configure.zcml', package=None):