diff --git a/tconfpy.py b/tconfpy.py index 13d20a6..88bde63 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.167 2004/04/08 22:56:37 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.168 2004/04/13 21:40:07 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -262,10 +262,11 @@ # Messages -Messages["dLINEIGNORE"] = FILENUM + " '%s' " + PTR + "%s\n" +Messages["dLINEIGNORE"] = FILENUM + " '%s'" + PTR + "%s\n" Messages["dNAMESPACE"] = FILENUM + "Setting Current Namespace To: '%s'" Messages["dNUMLINES"] = "Processing File '%s' Resulted In %d Total Lines Parsed" Messages["dPARSEDLINE"] = FILENUM + " '%s'" + PTR + "'%s'\n" +Messages["dVARREF"] = FILENUM + "Variable Dereference: '%s'" + PTR + "'%s'" ########### @@ -306,11 +307,11 @@ Messages["eVALSMALL"] = FILENUM + "%s Is Smaller Than The Minimum Allowed, %s, For Variable '%s'" Messages["eVARNAMESPC"] = FILENUM + "Variable Names May Not Contain Whitespace" Messages["eVARHASDELIM"] = FILENUM + "Variable Names May Not Include The '%s' Or '%s' Characters" % (DELIML, DELIMR) +Messages["eVARILLEGAL"] = FILENUM + "'%s' Is An Illegal Variable Name Here. Begins With '%s' Symbol" Messages["eVARNEW"] = FILENUM + "New Variable Creation Not Permitted" Messages["eVARNONAME"] = FILENUM + "Variable Name Evaluates To Null String. Not Permitted" Messages["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" Messages["eVARREFNEST"] = FILENUM + "Nested Variable References Are Not Permitted" -Messages["eVARRESERVED"] = FILENUM + "Variable Name Cannot Begin With The '%s' Symbol" Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -608,25 +609,41 @@ return line, ref_ok # By default, all variable names assumed to be relative to - # current namespace context unless escaped with NSSEP - - # Look for an escape - - if sym and sym[0] == NSSEP: - sym = sym[1:] + # current namespace unless escaped with NSSEP. + # However, environment variables and predefined variables + # are always presumed to be relative to the top-level + # namespace and are left untouched here. - # Prepend the current namespace for all but the top level + if sym not in Predefined and sym[0] != ENVIRO: + + # Look for an escape. This makes the variable + # reference "absolute" (relative to the top-level namespace). - elif SymTable[NAMESPACE].Value: - sym = "%s%s%s" % (SymTable[NAMESPACE].Value, NSSEP, sym) + if sym and sym[0] == NSSEP: + sym = sym[1:] + + # Prepend the current namespace unless we are in the top-level + # namespace. + + elif SymTable[NAMESPACE].Value: + sym = "%s%s%s" % (SymTable[NAMESPACE].Value, NSSEP, sym) # Handle environment variables if sym and sym[0] == ENVIRO and sym[1:] in os.environ: - line = line.replace(var, os.getenv(sym[1:])) + envvar = os.getenv(sym[1:]) + line = line.replace(var, envvar) + if DEBUG: + DebugMsg("dVARREF", (cfgfile, linenum, var, envvar)) + # Handle variables in symbol table elif sym in SymTable: - line = line.replace(var, str(SymTable[sym].Value)) + symval = str(SymTable[sym].Value) + line = line.replace(var, symval) + + if DEBUG: + DebugMsg("dVARREF", (cfgfile, linenum, var, symval)) + # Reference to undefined variable else: @@ -1088,14 +1105,20 @@ elif l.count(DELIML) or l.count(DELIMR): ErrorMsg("eVARHASDELIM", (cfgfile, linenum)) - # Suppress attempts to set variables named starting - # with certain reserved symbols because dereferencing - # such variable names is impossible - - elif l[0] in (COMMENT, ENVIRO): - ErrorMsg("eVARRESERVED", (cfgfile, linenum, l[0])) - # Suppress any attempt to change a RO variable + + # ***NOTE*** + # + # This test needs to happen here before any of the + # namespace stuff below. Doing it here guarantees we + # catch an attempt to modify one of the Predefined or + # Reserved variables, which are always marked RO and are + # always relative to the top-level namespace. This way, + # we don't have to put in an explicit check to ignore + # Predefined and Reserved variables in the namespace + # munging below. IOW, Don't move this test down into the + # body of the variable name processing where namespace + # fiddling takes place. elif l in SymTable and not SymTable[l].Writeable: ErrorMsg("eVARREADONLY", (cfgfile, linenum, l)) @@ -1142,7 +1165,10 @@ ns = SymTable[NAMESPACE].Value # Top level namespace variables don't need separator - if ns: + # Also, make sure the variable name does not begin with ENVIRO introducer. + # If it does, do nothing, and we'll catch the error below. + + if ns and l[0] != ENVIRO: l = "%s%s%s" % (ns, NSSEP, l) d = VarDescriptor() @@ -1153,8 +1179,12 @@ if l not in SymTable: + # Make sure the variable name does not begin with ENVIRO introducer + if l[0] == ENVIRO: + ErrorMsg("eVARILLEGAL", (cfgfile, linenum, l, ENVIRO)) + # Only do this if new variable creation allowed - if ALLOWNEWVAR: + elif ALLOWNEWVAR: d.Default = r d.Value = r SymTable[l] = d