diff --git a/tconfpy.py b/tconfpy.py index 8286970..4d0af68 100755 --- a/tconfpy.py +++ b/tconfpy.py @@ -6,7 +6,7 @@ # Program Information PROGNAME = "tconfpy" -RCSID = "$Id: tconfpy.py,v 1.187 2005/01/13 20:45:50 tundra Exp $" +RCSID = "$Id: tconfpy.py,v 1.188 2005/01/13 22:08:37 tundra Exp $" VERSION = RCSID.split()[2] # Copyright Information @@ -169,37 +169,37 @@ class SymbolTable(object): - Symbols = {} - DebugMsgs = [] - ErrMsgs = [] - WarnMsgs = [] - LiteralLines = [] - ALLOWNEWVAR = True - TEMPLATES = {} - TEMPONLY = False - LITERALVARS = False - INLITERAL = False - DEBUG = False - CondStack = [["", True],] # Always has one entry as a sentinel - TotalLines = 0 + def __init__(self): + self.Symbols = {} + self.DebugMsgs = [] + self.ErrMsgs = [] + self.WarnMsgs = [] + self.LiteralLines = [] + self.Templates = Template() + self.ALLOWNEWVAR = True + self.TEMPONLY = False + self.LITERALVARS = False + self.INLITERAL = False + self.DEBUG = False + self.CondStack = [["", True],] # Always has one entry as a sentinel + self.TotalLines = 0 # End of class 'SymbolTable' +# A Template is essentially a minimalist symbol table + +class Template(object): + + def __init__(self): + self.Symbols = {} + +# End of class 'Template' + # The descriptor is an object with the following attributes # # Value, Writeable, Type, Default, LegalVals = [list of legal vals], Min, Max] - -# -# Legal Variable Types - -TYPE_BOOL = type(True) -TYPE_COMPLEX = type(1-1j) -TYPE_FLOAT = type(3.14) -TYPE_INT = type(1) -TYPE_STRING = type('s') - # Object to hold full description and options for a given variable class VarDescriptor(object): @@ -216,19 +216,15 @@ # End of class 'VarDescriptor' +# Legal Variable Types + +TYPE_BOOL = type(True) +TYPE_COMPLEX = type(1-1j) +TYPE_FLOAT = type(3.14) +TYPE_INT = type(1) +TYPE_STRING = type('s') - -SymTable = SymbolTable() - -for var in Predefined.keys(): - - d = VarDescriptor() - d.Value = Predefined[var] - d.Writeable = False - SymTable.Symbols[var] = d - - ########## # Error, Warning, And Debug Message Strings Stored In A Global Dictionary ########## @@ -406,7 +402,7 @@ CallingProgram=PROGINFO, InitialSymTable=SymbolTable(), AllowNewVars=True, - Templates={}, + Templates=Template(), TemplatesOnly=False, LiteralVars=False, ReturnPredefs=True, @@ -418,19 +414,29 @@ mkmsg.proginfo = CallingProgram - # Create a new symbol table + # Create and initialize a new symbol table SymTable = SymbolTable() # Initialize the globals SymTable.ALLOWNEWVAR = AllowNewVars - SymTable.TEMPLATES = Templates + SymTable.Templates = Templates SymTable.TEMPONLY = TemplatesOnly SymTable.LITERALVARS = LiteralVars SymTable.INLITERAL = False SymTable.DEBUG = Debug + # Load the predefines symbols + + for var in Predefined.keys(): + + d = VarDescriptor() + d.Value = Predefined[var] + d.Writeable = False + SymTable.Symbols[var] = d + + # Add any passed symbols to the SymbolTable @@ -1174,11 +1180,11 @@ # Rule 1 - if varname in SymTable.TEMPLATES: + if varname in SymTable.Templates.Symbols: # Create the new variable - SymTable.Symbols[l] = SymTable.TEMPLATES[varname] + SymTable.Symbols[l] = SymTable.Templates.Symbols[varname] # Load the proposed value only if valid @@ -1448,6 +1454,7 @@ __all__ = ["ParseConfig", "SymbolTable", + "Template", "TYPE_BOOL", "TYPE_COMPLEX", "TYPE_FLOAT",