diff --git a/tconfpy.py b/tconfpy.py index 2fe034c..cee5692 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.135 2004/03/24 11:09:07 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.136 2004/03/24 22:25:47 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -90,7 +90,7 @@ # Regular Expressions -reVARREF = r"\%s.+?\%s" % (DELIML, DELIMR) # Variable reference +reVARREF = r"\%s.*\%s" % (DELIML, DELIMR) # Variable reference VarRef = re.compile(reVARREF) @@ -161,7 +161,7 @@ self.Writeable = True self.Type = TYPE_STRING self.Default = "" - self.LegalVals = None + self.LegalVals = [] self.Min = None self.Max = None @@ -378,7 +378,7 @@ if NAMESPACE not in SymTable: SymTable[NAMESPACE] = VarDescriptor() SymTable[NAMESPACE].Value = "" - SymTable[NAMESPACE].LegalVals = [""] + SymTable[NAMESPACE].LegalVals.append("") # Parse the file @@ -427,7 +427,7 @@ sym = var[1:-1] # Strip delimiters # Handle environment variables - if sym[0] == ENVIRO and sym[1:] in os.environ: + if sym and sym[0] == ENVIRO and sym[1:] in os.environ: line = line.replace(var, os.getenv(sym[1:])) # Handle variables in symbol table @@ -443,6 +443,7 @@ # Attempts to reference undefined variables are legitimate # in this case and ought not to generate an error message. + if reporterr: ErrorMsg("eVARUNDEF", (cfgfile, linenum, sym)) @@ -593,10 +594,15 @@ # Namespace Processing ##### - if len(VarRef.findall(line)) == 1 and line[0] == DELIML and line[-1] == DELIMR: + if (len(VarRef.findall(line)) == 1 and line[0] == DELIML and line[-1] == DELIMR): + + # Set the new namespace ns = line[1:-1] SymTable[NAMESPACE].Value = ns - SymTable[NAMESPACE].LegalVals.append(ns) + + # Save newly seen namespaces in list of legal vals + if ns not in SymTable[NAMESPACE].LegalVals: + SymTable[NAMESPACE].LegalVals.append(ns) ##### @@ -774,6 +780,7 @@ l = line[:e].strip() r = line[e+1:].strip() + # Suppress any attempt to change a RO variable if l in SymTable and not SymTable[l].Writeable: @@ -783,21 +790,32 @@ # Load variable into the symbol table else: + # Munge the variable name to incoroprate # the current namespace # Handle absolute variable references - if l[0] == NSSEP: + if l.startswith(NSSEP): l = l[1:] - # The NAMESPACE variable is special - leave it alone + # The NAMESPACE variable is special - It is presumed to reset + # the top level namespace. + elif l == NAMESPACE: - pass + # Save the new namespace + SymTable[NAMESPACE].Value = r - # Prepend current namespace + # Add to unique list of namespaces seen + if r not in SymTable[NAMESPACE].LegalVals: + SymTable[NAMESPACE].LegalVals.append(r) + + # In all other cases prepend current namespace else: ns = SymTable[NAMESPACE].Value - l = "%s%s%s" % (ns, NSSEP, l) + + # Top level namespace variables don't need separator + if ns: + l = "%s%s%s" % (ns, NSSEP, l) d = VarDescriptor() @@ -814,11 +832,6 @@ else: SymTable[l].Value = r - # And keep track of any namespace changes - - ns = SymTable[NAMESPACE].Value - if ns not in SymTable[l].LegalVals: - SymTable[l].LegalVals.append(ns) ##### # Line Format Is Not In One Of The Recognized Forms - Syntax Error