[Zodb-checkins] CVS: Zope3/src/ZConfig - __init__.py:1.10 cfgparser.py:1.8

Fred L. Drake, Jr. fred at zope.com
Fri Aug 1 17:42:06 EDT 2003


Update of /cvs-repository/Zope3/src/ZConfig
In directory cvs.zope.org:/tmp/cvs-serv9177

Modified Files:
	__init__.py cfgparser.py 
Log Message:
Provide location information for failed substitutions.

=== Zope3/src/ZConfig/__init__.py 1.9 => 1.10 ===
--- Zope3/src/ZConfig/__init__.py:1.9	Thu May  1 15:34:56 2003
+++ Zope3/src/ZConfig/__init__.py	Fri Aug  1 16:41:59 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)


=== Zope3/src/ZConfig/cfgparser.py 1.7 => 1.8 ===
--- Zope3/src/ZConfig/cfgparser.py:1.7	Tue Jan 14 10:16:55 2003
+++ Zope3/src/ZConfig/cfgparser.py	Fri Aug  1 16:41:59 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)




More information about the Zodb-checkins mailing list