From de8326d00dffdb500c02839a98330b869c2457f3 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sat, 22 Dec 2018 09:28:48 -0800 Subject: Trim trailing white space throughout the project Many editors clean up trailing white space on save. By removing it all in one go, it helps keep future diffs cleaner by avoiding spurious white space changes on unrelated lines. --- examples/configParse.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'examples/configParse.py') diff --git a/examples/configParse.py b/examples/configParse.py index 769249c..db7b6c7 100644 --- a/examples/configParse.py +++ b/examples/configParse.py @@ -15,7 +15,7 @@ import pprint inibnf = None def inifile_BNF(): global inibnf - + if not inibnf: # punctuation @@ -23,24 +23,24 @@ def inifile_BNF(): rbrack = Literal("]").suppress() equals = Literal("=").suppress() semi = Literal(";") - + comment = semi + Optional( restOfLine ) - + nonrbrack = "".join( [ c for c in printables if c != "]" ] ) + " \t" nonequals = "".join( [ c for c in printables if c != "=" ] ) + " \t" - + sectionDef = lbrack + Word( nonrbrack ) + rbrack keyDef = ~lbrack + Word( nonequals ) + equals + empty + restOfLine # strip any leading or trailing blanks from key def stripKey(tokens): tokens[0] = tokens[0].strip() keyDef.setParseAction(stripKey) - + # using Dict will allow retrieval of named data fields as attributes of the parsed results inibnf = Dict( ZeroOrMore( Group( sectionDef + Dict( ZeroOrMore( Group( keyDef ) ) ) ) ) ) - + inibnf.ignore( comment ) - + return inibnf @@ -59,14 +59,13 @@ def test( strng ): print(err.line) print(" "*(err.column-1) + "^") print(err) - + iniFile.close() print() return tokens - + if __name__ == "__main__": ini = test("setup.ini") - print("ini['Startup']['modemid'] =", ini['Startup']['modemid']) + print("ini['Startup']['modemid'] =", ini['Startup']['modemid']) print("ini.Startup =", ini.Startup) print("ini.Startup.modemid =", ini.Startup.modemid) - -- cgit v1.2.1