[Zodb-checkins] CVS: Packages/ZConfig - Context.py:1.15.10.5 __init__.py:1.3.10.3 loader.py:1.1.2.3

Fred L. Drake, Jr. fred@zope.com
Tue, 10 Dec 2002 14:50:05 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	Context.py __init__.py loader.py 
Log Message:
load() and loadfile() are now called loadURL() and loadFile(), to be more
consistent with the other names used.

More refactoring of resource handling; the loadURL() and loadFile() methods
are each only implemented once!  loadResource() is the specialized method.


=== Packages/ZConfig/Context.py 1.15.10.4 => 1.15.10.5 ===
--- Packages/ZConfig/Context.py:1.15.10.4	Tue Dec 10 13:50:11 2002
+++ Packages/ZConfig/Context.py	Tue Dec 10 14:50:03 2002
@@ -35,24 +35,10 @@
         from ZConfig.cfgparser import ZConfigParser
         ZConfigParser(resource, self).parse(section)
 
-    # public API
-
-    def load(self, url):
-        """Load a resource from a URL or pathname."""
-        url = self.normalizeURL(url)
-        top = self.createToplevelSection(url)
-        self._all_sections.append(top)
-        self._parse_url(url, top)
-        self._finish()
-        return top
-
-    def loadfile(self, file, url=None):
-        if not url:
-            url = self._url_from_file(file)
-        top = self.createToplevelSection(url)
+    def loadResource(self, resource):
+        top = self.createToplevelSection(resource.url)
         self._all_sections.append(top)
-        r = self.createResource(file, url)
-        self.parse(r, top)
+        self.parse(resource, top)
         self._finish()
         return top
 
@@ -98,17 +84,6 @@
         return newsect
 
     # internal helpers
-
-    def _parse_url(self, url, section):
-        url, fragment = urlparse.urldefrag(url)
-        if fragment:
-            raise ZConfig.ConfigurationError(
-                "fragment identifiers are not currently supported")
-        r = self.openResource(url)
-        try:
-            self.parse(r, section)
-        finally:
-            r.close()
 
     def _finish(self):
         # Resolve section delegations


=== Packages/ZConfig/__init__.py 1.3.10.2 => 1.3.10.3 ===
--- Packages/ZConfig/__init__.py:1.3.10.2	Tue Dec 10 14:16:49 2002
+++ Packages/ZConfig/__init__.py	Tue Dec 10 14:50:03 2002
@@ -16,21 +16,21 @@
 $Id$
 """
 
-def load(url):
+def loadURL(url):
     import Context
-    return Context.Context().load(url)
+    return Context.Context().loadURL(url)
 
-def loadfile(file, url=None):
+def loadFile(file, url=None):
     import Context
-    return Context.Context().loadfile(file, url)
+    return Context.Context().loadFile(file, url)
 
-def loadschema(url):
+def loadSchema(url):
     import loader
-    return loader.SchemaLoader().load(url)
+    return loader.SchemaLoader().loadURL(url)
 
-def loadschemafile(file, url=None):
+def loadSchemaFile(file, url=None):
     import loader
-    return loader.SchemaLoader().loadfile(file, url)
+    return loader.SchemaLoader().loadFile(file, url)
 
 
 class ConfigurationError(Exception):


=== Packages/ZConfig/loader.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/loader.py:1.1.2.2	Tue Dec 10 11:28:03 2002
+++ Packages/ZConfig/loader.py	Tue Dec 10 14:50:03 2002
@@ -21,14 +21,16 @@
     def createResource(self, file, url):
         return Resource(file, url)
 
-    def load(self, url):
-        pass
+    def loadURL(self, url):
+        url = self.normalizeURL(url)
+        r = self.openResource(url)
+        return self.loadResource(r)
 
-    def loadfile(self, file, url=None):
+    def loadFile(self, file, url=None):
         if not url:
-            name = getattr(file, "name", None)
-            if name and name[0] != "<" and name[-1] != ">":
-                url = "file://" + urllib.pathname2url(os.path.abspath(name))
+            url = self._url_from_file(file)
+        r = self.createResource(file, url)
+        return self.loadResource(r)
 
     # utilities
 
@@ -44,6 +46,11 @@
             if not parts[0]:
                 raise ValueError("invalid URL, or file does not exist:\n"
                                  + repr(url))
+        if url:
+            url, fragment = urlparse.urldefrag(url)
+            if fragment:
+                raise ZConfig.ConfigurationError(
+                    "fragment identifiers are not currently supported")
         return url
 
     def _url_from_file(self, file):
@@ -55,21 +62,19 @@
 
 
 class SchemaLoader(BaseLoader):
-    def load(self, url):
-        url = self.normalizeURL(url)
-        r = self.openResource(url)
-        return self._load_resource(r)
-
-    def loadfile(self, file, url=None):
-        if not url:
-            url = self._url_from_file(file)
-        r = self.createResource(file, url)
-        return self._load_resource(r)
-
-    def _load_resource(self, resource):
+    def loadResource(self, resource):
         from SchemaParser import SchemaParser
         parser = SchemaParser()
         return parser.parseStream(resource.file)
+
+
+class ConfigLoader(BaseLoader):
+    def __init__(self, schema):
+        BaseLoader.__init__(self)
+        self.schema = schema
+
+    def loadResource(self, resource):
+        raise NotImpementedError
 
 
 class Resource: