[Zope-Checkins] CVS: Zope3/lib/python/Zope/Configuration - xmlconfig.py:1.1.2.5
Casey Duncan
casey_duncan@yahoo.com
Fri, 1 Feb 2002 15:13:31 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Configuration
In directory cvs.zope.org:/tmp/cvs-serv8446
Modified Files:
Tag: Zope-3x-branch
xmlconfig.py
Log Message:
Added package attribute to include directive for including on zcml file in
another via a file path relative to the package.
=== Zope3/lib/python/Zope/Configuration/xmlconfig.py 1.1.2.4 => 1.1.2.5 ===
# FOR A PARTICULAR PURPOSE.
+import name
from xml.sax import make_parser
from xml.sax.xmlreader import InputSource
from xml.sax.handler import ContentHandler, feature_namespaces
@@ -177,8 +178,24 @@
self._stack=[file_name]
xmlconfig(f, self._actions, tuple(self._stack), self._directives)
- def include(self, file):
- file_name = os.path.join(os.path.dirname(self._stack[-1]), file)
+ def include(self, file, package=None):
+ if package is not None:
+ try:
+ module = name.resolve(package)
+ if len(module.__path__) != 1:
+ print ("Module Path: '%s' has wrong number of elements" % str(module.__path__))
+ # XXX: This should work for 99% of cases
+ # We may want to revisit this with a more robust
+ # mechanism later. Specifically, sometimes __path__
+ # will have more than one element. Also, we could
+ # use module.__file__, and lop the tail off that.
+ prefix = module.__path__[0]
+ except (ImportError, AttributeError, ValueError):
+ raise ValueError, "Invalid package attribute: %s" % package
+ else:
+ prefix = os.path.dirname(self._stack[-1])
+
+ file_name = os.path.join(prefix, file)
f = open(file_name)
self._stack.append(file_name)