Commits

Michael Hudson-Doyle committed c366403

refactor run_file between main() & run_string()

  • Participants
  • Parent commits 2cb8ecf

Comments (0)

Files changed (1)

File pypy/interpreter/main.py

 import sys
 
 def run_string(source, fname):
-    space = StdObjSpace()
-    code = compile(source, fname, 'exec')
-    ec = executioncontext.ExecutionContext(space)
+    try:
+        space = StdObjSpace()
+        code = compile(source, fname, 'exec')
+        ec = executioncontext.ExecutionContext(space)
 
-    w_globals = ec.make_standard_w_globals()
-    frame = pyframe.PyFrame(space, code, w_globals, w_globals)
-    try:
+        w_globals = ec.make_standard_w_globals()
+        frame = pyframe.PyFrame(space, code, w_globals, w_globals)
+    except baseobjspace.OperationError, operationerr:
+        raise PyPyError(operationerr)
+    else:
         ec.eval_frame(frame)
-    except baseobjspace.OperationError, operationerr:
-        # XXX insert exception info into the application-level sys.last_xxx
-        operationerr.print_detailed_traceback(space)
+
+def run_file(fname):
+    ifile = open(fname)
+    run_string(ifile.read(), fname)
 
 def main(argv=None):
     if argv is None:
         argv = sys.argv
 
-    fname = argv[1]
-
-    ifile = open(fname)
-    run_string(ifile.read(), fname)
+    try:
+        run_file(argv[1])
+    except baseobjspace.OperationError, operationerr:
+        # XXX insert exception info into the application-level sys.last_xxx
+        operationerr.print_detailed_traceback(space)
 
 if __name__ == '__main__':
     sys.exit(main(sys.argv))