[Zope-Checkins] CVS: ZODB3/ZConfig - substitution.py:1.2.54.3 schema.py:1.20.22.3 loader.py:1.18.44.3 info.py:1.15.12.3 datatypes.py:1.13.36.3 cfgparser.py:1.7.52.3 __init__.py:1.9.22.3

Jeremy Hylton jeremy at zope.com
Fri Sep 19 17:24:52 EDT 2003


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

Modified Files:
      Tag: Zope-2_7-branch
	substitution.py schema.py loader.py info.py datatypes.py 
	cfgparser.py __init__.py 
Log Message:
Remove changes made during merge of ZODB3-3_2-branch.


=== ZODB3/ZConfig/substitution.py 1.2.54.2 => 1.2.54.3 ===
--- ZODB3/ZConfig/substitution.py:1.2.54.2	Mon Sep 15 14:03:00 2003
+++ ZODB3/ZConfig/substitution.py	Fri Sep 19 17:24:51 2003
@@ -23,17 +23,17 @@
 
 
 def substitute(s, mapping):
-    """Interpolate variables from `section` into `s`."""
+    """Interpolate variables from `mapping` into `s`."""
     if "$" in s:
         result = ''
         rest = s
         while rest:
-            p, name, rest = _split(rest)
+            p, name, namecase, rest = _split(rest)
             result += p
             if name:
                 v = mapping.get(name)
                 if v is None:
-                    raise ZConfig.SubstitutionReplacementError(s, name)
+                    raise ZConfig.SubstitutionReplacementError(s, namecase)
                 result += v
         return result
     else:
@@ -50,9 +50,10 @@
 
 
 def _split(s):
-    # Return a triple:  prefix, name, suffix
+    # Return a four tuple:  prefix, name, namecase, 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:
@@ -62,7 +63,7 @@
             raise ZConfig.SubstitutionSyntaxError(
                 "illegal lone '$' at end of source")
         if c == "$":
-            return s[:i+1], None, s[i+2:]
+            return s[:i+1], None, None, s[i+2:]
         prefix = s[:i]
         if c == "{":
             m = _name_match(s, i + 2)
@@ -81,9 +82,9 @@
                     "'$' not followed by '$' or name")
             name = m.group(0)
             i = m.end()
-        return prefix, name.lower(), s[i:]
+        return prefix, name.lower(), name, s[i:]
     else:
-        return s, None, None
+        return s, None, None, None
 
 
 import re


=== ZODB3/ZConfig/schema.py 1.20.22.2 => 1.20.22.3 ===
--- ZODB3/ZConfig/schema.py:1.20.22.2	Mon Sep 15 14:03:00 2003
+++ ZODB3/ZConfig/schema.py	Fri Sep 19 17:24:51 2003
@@ -13,6 +13,7 @@
 ##############################################################################
 """Parser for ZConfig schemas."""
 
+import os
 import xml.sax
 
 import ZConfig
@@ -279,44 +280,39 @@
     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:
-            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,
+            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,
                                  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
@@ -525,23 +521,4 @@
         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.2 => 1.18.44.3 ===
--- ZODB3/ZConfig/loader.py:1.18.44.2	Mon Sep 15 14:03:00 2003
+++ ZODB3/ZConfig/loader.py	Fri Sep 19 17:24:51 2003
@@ -137,7 +137,7 @@
 
     # schema parser support API
 
-    def schemaComponentInfo(self, package):
+    def schemaComponentSource(self, package, file):
         parts = package.split(".")
         if not parts:
             raise ZConfig.SchemaError(
@@ -146,23 +146,16 @@
             # '' 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, "component.xml")
+            fn = os.path.join(dirname, file)
             if os.path.exists(fn):
                 break
         else:
             raise ZConfig.SchemaError(
                 "schema component not found: " + `package`)
-        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
+        return "file://" + urllib.pathname2url(fn)
 
 
 class ConfigLoader(BaseLoader):
@@ -186,7 +179,8 @@
 
     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.2 => 1.15.12.3 ===
--- ZODB3/ZConfig/info.py:1.15.12.2	Mon Sep 15 14:03:01 2003
+++ ZODB3/ZConfig/info.py	Fri Sep 19 17:24:51 2003
@@ -355,7 +355,9 @@
                     pass
                 else:
                     return info
-        raise ZConfig.ConfigurationError("no matching section defined")
+        raise ZConfig.ConfigurationError(
+            "no matching section defined for type='%s', name='%s'" % (
+            type, name))
 
     def isabstract(self):
         return False


=== ZODB3/ZConfig/datatypes.py 1.13.36.2 => 1.13.36.3 ===
--- ZODB3/ZConfig/datatypes.py:1.13.36.2	Mon Sep 15 14:03:01 2003
+++ ZODB3/ZConfig/datatypes.py	Fri Sep 19 17:24:51 2003
@@ -111,14 +111,13 @@
         RegularExpressionConversion.__init__(self, "[_a-zA-Z][_a-zA-Z0-9]*")
 
 
-if sys.version[:3] < "2.3":
-    def integer(value):
-        try:
-            return int(value)
-        except ValueError:
-            return long(value)
-else:
-    integer = int
+def integer(value):
+    try:
+        return int(value)
+    except ValueError:
+        return long(value)
+    except OverflowError:
+        return long(value)
 
 
 def null_conversion(value):
@@ -209,10 +208,10 @@
     raise ValueError, '%s is not an existing file' % v
 
 def existing_dirpath(v):
-    if not os.path.split(v)[0]:
-        # relative pathname
-        return v
     dir = os.path.dirname(v)
+    if not dir:
+        # relative pathname with no directory component
+        return 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.2 => 1.7.52.3 ===
--- ZODB3/ZConfig/cfgparser.py:1.7.52.2	Mon Sep 15 14:03:01 2003
+++ ZODB3/ZConfig/cfgparser.py	Fri Sep 19 17:24:51 2003
@@ -128,7 +128,7 @@
         if not value:
             value = ''
         else:
-            value = substitute(value, self.defs)
+            value = self.replace(value)
         try:
             section.addValue(key, value, (self.lineno, None, self.url))
         except ZConfig.ConfigurationError, e:
@@ -164,7 +164,15 @@
             self.error("cannot redefine " + `defname`)
         if not isname(defname):
             self.error("not a substitution legal name: " + `defname`)
-        self.defs[defname] = substitute(defvalue, self.defs)
+        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
 
     def error(self, message):
         raise ZConfig.ConfigurationSyntaxError(message, self.url, self.lineno)


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




More information about the Zope-Checkins mailing list