Author: derek Date: Mon Nov 13 15:27:02 2006 New Revision: 184 Modified: sofaswitch/trunk/callflow/src/conditional.cpp sofaswitch/trunk/callflow/src/startfor.cpp Log: Protect calls to eval with try except statements. Thus, incorrect code prints out a warning when the user supplied code with cause a Python exception. Modified: sofaswitch/trunk/callflow/src/conditional.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/conditional.cpp (original) +++ sofaswitch/trunk/callflow/src/conditional.cpp Mon Nov 13 15:27:02 2006 @@ -84,7 +84,12 @@ file.AddLine(" def Conditional(self, aTuple): "); file.AddLine(" a,b,c = aTuple "); file.AddLine(" test = self.data[a][\"Test\"] "); - file.AddLine(" if eval(test) : "); + file.AddLine(" try: "); + file.AddLine(" self.conditional= eval(test) "); + file.AddLine(" except: "); + file.AddLine(" self.conditional=False "); + file.AddLine(" print \"Condition of \", test, \" was not valid Python code\" "); + file.AddLine(" if self.conditional : "); file.AddLine(" return self.data[a][\"OutputTrue\"] "); file.AddLine(" return self.data[a][\"OutputFalse\"] "); file.AddLine(" "); Modified: sofaswitch/trunk/callflow/src/startfor.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/startfor.cpp (original) +++ sofaswitch/trunk/callflow/src/startfor.cpp Mon Nov 13 15:27:02 2006 @@ -76,19 +76,30 @@ bool DndShapeStartFor::WriteSystemCode(wxTextFile & file) { - file.AddLine(" def Start_For(self, aTuple): "); - file.AddLine(" a,b,c = aTuple"); - - file.AddLine(" if b==0:"); - file.AddLine(" exec(self.data[a][\"Initialise\"])"); - file.AddLine(" else:"); - file.AddLine(" exec(self.data[a][\"Increment\"])"); - file.AddLine(" "); - file.AddLine(" if eval(self.data[a][\"Test\"]):"); - file.AddLine(" return self.data[a][\"Output\"]"); - file.AddLine(" "); - file.AddLine(" next = self.data[a][\"EndForLoop\"]"); - file.AddLine(" return self.data[next][\"AllDone\"]"); + file.AddLine(" def Start_For(self, aTuple): "); + file.AddLine(" a,b,c = aTuple "); + file.AddLine(" if b==0: "); + file.AddLine(" try: "); + file.AddLine(" exec(self.data[a][\"Initialise\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The initialise statement of \", self.data[a][\"Initialise\"], \" was not valid Python\" "); + file.AddLine(" else: "); + file.AddLine(" try: "); + file.AddLine(" exec(self.data[a][\"Increment\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The increment statement of \", self.data[a][\"Increment\"], \" was not valid Python\" "); + file.AddLine(" "); + file.AddLine(" try: "); + file.AddLine(" self.forCondition = eval(self.data[a][\"Test\"]) "); + file.AddLine(" except: "); + file.AddLine(" print \"The Test statement of \", self.data[a][\"Test\"], \" was not valid Python\" "); + file.AddLine(" self.forCondition = False "); + file.AddLine(" "); + file.AddLine(" if self.forCondition: "); + file.AddLine(" return self.data[a][\"Output\"] "); + file.AddLine(" "); + file.AddLine(" next = self.data[a][\"EndForLoop\"] "); + file.AddLine(" return self.data[next][\"AllDone\"] "); file.AddLine(" "); return true;
participants (1)
-
SofaSWITCH SVN