[Zope3-checkins] CVS: Packages/ZConfig - loader.py:1.4 schema.py:1.6

Fred L. Drake, Jr. fred@zope.com
Tue, 7 Jan 2003 01:27:44 -0500


Update of /cvs-repository/Packages/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv15032

Modified Files:
	loader.py schema.py 
Log Message:
Very preliminary implementation of a schema component library.
Not ready for deployment.


=== Packages/ZConfig/loader.py 1.3 => 1.4 ===
--- Packages/ZConfig/loader.py:1.3	Fri Jan  3 17:37:05 2003
+++ Packages/ZConfig/loader.py	Tue Jan  7 01:27:08 2003
@@ -14,6 +14,7 @@
 """Schema loader utility."""
 
 import os.path
+import sys
 import urllib
 import urllib2
 
@@ -30,6 +31,8 @@
     False = 0
 
 
+LIBRARY_DIR = os.path.join(sys.prefix, "lib", "zconfig")
+
 RESOURCE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                             "resources")
 
@@ -114,12 +117,15 @@
 
 
 class SchemaLoader(BaseLoader):
-    def __init__(self, registry=None):
+    def __init__(self, registry=None, library=None):
         if registry is None:
             registry = datatypes.Registry()
+        BaseLoader.__init__(self)
         self.registry = registry
         self._cache = {}
-        BaseLoader.__init__(self)
+        if library is None:
+            library = LIBRARY_DIR
+        self._library = library
 
     def loadResource(self, resource):
         if resource.url and self._cache.has_key(resource.url):
@@ -136,6 +142,31 @@
     def allowFragments(self):
         return True
 
+    # schema parser support API
+
+    def schemaPackageURLs(self, package):
+        parts = package.split(".")
+        if not parts:
+            raise ZConfig.SchemaError(
+                "illegal schema component name: " + `package`)
+        if len(filter(None, parts)) != len(parts):
+            # '' somewhere in the package spec; still illegal
+            raise ZConfig.SchemaError(
+                "illegal schema component name: " + `package`)
+        dirname = os.path.join(self._library, *parts)
+        fn = os.path.join(dirname, "schema.xml")
+        if not os.path.exists(fn):
+            raise ZConfig.SchemaError(
+                "schema component not found: " + `package`)
+        urls = [fn]
+        for fn in os.listdir(dirname):
+            if fn == "schema.xml":
+                continue
+            path = os.path.join(dirname, fn, "schema.xml")
+            if os.path.exists(path):
+                urls.append(path)
+        return urls
+
 
 class ConfigLoader(BaseLoader):
     def __init__(self, schema):
@@ -151,7 +182,7 @@
         self._parse_resource(sm, resource)
         return sm.finish(), CompositeHandler(self.handlers, self.schema)
 
-    # parser support API
+    # config parser support API
 
     def startSection(self, parent, type, name, delegatename):
         if delegatename:


=== Packages/ZConfig/schema.py 1.5 => 1.6 ===
--- Packages/ZConfig/schema.py:1.5	Mon Jan  6 17:30:18 2003
+++ Packages/ZConfig/schema.py	Tue Jan  7 01:27:08 2003
@@ -129,8 +129,9 @@
                 self.error("import src many not include a fragment identifier")
             urls = [src]
         else:
-            raise NotImpementedError(
-                "<import package='...'/> not yet implemented")
+            urls = self._loader.schemaPackageURLs(pkg)
+            if not urls:
+                self.error("could not locate schema component " + `pkg`)
         for s in urls:
             schema = self._loader.loadURL(s)
             for n in schema.gettypenames():