[Zope3-checkins] CVS: Packages/ZConfig - Substitution.py:1.10

Fred L. Drake, Jr. fred@zope.com
Wed, 4 Dec 2002 17:49:02 -0500


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

Modified Files:
	Substitution.py 
Log Message:
Clean out a bunch of the ZConfig.Substitution module that is no longer
useful now that %define and substitution is built into the basic handling
of the configuration files.


=== Packages/ZConfig/Substitution.py 1.9 => 1.10 ===
--- Packages/ZConfig/Substitution.py:1.9	Wed Dec  4 15:59:13 2002
+++ Packages/ZConfig/Substitution.py	Wed Dec  4 17:48:31 2002
@@ -5,69 +5,25 @@
 except NameError:
     False = 0
 
-class SubstitutionError(Exception):
-    """Base exception for string substitution errors."""
+class SubstitutionSyntaxError(Exception):
+    """Raised when interpolation source text contains syntactical errors."""
 
-    def __init__(self, msg, context):
+    def __init__(self, msg):
         self.message = msg
-        if context is not None:
-            context = context[:]
-        self.context = context
 
     def __str__(self):
         return self.message
 
-class SubstitutionSyntaxError(SubstitutionError):
-    """Raised when interpolation source text contains syntactical errors."""
-
-    def __init__(self, msg, context):
-        SubstitutionError.__init__(self, msg, context)
-
-class SubstitutionRecursionError(SubstitutionError):
-    """Raised when a nested interpolation is recursive."""
-
-    def __init__(self, name, context):
-        self.name = name
-        msg = ("recursion on %s; current context:\n%s"
-               % (repr(name), ", ".join(context)))
-        SubstitutionError.__init__(self, msg, context)
-
-
-def get(section, name, default=None):
-    # XXX should this interpolate from default if that's what's used?
-    missing = []
-    s = section.get(name, missing)
-    if s is missing:
-        return default
-    if "$" in s:
-        accum = []
-        _interp(accum, s, section, [name])
-        s = ''.join(accum)
-    return s
-
 
-def substitute(s, section):
+def substitute(s, mapping):
     """Interpolate variables from `section` into `s`."""
     if "$" in s:
         accum = []
-        _interp(accum, s, section, None)
+        _interp(accum, s, mapping)
         s = ''.join(accum)
     return s
 
 
-def getnames(s):
-    """Return a list of names referenced by s."""
-    if "$" in s:
-        L = []
-        while s:
-            p, name, s = _split(s, None)
-            if name and name not in L:
-                L.append(name)
-        return L
-    else:
-        return []
-
-
 def isname(s):
     """Return True iff s is a valid substitution name."""
     m = _name_match(s)
@@ -77,33 +33,19 @@
         return False
 
 
-def _interp(accum, rest, section, context):
+def _interp(accum, rest, mapping):
     while 1:
-        s, name, rest = _split(rest, context)
+        s, name, rest = _split(rest)
         if s:
             accum.append(s)
         if name:
-            v = section.get(name)
-            if v is None:
-                parent = getattr(section, "container", None)
-                while parent is not None:
-                    v = parent.get(name)
-                    if v is not None:
-                        break
-                    parent = getattr(parent, "container", None)
-                else:
-                    v = ""
-            if "$" in v and context:
-                if name in context:
-                    raise SubstitutionRecursionError(name, context)
-                _interp(accum, v, section, context + [name])
-            else:
-                accum.append(v)
+            v = mapping.get(name, "")
+            accum.append(v)
         if not rest:
             return
 
 
-def _split(s, context):
+def _split(s):
     # 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
@@ -120,13 +62,12 @@
         if c == "{":
             m = _name_match(s, i + 2)
             if not m:
-                raise SubstitutionSyntaxError("'${' not followed by name",
-                                              context)
+                raise SubstitutionSyntaxError("'${' not followed by name")
             name = m.group(0)
             i = m.end() + 1
             if not s.startswith("}", i - 1):
                 raise SubstitutionSyntaxError(
-                    "'${%s' not followed by '}'" % name, context)
+                    "'${%s' not followed by '}'" % name)
         else:
             m = _name_match(s, i+1)
             if not m: