Cleaned up all manner of bugs having to do with variable names
containing whitespace and references involving them.

Added explicit check for nested variable references.
1 parent 82f3b45 commit 0492aec0f9873342084836ade3f5a16c4528f2e5
@tundra tundra authored on 8 Apr 2004
Showing 1 changed file
View
57
tconfpy.py
 
# Program Information
 
PROGNAME = "tconfpy"
RCSID = "$Id: tconfpy.py,v 1.165 2004/04/08 17:11:09 tundra Exp $"
RCSID = "$Id: tconfpy.py,v 1.166 2004/04/08 22:46:52 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
 
 
# Regular Expressions
 
reVARWHITE = r".*\s+.*"
reVARILLEGAL = r"\%s(%s)%s" % (DELIML, reVARWHITE, DELIMR) # Variable reference with spaces in it
reVARREF = r"\%s.+?\%s" % (DELIML, DELIMR) # Variable reference
 
VarWhite = re.compile(reVARWHITE)
VarIllegal = re.compile(reVARILLEGAL)
VarRef = re.compile(reVARREF)
reVARWHITE = r".*\s+.*" # Look for embedded whitespace
reVARREF = r"\%s.+?\%s" % (DELIML, DELIMR) # Variable reference
 
VarWhite = re.compile(reVARWHITE)
VarRef = re.compile(reVARREF)
 
 
 
###########
# Literals
Messages["eENDIFEXTRA"] = FILENUM + "'" + ENDIF + "' Without Matching Condition"
Messages["eENDIFMISS"] = FILENUM + "Missing %d" + " '%s' " % ENDIF + " Statement(s)"
Messages["eEQUIVEXTRA"] = FILENUM + "Only a single '%s' Or '%s' Operator Permitted" % (EQUIV, NOTEQUIV)
Messages["eIFEXTRATXT"] = FILENUM + "Extra Text On Line. '%s' Only Accepts Variable References As Arguments"
Messages["eNAMESPACENEW"] = FILENUM + "New Namespace Creation Not Permitted. Current Namespace Unchanged: '%s'"
Messages["eNOTLEGALVAL"] = FILENUM + "'%s' Not Found In List Of Legal Values For Variable '%s'"
Messages["eNAMESPACENEW"] = FILENUM + "New Namespace Creation Not Permitted. Current Namespace Unchanged: '%s'"
Messages["eSTRINGLONG"] = FILENUM + "Right-Hand-Side Too Long. '%s' Must Be No More Than %s Characters Long"
Messages["eSTRINGSHORT"] = FILENUM + "Right-Hand-Side Too Short. '%s' Must Be At Least %s Characters Long"
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["eVARRESERVED"] = FILENUM + "Variable Name Cannot Begin With The '%s' Symbol"
Messages["eVARNAMESPC"] = FILENUM + "Variable Names May Not Contain Whitespace"
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'"
 
 
###########
for var in VarRef.findall(line):
 
sym = var[1:-1] # Strip delimiters
 
# Do some preliminary tests to validate variable names
# Make sure there is no whitespace in the variable reference
 
if VarWhite.match(sym):
ErrorMsg("eVARNAMESPC", (cfgfile, linenum))
ref_ok = False
 
# Look for evidence of attempts to nest variable references
 
if sym.count(DELIML) or sym.count(DELIMR):
ErrorMsg("eVARREFNEST", (cfgfile, linenum))
ref_ok = False
# If Preliminary tests found errors - quit now
if not ref_ok:
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 DEBUG:
DebugMsg("dLINEIGNORE", (cfgfile, linenum, orig, dNOTINCLUDE))
return
 
# Catch attempts to use whitespace within variable names or references
 
if VarIllegal.findall(line) or VarWhite.findall(line.split(EQUAL)[0].strip()):
ErrorMsg("eVARNAMESPC", (cfgfile, linenum))
return
 
# Catch attempts to dereference without name
 
if line.count(DELIML + DELIMR):
ErrorMsg("eVARNONAME", (cfgfile, linenum))
 
if DEBUG:
DebugMsg("dPARSEDLINE", (cfgfile, linenum, orig, line))
 
return
# Do any necessary variable dereferencing
line, ref_ok = DerefVar(line, cfgfile, linenum)
l = line[:e].strip()
r = line[e+1:].strip()
 
 
# Make sure the variable name has no spaces in it
 
if VarWhite.match(l):
ErrorMsg("eVARNAMESPC", (cfgfile, linenum))
 
# Suppress attempts to set null-named variables
 
if not l:
elif not l:
ErrorMsg("eVARNONAME", (cfgfile, linenum))
# Suppress attempts to set variables named starting
# with certain reserved symbols because dereferencing