summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-09-15 05:57:40 +0000
committerptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b>2016-09-15 05:57:40 +0000
commitfd6099fbc56bf108ab20409750a8887a9e703a11 (patch)
tree3943979bb9c8a01627b44a4f4b53a4de6f861767
parent92a3d045f31cd690c1fd959fd2e81a4bb18f05a5 (diff)
downloadpyparsing-fd6099fbc56bf108ab20409750a8887a9e703a11.tar.gz
Remove all uses of 'eval'
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@440 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
-rw-r--r--src/unitTests.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/unitTests.py b/src/unitTests.py
index 17316f9..d9a6471 100644
--- a/src/unitTests.py
+++ b/src/unitTests.py
@@ -236,8 +236,11 @@ class ParseConfigFileTest(ParseTestCase):
#~ print
assert len(flatten(iniData.asList())) == numToks, "file %s not parsed correctly" % fnam
for chk in resCheckList:
- print_(chk[0], eval("iniData."+chk[0]), chk[1])
- assert eval("iniData."+chk[0]) == chk[1]
+ var = iniData
+ for attr in chk[0].split('.'):
+ var = getattr(var, attr)
+ print_(chk[0], var, chk[1])
+ assert var == chk[1]
print_("OK")
test("test/karthik.ini", 23,
@@ -1161,6 +1164,7 @@ class RecursiveCombineTest(ParseTestCase):
class InfixNotationGrammarTest1(ParseTestCase):
def runTest(self):
from pyparsing import Word,nums,alphas,Literal,oneOf,infixNotation,opAssoc
+ import ast
integer = Word(nums).setParseAction(lambda t:int(t[0]))
variable = Word(alphas,exact=1)
@@ -1202,7 +1206,7 @@ class InfixNotationGrammarTest1(ParseTestCase):
[['M', '*', ['X', '+', 'B']]]
[[1, '+', [2, '*', ['-', [3, '^', 4]], '*', 5], '+', ['-', ['+', ['-', 6]]]]]
[[3, '!', '!']]""".split('\n')
- expected = [eval(x) for x in expected]
+ expected = [ast.literal_eval(x.strip()) for x in expected]
for t,e in zip(test,expected):
print_(t,"->",e, "got", expr.parseString(t).asList())
assert expr.parseString(t).asList() == e,"mismatched results for infixNotation: got %s, expected %s" % (expr.parseString(t).asList(),e)
@@ -2794,6 +2798,7 @@ class RunTestsTest(ParseTestCase):
class CommonExpressionsTest(ParseTestCase):
def runTest(self):
from pyparsing import pyparsing_common
+ import ast
success = pyparsing_common.mac_address.runTests("""
AA:BB:CC:DD:EE:FF
@@ -2946,7 +2951,7 @@ class CommonExpressionsTest(ParseTestCase):
6.02e23""")
assert success, "failed to parse numerics"
for test,result in results:
- expected = eval(test)
+ expected = ast.literal_eval(test)
assert result[0] == expected, "numeric parse failed (wrong value) (%s should be %s)" % (result[0], expected)
assert type(result[0]) == type(expected), "numeric parse failed (wrong type) (%s should be %s)" % (type(result[0]), type(expected))