[Zodb-checkins] CVS: ZODB3/ZConfig - substitution.py:1.2.54.2 schema.py:1.20.22.2 loader.py:1.18.44.2 info.py:1.15.12.2 datatypes.py:1.13.36.2 cfgparser.py:1.7.52.2 __init__.py:1.9.22.2

Jeremy Hylton jeremy at zope.com
Mon Sep 15 14:03:44 EDT 2003


Update of /cvs-repository/ZODB3/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv13599/ZConfig

Modified Files:
      Tag: Zope-2_7-branch
	substitution.py schema.py loader.py info.py datatypes.py 
	cfgparser.py __init__.py 
Log Message:
Take two: Merge changes from ZODB3-3_2-branch to Zope-2_7-branch.

Please make all future changes on the Zope-2_7-branch instead.

The previous attempt used "cvs up -j ZODB3-3_2-branch", but appeared
to get only a small fraction of the changes.  This attempt is based on
copying a checkout of ZODB3-3_2-branch over top of a checkout of
Zope-2_7-branch.


=== ZODB3/ZConfig/substitution.py 1.2.54.1 => 1.2.54.2 ===
--- ZODB3/ZConfig/substitution.py:1.2.54.1	Sat Aug  2 01:07:20 2003
+++ ZODB3/ZConfig/substitution.py	Mon Sep 15 14:03:00 2003
@@ -23,17 +23,17 @@
 
 
 def substitute(s, mapping):
-    """Interpolate variables from `mapping` into `s`."""
+    """Interpolate variables from `section` into `s`."""
     if "$" in s:
         result = ''
         rest = s
         while rest:
-            p, name, namecase, rest = _split(rest)
+            p, name, rest = _split(rest)
             result += p
             if name:
                 v = mapping.get(name)
                 if v is None:
-                    raise ZConfig.SubstitutionReplacementError(s, namecase)
+                    raise ZConfig.SubstitutionReplacementError(s, name)
                 result += v
         return result
     else:
@@ -50,10 +50,9 @@
 
 
 def _split(s):
-    # Return a four tuple:  prefix, name, namecase, suffix
+    # Return a triple:  prefix, name, suffix
     # - prefix is text that can be used literally in the result (may be '')
     # - name is a referenced name, or None
-    # - namecase is the name with case preserved
     # - suffix is trailling text that may contain additional references
     #   (may be '' or None)
     if "$" in s:
@@ -63,7 +62,7 @@
             raise ZConfig.SubstitutionSyntaxError(
                 "illegal lone '$' at end of source")
         if c == "$":
-            return s[:i+1], None, None, s[i+2:]
+            return s[:i+1], None, s[i+2:]
         prefix = s[:i]
         if c == "{":
             m = _name_match(s, i + 2)
@@ -82,9 +81,9 @@
                     "'$' not followed by '$' or name")
             name = m.group(0)
             i = m.end()
-        return prefix, name.lower(), name, s[i:]
+        return prefix, name.lower(), s[i:]
     else:
-        return s, None, None, None
+        return s, None, None
 
 
 import re


=== ZODB3/ZConfig/schema.py 1.20.22.1 => 1.20.22.2 ===
--- ZODB3/ZConfig/schema.py:1.20.22.1	Mon Jul 21 12:36:51 2003
+++ ZODB3/ZConfig/schema.py	Mon Sep 15 14:03:00 2003
@@ -13,7 +13,6 @@
 ##############################################################################
 """Parser for ZConfig schemas."""
 
-import os
 import xml.sax
 
 import ZConfig
@@ -280,39 +279,44 @@
     def start_import(self, attrs):
         src = attrs.get("src", "").strip()
         pkg = attrs.get("package", "").strip()
-        file = attrs.get("file", "").strip()
         if not (src or pkg):
             self.error("import must specify either src or package")
         if src and pkg:
             self.error("import may only specify one of src or package")
         if src:
-            if file:
-                self.error("import may not specify file and src")
             src = url.urljoin(self._url, src)
             src, fragment = url.urldefrag(src)
             if fragment:
-                self.error("import src many not include"
-                           " a fragment identifier")
+                self.error("import src many not include a fragment identifier")
             schema = self._loader.loadURL(src)
             for n in schema.gettypenames():
                 self._schema.addtype(schema.gettype(n))
+        elif self._components.has_key(pkg):
+            # already loaded, or in progress
+            pass
         else:
-            if os.path.dirname(file):
-                self.error("file may not include a directory part")
-            src = self._loader.schemaComponentSource(pkg, file)
-            if not self._components.has_key(src):
-                self._components[pkg] = src
-                self.loadComponent(src)
-
-    def loadComponent(self, src):
-        r = self._loader.openResource(src)
-        parser = ComponentParser(self._registry, self._loader, src,
+            pi = self._loader.schemaComponentInfo(pkg)
+            if not pi:
+                self.error("could not locate schema component " + `pkg`)
+            self._components[pkg] = pi
+            self.loadComponent(pi)
+
+    def loadComponent(self, info):
+        base, extensions = info
+        r = self._loader.openResource(base)
+        parser = ComponentParser(self._registry, self._loader, base,
                                  self._schema)
         parser._components = self._components
         try:
             xml.sax.parse(r.file, parser)
         finally:
             r.close()
+        for ext in extensions:
+            r = self._loader.openResource(ext)
+            try:
+                parser.loadExtension(r)
+            finally:
+                r.close()
 
     def end_import(self):
         pass
@@ -521,4 +525,23 @@
         self.push_prefix(attrs)
 
     def end_component(self):
+        self.pop_prefix()
+
+    def loadExtension(self, resource):
+        parser = ExtensionParser(self._registry, self._loader, resource.url,
+                                 self._parent, self._localtypes)
+        parser._components = self._components
+        xml.sax.parse(resource.file, parser)
+
+
+class ExtensionParser(BaseComponentParser):
+
+    _handled_tags = BaseComponentParser._handled_tags + ("extension",)
+    _top_level = "extension"
+
+    def start_extension(self, attrs):
+        self._schema = self._parent
+        self.push_prefix(attrs)
+
+    def end_extension(self):
         self.pop_prefix()


=== ZODB3/ZConfig/loader.py 1.18.44.1 => 1.18.44.2 ===
--- ZODB3/ZConfig/loader.py:1.18.44.1	Mon Jul 21 12:36:51 2003
+++ ZODB3/ZConfig/loader.py	Mon Sep 15 14:03:00 2003
@@ -137,7 +137,7 @@
 
     # schema parser support API
 
-    def schemaComponentSource(self, package, file):
+    def schemaComponentInfo(self, package):
         parts = package.split(".")
         if not parts:
             raise ZConfig.SchemaError(
@@ -146,16 +146,23 @@
             # '' somewhere in the package spec; still illegal
             raise ZConfig.SchemaError(
                 "illegal schema component name: " + `package`)
-        file = file or "component.xml"
         for dir in sys.path:
             dirname = os.path.join(os.path.abspath(dir), *parts)
-            fn = os.path.join(dirname, file)
+            fn = os.path.join(dirname, "component.xml")
             if os.path.exists(fn):
                 break
         else:
             raise ZConfig.SchemaError(
                 "schema component not found: " + `package`)
-        return "file://" + urllib.pathname2url(fn)
+        url = "file://" + urllib.pathname2url(fn)
+        extensions = []
+        for fn in os.listdir(dirname):
+            if fn == "component.xml":
+                continue
+            path = os.path.join(dirname, fn, "extension.xml")
+            if os.path.exists(path):
+                extensions.append("file://" + urllib.pathname2url(path))
+        return url, extensions
 
 
 class ConfigLoader(BaseLoader):
@@ -179,8 +186,7 @@
 
     def startSection(self, parent, type, name, delegatename):
         if delegatename:
-            raise NotImpementedError(
-                "section delegation is not yet supported")
+            raise NotImpementedError("section delegation is not yet supported")
         t = self.schema.gettype(type)
         if t.isabstract():
             raise ZConfig.ConfigurationError(


=== ZODB3/ZConfig/info.py 1.15.12.1 => 1.15.12.2 ===
--- ZODB3/ZConfig/info.py:1.15.12.1	Sat Aug  2 13:11:58 2003
+++ ZODB3/ZConfig/info.py	Mon Sep 15 14:03:01 2003
@@ -355,9 +355,7 @@
                     pass
                 else:
                     return info
-        raise ZConfig.ConfigurationError(
-            "no matching section defined for type='%s', name='%s'" % (
-            type, name))
+        raise ZConfig.ConfigurationError("no matching section defined")
 
     def isabstract(self):
         return False


=== ZODB3/ZConfig/datatypes.py 1.13.36.1 => 1.13.36.2 ===
--- ZODB3/ZConfig/datatypes.py:1.13.36.1	Mon Jul 21 12:36:51 2003
+++ ZODB3/ZConfig/datatypes.py	Mon Sep 15 14:03:01 2003
@@ -111,13 +111,14 @@
         RegularExpressionConversion.__init__(self, "[_a-zA-Z][_a-zA-Z0-9]*")
 
 
-def integer(value):
-    try:
-        return int(value)
-    except ValueError:
-        return long(value)
-    except OverflowError:
-        return long(value)
+if sys.version[:3] < "2.3":
+    def integer(value):
+        try:
+            return int(value)
+        except ValueError:
+            return long(value)
+else:
+    integer = int
 
 
 def null_conversion(value):
@@ -208,10 +209,10 @@
     raise ValueError, '%s is not an existing file' % v
 
 def existing_dirpath(v):
-    dir = os.path.dirname(v)
-    if not dir:
-        # relative pathname with no directory component
+    if not os.path.split(v)[0]:
+        # relative pathname
         return v
+    dir = os.path.dirname(v)
     if os.path.isdir(dir):
         return v
     raise ValueError, ('The directory named as part of the path %s '


=== ZODB3/ZConfig/cfgparser.py 1.7.52.1 => 1.7.52.2 ===
--- ZODB3/ZConfig/cfgparser.py:1.7.52.1	Sat Aug  2 01:07:20 2003
+++ ZODB3/ZConfig/cfgparser.py	Mon Sep 15 14:03:01 2003
@@ -128,7 +128,7 @@
         if not value:
             value = ''
         else:
-            value = self.replace(value)
+            value = substitute(value, self.defs)
         try:
             section.addValue(key, value, (self.lineno, None, self.url))
         except ZConfig.ConfigurationError, e:
@@ -164,15 +164,7 @@
             self.error("cannot redefine " + `defname`)
         if not isname(defname):
             self.error("not a substitution legal name: " + `defname`)
-        self.defs[defname] = self.replace(defvalue)
-
-    def replace(self, text):
-        try:
-            return substitute(text, self.defs)
-        except ZConfig.SubstitutionReplacementError, e:
-            e.lineno = self.lineno
-            e.url = self.url
-            raise
+        self.defs[defname] = substitute(defvalue, self.defs)
 
     def error(self, message):
         raise ZConfig.ConfigurationSyntaxError(message, self.url, self.lineno)


=== ZODB3/ZConfig/__init__.py 1.9.22.1 => 1.9.22.2 ===
--- ZODB3/ZConfig/__init__.py:1.9.22.1	Sat Aug  2 01:07:20 2003
+++ ZODB3/ZConfig/__init__.py	Mon Sep 15 14:03:01 2003
@@ -115,11 +115,10 @@
     """Raised when interpolation source text contains syntactical errors."""
 
 
-class SubstitutionReplacementError(ConfigurationSyntaxError, LookupError):
+class SubstitutionReplacementError(ConfigurationError, LookupError):
     """Raised when no replacement is available for a reference."""
 
-    def __init__(self, source, name, url=None, lineno=None):
+    def __init__(self, source, name):
         self.source = source
         self.name = name
-        ConfigurationSyntaxError.__init__(
-            self, "no replacement for " + `name`, url, lineno)
+        ConfigurationError.__init__(self, "no replacement for " + `name`)




More information about the Zodb-checkins mailing list