[Zope3-checkins] CVS: Zope/lib/python/ZConfig - __init__.py:1.9.22.1 cfgparser.py:1.7.52.1 substitution.py:1.2.54.1
Chris McDonough
chrism@zope.com
Sat, 2 Aug 2003 01:07:26 -0400
Update of /cvs-repository/Zope/lib/python/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv11382
Modified Files:
Tag: Zope-2_7-branch
__init__.py cfgparser.py substitution.py
Log Message:
Merge case preservation/lineno reporting to 2.7 branch.
=== Zope/lib/python/ZConfig/__init__.py 1.9 => 1.9.22.1 ===
--- Zope/lib/python/ZConfig/__init__.py:1.9 Thu May 1 15:34:56 2003
+++ Zope/lib/python/ZConfig/__init__.py Sat Aug 2 01:07:20 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)
=== Zope/lib/python/ZConfig/cfgparser.py 1.7 => 1.7.52.1 ===
--- Zope/lib/python/ZConfig/cfgparser.py:1.7 Tue Jan 14 10:16:55 2003
+++ Zope/lib/python/ZConfig/cfgparser.py Sat Aug 2 01:07:20 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)
=== Zope/lib/python/ZConfig/substitution.py 1.2 => 1.2.54.1 ===
--- Zope/lib/python/ZConfig/substitution.py:1.2 Fri Jan 3 16:05:51 2003
+++ Zope/lib/python/ZConfig/substitution.py Sat Aug 2 01:07:20 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