Fixed bug that prevented environment variables from being derefenced.
Removed unnecessary validation checks in variable assignment code.
1 parent f063bb5 commit fc4ff9cbbcdcb0de5b0166b585dc71aecfb209c5
@tundra tundra authored on 14 Apr 2004
Showing 1 changed file
View
39
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.172 2004/04/14 21:23:35 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.173 2004/04/14 22:18:39 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
PREDEFINTRO + "PYTHONVERSION" : platform.python_version()
}
 
 
# Symbols Illegal As First Character Of Variable/Namespace Name
 
IllegalStart = (ENVIRO)
 
# Symbols Illegal Anywhere In A Variable/Namespace Name
 
IllegalChars = (DELIML, DELIMR, COMMENT)
 
Messages["eSYMNONAME"] = FILENUM + "Symbol Name Evaluates To Null String. Not Permitted"
Messages["eTYPEBAD"] = FILENUM + "Type Mismatch. '%s' Must Be Assigned Values Of Type %s Only"
Messages["eVALLARGE"] = FILENUM + "%s Is Larger Than The Maximum Allowed, %s, For Variable '%s'"
Messages["eVALSMALL"] = FILENUM + "%s Is Smaller Than The Minimum Allowed, %s, For Variable '%s'"
Messages["eVARILLEGAL"] = FILENUM + "'%s' Is An Illegal Variable Name Here. Begins With '%s' Symbol"
Messages["eVARNEW"] = FILENUM + "New Variable Creation Not Permitted"
Messages["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value"
Messages["eVARREFNEST"] = FILENUM + "Nested Variable References Are Not Permitted"
Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'"
sym = var[1:-1] # Strip delimiters
 
# Make sure symbol name is properly formed
 
ref_ok = ValidateSymbolName(sym, cfgfile, linenum)
ref_ok = ValidateSymbolName(sym, cfgfile, linenum, AllowEnviro=True)
# If Preliminary tests found errors - quit now
if not ref_ok:
if not ALLOWNEWNS and r != SymTable[NAMESPACE].Value and r not in SymTable[NAMESPACE].LegalVals:
ErrorMsg("eNAMESPACENEW", (cfgfile, linenum, SymTable[NAMESPACE].Value))
update = False
# Make sure the new namespace does not start with
# an illegal character.
# Make sure the new namespace is properly formed
elif not ValidateSymbolName(r, cfgfile, linenum, AllowEmpty=True):
update = False # Validation function issues relevant error messages
 
else:
ns = SymTable[NAMESPACE].Value
 
# Top level namespace variables don't need
# separator Also, make sure the variable name does
# not begin with an illegal character. If it
# does, do nothing, and we'll catch the error
# below.
# separator.
if ns and l[0] not in IllegalStart:
if ns:
l = "%s%s%s" % (ns, NSSEP, l)
 
d = VarDescriptor()
 
# create the new entry
 
if l not in SymTable:
 
# Make sure the variable name does not begin with
# an illegal character.
if l[0] in IllegalStart:
ErrorMsg("eVARILLEGAL", (cfgfile, linenum, l, l[0]))
 
# Only do this if new variable creation allowed
elif ALLOWNEWVAR:
if ALLOWNEWVAR:
d.Default = r
d.Value = r
SymTable[l] = d
 
#####
# Ensure Symbol Name Is Properly Formed
#####
 
def ValidateSymbolName(sym, cfgfile, linenum, AllowEmpty=False):
def ValidateSymbolName(sym, cfgfile, linenum, AllowEmpty=False, AllowEnviro=False):
 
sym_ok = True
 
# Check for whitespace
ErrorMsg("eSYMNONAME", (cfgfile, linenum))
sym_ok = False
 
# Check for illegal starting symbol
 
if sym and sym[0] in IllegalStart:
# Check for illegal ENVIRO introducer
 
if not AllowEnviro and sym and sym[0] == ENVIRO:
ErrorMsg("eSYMBADSTART", (cfgfile, linenum, sym))
sym_ok = False
 
# Check for illegal characters in symbol name