diff --git a/tconfpy.py b/tconfpy.py index 09a5f73..670cf13 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.145 2004/03/25 06:21:11 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.146 2004/03/25 07:03:20 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -233,6 +233,7 @@ # Messages Messages["eBADCOND"] = FILENUM + "Bad '%s' Directive. %s" +Messages["eBADREGEX"] = FILENUM + "Bad Regular Expression, '%s', In Legal Values List For Variable '%s'" Messages["eBADSYNTAX"] = FILENUM + "Syntax Error. Statement Not In Known Form" Messages["eCONFOPEN"] = FILENUM + "Cannot Open The File '%s'" Messages["eDESCRIPTBAD"] = "API Error: %s For Variable '%s'" @@ -240,13 +241,14 @@ 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["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" +Messages["eNOTLEGALVAL"] = FILENUM + "'%s' Not Found In List Of Legal Values For Variable '%s'" Messages["eRESERVED"] = FILENUM + "Cannot Modify Value Of Reserved Symbol '%s'" -Messages["eSTRINGLONG"] = FILENUM + "Right-Hand-Side, '%s' Longer Than Max Allowed Length, %s" -Messages["eSTRINGSHORT"] = FILENUM + "Right-Hand-Side, '%s' Shorter Than Min Allowed Length, %s" +Messages["eSTRINGLONG"] = FILENUM + "Right-Hand-Side, '%s' Longer Than Max Allowed Length, %s, For Variable '%s'" +Messages["eSTRINGSHORT"] = FILENUM + "Right-Hand-Side, '%s' Shorter Than Min Allowed Length, %s, For Variable '%s'" Messages["eTYPEBAD"] = FILENUM + "Type Mismatch. '%s' Must Be Assigned Values Of Type %s Only" -Messages["eVALSMALL"] = FILENUM + "%s Is Smaller Than The Minimum Allowed, %s" -Messages["eVALLARGE"] = FILENUM + "%s Is Larger Than The Maximum Allowed, %s" +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["eVARREADONLY"] = FILENUM + "Variable '%s' Is Read-Only. Cannot Change Its Value" Messages["eVARUNDEF"] = FILENUM + "Attempt To Reference Undefined Variable '%s'" @@ -944,6 +946,46 @@ update = False ErrorMsg("eTYPEBAD", (cfgfile, linenum, l, str(typ).split()[1][:-1])) + + ##### + # Legal Values Enforcement + ##### + + # These tests valid for everything except booleans. + # An empty LegalVals list means this test is skipped. + # For all numeric types, the test is to see if the new + # value is one of the ones enumerated in LegalVals. + # + # For strings, LegalVals is presumed to contain a list + # of regular expressions. The test is to compile each + # regex and see if any match the new value. + + if update and lv: + + if typ in (TYPE_COMPLEX, TYPE_FLOAT, TYPE_INT): + if r not in lv: + ErrorMsg("eNOTLEGALVAL", (cfgfile, linenum, r, l)) + update = False + + elif typ == TYPE_STRING: + + foundmatch = False + for rex in lv: + try: + rexc=re.compile(rex) + if rexc.match(r): + foundmatch = True + + except: + ErrorMsg("eBADREGEX", (cfgfile, linenum, rex, l)) + update = False + + if not foundmatch: + ErrorMsg("eNOTLEGALVAL", (cfgfile, linenum, r, l)) + update = False + + + ##### # Bounds Checks ##### @@ -953,11 +995,11 @@ if update and typ in (TYPE_FLOAT, TYPE_INT): if low != None and r < low: - ErrorMsg("eVALSMALL", (cfgfile, linenum, r, low)) + ErrorMsg("eVALSMALL", (cfgfile, linenum, r, low, l)) update = False if up != None and r > up: - ErrorMsg("eVALLARGE", (cfgfile, linenum, r, up)) + ErrorMsg("eVALLARGE", (cfgfile, linenum, r, up, l)) update = False # Check bounds for strings - these are min/max string lengths, if present @@ -965,11 +1007,11 @@ if update and typ == TYPE_STRING: if low != None and len(r) < low: - ErrorMsg("eSTRINGSHORT", (cfgfile, linenum, r, low)) + ErrorMsg("eSTRINGSHORT", (cfgfile, linenum, r, low, l)) update = False if up != None and len(r) > up: - ErrorMsg("eSTRINGLONG", (cfgfile, linenum, r, up)) + ErrorMsg("eSTRINGLONG", (cfgfile, linenum, r, up, l)) update = False