Author: oracle
Date: Thu Jul 24 20:33:30 2008
New Revision: 28182
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28182&view=rev
Log:
Changed exception handling to cover restricted and unrestricted
executions.
Modified:
trunk/data/ais/ai_launcher.py
Modified: trunk/data/ais/ai_launcher.py
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/ais/ai_launcher.py?rev=28182&r1=28181&r2=28182&view=diff
==============================================================================
--- trunk/data/ais/ai_launcher.py (original)
+++ trunk/data/ais/ai_launcher.py Thu Jul 24 20:33:30 2008
@@ -10,34 +10,39 @@
print "launch has been imported!"
-def launch( script, restrict ):
+def launch( script, restrict, importOnly=False ):
# Launch one of two possible environments
# If restrict arg is True, run inside the available
# restrictied python environment (safe.py). If restrict
- # is False, then run without any type of restrictions.
- if restrict:
- print "restricted environment detected - running parse/safe"
- try:
+ # is False, then run without any type of restrictions at
+ # all. If importOnly is True, only import but don't attempt
+ # to execute.
+ try:
+ if restrict:
+ print "restricted environment detected - running parse/safe"
import safe
import parse
parse.paths = ""
code, context = parse.parse( script )
- safe.safe_exec( code, context, restrict )
+ if not importOnly:
+ safe.safe_exec( code, context, restrict )
- except:
- err = str( traceback.format_exc() )
- raise
+ else:
+ print "unrestricted environment detected..."
+ __import__( script )
+ scrpt = sys.modules[ script ]
- else:
- print "unrestricted environment detected...running directly."
- __import__( script )
- scrpt = sys.modules[ script ]
+ # Call our entry points
+ if not importOnly:
+ print "Running script in unrestricted environment..."
+ scrpt.turn()
+ print "Script has completed execution."
- # Call our entry points
- scrpt.start()
- scrpt.turn()
- scrpt.end()
+ except:
+ err = str( traceback.format_exc() )
+ raise
+
print "launch has completed."
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits