]> granicus.if.org Git - python/commitdiff
Kill execfile(), use exec() instead
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 12 Aug 2007 00:43:29 +0000 (00:43 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 12 Aug 2007 00:43:29 +0000 (00:43 +0000)
98 files changed:
Demo/scripts/newslist.py
Demo/scripts/pp.py
Doc/dist/dist.tex
Doc/howto/doanddont.tex
Doc/lib/libdoctest.tex
Doc/lib/libexcs.tex
Doc/lib/libfuncs.tex
Doc/lib/libuser.tex
Doc/ref/ref4.tex
Doc/ref/ref6.tex
Doc/tut/tut.tex
Lib/CGIHTTPServer.py
Lib/cProfile.py
Lib/distutils/core.py
Lib/doctest.py
Lib/lib-tk/Tkinter.py
Lib/optparse.py
Lib/pdb.py
Lib/plat-mac/appletrawmain.py
Lib/plat-mac/bundlebuilder.py
Lib/profile.py
Lib/test/test_builtin.py
Lib/test/test_multibytecodec.py
Lib/test/test_pkg.py
Lib/test/test_univnewlines.py
Lib/trace.py
Lib/user.py
Mac/Modules/ae/aescan.py
Mac/Modules/ae/aesupport.py
Mac/Modules/ah/ahscan.py
Mac/Modules/ah/ahsupport.py
Mac/Modules/app/appscan.py
Mac/Modules/app/appsupport.py
Mac/Modules/carbonevt/CarbonEvtscan.py
Mac/Modules/carbonevt/CarbonEvtsupport.py
Mac/Modules/cf/cfscan.py
Mac/Modules/cf/cfsupport.py
Mac/Modules/cg/cgscan.py
Mac/Modules/cg/cgsupport.py
Mac/Modules/cm/cmscan.py
Mac/Modules/cm/cmsupport.py
Mac/Modules/ctl/ctlscan.py
Mac/Modules/ctl/ctlsupport.py
Mac/Modules/dlg/dlgscan.py
Mac/Modules/dlg/dlgsupport.py
Mac/Modules/drag/dragscan.py
Mac/Modules/drag/dragsupport.py
Mac/Modules/evt/evtscan.py
Mac/Modules/evt/evtsupport.py
Mac/Modules/file/filescan.py
Mac/Modules/file/filesupport.py
Mac/Modules/fm/fmscan.py
Mac/Modules/fm/fmsupport.py
Mac/Modules/folder/folderscan.py
Mac/Modules/folder/foldersupport.py
Mac/Modules/help/helpscan.py
Mac/Modules/help/helpsupport.py
Mac/Modules/ibcarbon/IBCarbonscan.py
Mac/Modules/ibcarbon/IBCarbonsupport.py
Mac/Modules/icn/icnscan.py
Mac/Modules/icn/icnsupport.py
Mac/Modules/launch/launchscan.py
Mac/Modules/launch/launchsupport.py
Mac/Modules/list/listscan.py
Mac/Modules/list/listsupport.py
Mac/Modules/menu/menuscan.py
Mac/Modules/menu/menusupport.py
Mac/Modules/mlte/mltescan.py
Mac/Modules/mlte/mltesupport.py
Mac/Modules/osa/osascan.py
Mac/Modules/osa/osasupport.py
Mac/Modules/qd/qdscan.py
Mac/Modules/qd/qdsupport.py
Mac/Modules/qdoffs/qdoffsscan.py
Mac/Modules/qdoffs/qdoffssupport.py
Mac/Modules/qt/qtscan.py
Mac/Modules/qt/qtsupport.py
Mac/Modules/res/resscan.py
Mac/Modules/res/ressupport.py
Mac/Modules/scrap/scrapscan.py
Mac/Modules/scrap/scrapsupport.py
Mac/Modules/snd/sndscan.py
Mac/Modules/snd/sndsupport.py
Mac/Modules/te/tescan.py
Mac/Modules/te/tesupport.py
Mac/Modules/win/winscan.py
Mac/Modules/win/winsupport.py
Misc/NEWS
Misc/Vim/python.vim
Misc/cheatsheet
Misc/python-mode.el
Objects/fileobject.c
Python/bltinmodule.c
README
Tools/scripts/hotshotmain.py
Tools/versioncheck/README
Tools/versioncheck/checkversions.py
setup.py

index 7038380f5c02553b46551c149e1133eeab3c4a85..3d65a08381277f3f94c05904bf1fe62bdfc56346 100755 (executable)
@@ -99,7 +99,7 @@ for dir in os.curdir, os.environ['HOME']:
     rcfile = os.path.join(dir, '.newslistrc.py')
     if os.path.exists(rcfile):
         print(rcfile)
-        execfile(rcfile)
+        exec(open(rcfile).read())
         break
 
 from nntplib import NNTP
index 486986ae34d21abdf0db8a070b1f119e620ba47e..9010b7af4d3e1e5f3fa37992981697b4a965734c 100755 (executable)
@@ -123,8 +123,9 @@ import tempfile
 fp = tempfile.NamedTemporaryFile()
 fp.write(program)
 fp.flush()
+script = open(tfn).read()
 if DFLAG:
     import pdb
-    pdb.run('execfile(%r)' % (tfn,))
+    pdb.run(script)
 else:
-    execfile(tfn)
+    exec(script)
index ff5106a1691524b9dae2325936cbbeef32952508..a33227f71090459ccda82dddac2d0a59d3677f1a 100644 (file)
@@ -2290,7 +2290,7 @@ This is useful if you need to find out the distribution meta-data
 (passed as keyword args from \var{script} to \function{setup()}), or 
 the contents of the config files or command-line.
 
-\var{script_name} is a file that will be run with \function{execfile()}
+\var{script_name} is a file that will be read and run with \function{exec()}
 \code{sys.argv[0]} will be replaced with \var{script} for the duration of the
 call.  \var{script_args} is a list of strings; if supplied,
 \code{sys.argv[1:]} will be replaced by \var{script_args} for the duration 
index 0cd5d912b93349c1111910b3edf9bc422f1bc849..b54f0690a3d632b0bb9c99c723b8b49523ec5047 100644 (file)
@@ -81,7 +81,7 @@ There are situations in which \code{from module import *} is just fine:
 
 \end{itemize}
 
-\subsection{Unadorned \function{exec}, \function{execfile} and friends}
+\subsection{Unadorned \function{exec} and friends}
 
 The word ``unadorned'' refers to the use without an explicit dictionary,
 in which case those constructs evaluate code in the {\em current} environment.
@@ -97,7 +97,7 @@ Bad examples:
 >>> def func(s, **kw):
 >>>     for var, val in kw.items():
 >>>         exec("s.%s=val" % var)  # invalid!
->>> execfile("handler.py")
+>>> exec(open("handler.py").read())
 >>> handle()
 \end{verbatim}
 
@@ -111,7 +111,7 @@ Good examples:
 >>>     for var, val in kw.items():
 >>>         setattr(s, var, val)
 >>> d={}
->>> execfile("handle.py", d, d)
+>>> exec(open("handler.py").read(), d, d)
 >>> handle = d['handle']
 >>> handle()
 \end{verbatim}
index 5e28c2acc0c20bf82bb40eb37aadbcc3b9232d5a..9143b8486b0ac9fab37f6eac725f7d4c065ec1b7 100644 (file)
@@ -1828,7 +1828,7 @@ print doctest.testsource(a, "a.f")
   via \function{\refmodule{pdb}.post_mortem()}, passing the traceback object
   from the unhandled exception.  If \var{pm} is not specified, or is false,
   the script is run under the debugger from the start, via passing an
-  appropriate \function{execfile()} call to \function{\refmodule{pdb}.run()}.
+  appropriate \function{exec()} call to \function{\refmodule{pdb}.run()}.
 
   \versionadded{2.3}
 
index 298f04dcfd830a9c1f81ff88b17ac62ae7acd442..74531d3a4d5e68d1097f8de92b24d2685550f681 100644 (file)
@@ -260,7 +260,7 @@ Raised when an \keyword{assert} statement fails.
 % XXXJH xref to these functions?
   Raised when the parser encounters a syntax error.  This may occur in
   an \keyword{import} statement, in a call to the built-in functions
-  \function{exec()}, \function{execfile()}, \function{eval()} or
+  \function{exec()}, \function{eval()} or
   \function{input()}, or when reading the initial script or standard
   input (also interactively).
 
index 3cc06c85216694823ac8792775c9a46e4096f6d3..0b99c3fd499373f67553ee07aeb1071c60416439 100644 (file)
@@ -382,15 +382,13 @@ class C:
   compiled passing \code{'eval'} as the \var{kind} argument.
 
   Hints: dynamic execution of statements is supported by the
-  \function{exec()} function.  Execution of statements from a file is
-  supported by the \function{execfile()} function.  The
+  \function{exec()} function.  The
   \function{globals()} and \function{locals()} functions returns the
   current global and local dictionary, respectively, which may be
   useful to pass around for use by \function{eval()} or
-  \function{execfile()}.
+  \function{exec()}.
 \end{funcdesc}
 
-
 \begin{funcdesc}{exec}{object\optional{, globals\optional{, locals}}}
   This function supports dynamic execution of Python code.
   \var{object} must be either a string, an open file object, or
@@ -425,31 +423,6 @@ class C:
        argument to \function{exec()}.}
 \end{funcdesc}
 
-\begin{funcdesc}{execfile}{filename\optional{, globals\optional{, locals}}}
-  This function is similar to the \function{exec()} function, but parses a
-  file given by the file name instead of a string.  It
-  is different from the \keyword{import} statement in that it does not
-  use the module administration --- it reads the file unconditionally
-  and does not create a new module.
-
-  The arguments are a file name and two optional dictionaries.  The file is
-  parsed and evaluated as a sequence of Python statements (similarly to a
-  module) using the \var{globals} and \var{locals} dictionaries as global and
-  local namespace. If provided, \var{locals} can be any mapping object.
-  \versionchanged[formerly \var{locals} was required to be a dictionary]{2.4}
-  If the \var{locals} dictionary is omitted it defaults to the \var{globals}
-  dictionary. If both dictionaries are omitted, the expression is executed in
-  the environment where \function{execfile()} is called.  The return value is
-  \code{None}.
-
-  \warning{The default \var{locals} act as described for function
-  \function{locals()} below:  modifications to the default \var{locals}
-  dictionary should not be attempted.  Pass an explicit \var{locals}
-  dictionary if you need to see effects of the code on \var{locals} after
-  function \function{execfile()} returns.  \function{execfile()} cannot
-  be used reliably to modify a function's locals.}
-\end{funcdesc}
-
 \begin{funcdesc}{file}{filename\optional{, mode\optional{, bufsize}}}
   Constructor function for the \class{file} type, described further 
   in section~\ref{bltin-file-objects}, ``\ulink{File
index 4e915a22c88c1f252b1e0c0c97349403b7572959..6dd1546f02e18f7a1f37e2788d77e343b218b5b5 100644 (file)
@@ -24,7 +24,7 @@ import user
 
 The \module{user} module looks for a file \file{.pythonrc.py} in the user's
 home directory and if it can be opened, executes it (using
-\function{execfile()}\bifuncindex{execfile}) in its own (the
+\function{exec()}\bifuncindex{exec}) in its own (the
 module \module{user}'s) global namespace.  Errors during this phase
 are not caught; that's up to the program that imports the
 \module{user} module, if it wishes.  The home directory is assumed to
index 9ae8bfaea06c8e2077ba5e7bd22c1eb609afc694..6ec60f8c1282396cd48c693cd40191ae374137fa 100644 (file)
@@ -19,8 +19,7 @@ block.  A script file (a file given as standard input to the
 interpreter or specified on the interpreter command line the first
 argument) is a code block.  A script command (a command specified on
 the interpreter command line with the `\strong{-c}' option) is a code
-block.  The file read by the built-in function \function{execfile()}
-is a code block.  The string argument passed to the built-in functions
+block.  The string argument passed to the built-in functions
 \function{eval()} and \function{exec()} is a code block.
 The expression read and evaluated by the built-in function
 \function{input()} is a code block.
@@ -139,7 +138,7 @@ If the wild card form of import --- \samp{import *} --- is used in a
 function and the function contains or is a nested block with free
 variables, the compiler will raise a \exception{SyntaxError}.
 
-The \function{eval()}, \function{exec()}, \function{execfile()},
+The \function{eval()}, \function{exec()},
 and \function{input()} functions do not have access to the
 full environment for resolving names.  Names may be resolved in the
 local and global namespaces of the caller.  Free variables are not
@@ -147,7 +146,7 @@ resolved in the nearest enclosing namespace, but in the global
 namespace.\footnote{This limitation occurs because the code that is
     executed by these operations is not available at the time the
     module is compiled.}
-The \function{exec()}, \function{eval()} and \function{execfile()}
+The \function{exec()} and \function{eval()}
 functions have optional arguments to override
 the global and local namespace.  If only one namespace is specified,
 it is used for both.
index 60e7b02bec69674a3ef821a8a80230134aac5fba..11390056b2e4aabd55df7ededde43e757d4fcd59 100644 (file)
@@ -760,8 +760,8 @@ import __future__ [as name]
 That is not a future statement; it's an ordinary import statement with
 no special semantics or syntax restrictions.
 
-Code compiled by calls to the builtin functions \function{exec()},
-\function{compile()} and \function{execfile()} that occur in a module
+Code compiled by calls to the builtin functions \function{exec()} and
+\function{compile()} that occur in a module
 \module{M} containing a future statement will, by default, use the new 
 syntax or semantics associated with the future statement.  This can,
 starting with Python 2.2 be controlled by optional arguments to
@@ -811,9 +811,8 @@ string or code object supplied to the builtin \function{exec()} function
 does not affect the code block \emph{containing} the function call,
 and code contained in such a string is unaffected by \keyword{global}
 statements in the code containing the function call.  The same applies to the
-\function{eval()}, \function{execfile()} and \function{compile()} functions.
+\function{eval()} and \function{compile()} functions.
 \bifuncindex{exec}
 \bifuncindex{eval}
-\bifuncindex{execfile}
 \bifuncindex{compile}
 
index 74468b1b9f42bac34bb8ac36e8ff4378fa8f045c..b39cd473bcac7449753a10afb509ddeb6fb2bda7 100644 (file)
@@ -409,14 +409,14 @@ this file.
 If you want to read an additional start-up file from the current
 directory, you can program this in the global start-up file using code
 like \samp{if os.path.isfile('.pythonrc.py'):
-execfile('.pythonrc.py')}.  If you want to use the startup file in a
+exec(open('.pythonrc.py')).read()}.  If you want to use the startup file in a
 script, you must do this explicitly in the script:
 
 \begin{verbatim}
 import os
 filename = os.environ.get('PYTHONSTARTUP')
 if filename and os.path.isfile(filename):
-    execfile(filename)
+    exec(open(filename).read())
 \end{verbatim}
 
 
@@ -2736,14 +2736,14 @@ standard module \module{__builtin__}\refbimodindex{__builtin__}:
  '__name__', 'abs', 'basestring', 'bool', 'buffer',
  'chr', 'classmethod', 'cmp', 'compile',
  'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod',
- 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float',
+ 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float',
  'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex',
  'id', 'input', 'int', 'isinstance', 'issubclass', 'iter',
- 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min',
+ 'len', 'license', 'list', 'locals', 'map', 'max', 'min',
  'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range',
  'repr', 'reversed', 'round', 'set',
  'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super',
- 'tuple', 'type', 'unichr', 'unicode', 'vars', 'zip']
+ 'tuple', 'type', 'vars', 'zip']
 \end{verbatim}
 
 
@@ -4413,8 +4413,8 @@ the debugger, and that's one reason why this loophole is not closed.
 (Buglet: derivation of a class with the same name as the base class
 makes use of private variables of the base class possible.)
 
-Notice that code passed to \code{exec()}, \code{eval()} or
-\code{execfile()} does not consider the classname of the invoking 
+Notice that code passed to \code{exec()} or \code{eval()}
+does not consider the classname of the invoking 
 class to be the current class; this is similar to the effect of the 
 \code{global} statement, the effect of which is likewise restricted to 
 code that is byte-compiled together.  The same restriction applies to
index a2d809c14c644a5bb08db1bab9a1e08dade4b261..828b092496b8c470cb31cb8d14235a91ea7eee02 100644 (file)
@@ -316,7 +316,7 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
                         sys.argv.append(decoded_query)
                     sys.stdout = self.wfile
                     sys.stdin = self.rfile
-                    execfile(scriptfile, {"__name__": "__main__"})
+                    exec(open(scriptfile).read(), {"__name__": "__main__"})
                 finally:
                     sys.argv = save_argv
                     sys.stdin = save_stdin
index d10b7ab9f7b4bd93cf4d0e1a53abe3763bbb23a9..ae16277bcbf33f17dafa0ac67bea6d20bd26d38f 100755 (executable)
@@ -180,7 +180,12 @@ def main():
 
     if (len(sys.argv) > 0):
         sys.path.insert(0, os.path.dirname(sys.argv[0]))
-        run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
+        fp = open(sys.argv[0])
+        try:
+            script = fp.read()
+        finally:
+            fp.close()
+        run('exec(%r)' % script, options.outfile, options.sort)
     else:
         parser.print_usage()
     return parser
index bd9b8542cd4af8fbac6fcecf5acf33ddd16da3ef..d60998240f8ce7e9643246e0442c11034014a3ff 100644 (file)
@@ -179,7 +179,7 @@ def run_setup (script_name, script_args=None, stop_after="run"):
     keyword args from 'script' to 'setup()', or the contents of the
     config files or command-line.
 
-    'script_name' is a file that will be run with 'execfile()';
+    'script_name' is a file that will be read and run with 'exec()';
     'sys.argv[0]' will be replaced with 'script' for the duration of the
     call.  'script_args' is a list of strings; if supplied,
     'sys.argv[1:]' will be replaced by 'script_args' for the duration of
@@ -217,7 +217,7 @@ def run_setup (script_name, script_args=None, stop_after="run"):
             sys.argv[0] = script_name
             if script_args is not None:
                 sys.argv[1:] = script_args
-            execfile(script_name, g, l)
+            exec(open(script_name).read(), g, l)
         finally:
             sys.argv = save_argv
             _setup_stop_after = None
index 0f408185f0bbadb2a890e3dccfe31d4e0df3fd93..ec51657419533b7cd87aed3d80e94380014b04ec 100644 (file)
@@ -2490,7 +2490,7 @@ def debug_script(src, pm=False, globs=None):
 
     # Note that tempfile.NameTemporaryFile() cannot be used.  As the
     # docs say, a file so created cannot be opened by name a second time
-    # on modern Windows boxes, and execfile() needs to open it.
+    # on modern Windows boxes, and exec() needs to open and read it.
     srcfilename = tempfile.mktemp(".py", "doctestdebug")
     f = open(srcfilename, 'w')
     f.write(src)
@@ -2504,14 +2504,17 @@ def debug_script(src, pm=False, globs=None):
 
         if pm:
             try:
-                execfile(srcfilename, globs, globs)
+                exec(open(srcfilename).read(), globs, globs)
             except:
                 print(sys.exc_info()[1])
                 pdb.post_mortem(sys.exc_info()[2])
         else:
-            # Note that %r is vital here.  '%s' instead can, e.g., cause
-            # backslashes to get treated as metacharacters on Windows.
-            pdb.run("execfile(%r)" % srcfilename, globs, globs)
+            fp = open(srcfilename)
+            try:
+                script = fp.read()
+            finally:
+                fp.close()
+            pdb.run("exec(%r)" % script, globs, globs)
 
     finally:
         os.remove(srcfilename)
index ef588e87bc10939d4f46a79d203921d98455d635..144be0a1a8876731b87ebfd0318d69bf212d3b05 100644 (file)
@@ -1688,8 +1688,8 @@ class Tk(Misc, Wm):
             _default_root = None
     def readprofile(self, baseName, className):
         """Internal function. It reads BASENAME.tcl and CLASSNAME.tcl into
-        the Tcl Interpreter and calls execfile on BASENAME.py and CLASSNAME.py if
-        such a file exists in the home directory."""
+        the Tcl Interpreter and calls exec on the contents of BASENAME.py and
+        CLASSNAME.py if such a file exists in the home directory."""
         import os
         if 'HOME' in os.environ: home = os.environ['HOME']
         else: home = os.curdir
@@ -1702,11 +1702,11 @@ class Tk(Misc, Wm):
         if os.path.isfile(class_tcl):
             self.tk.call('source', class_tcl)
         if os.path.isfile(class_py):
-            execfile(class_py, dir)
+            exec(open(class_py).read(), dir)
         if os.path.isfile(base_tcl):
             self.tk.call('source', base_tcl)
         if os.path.isfile(base_py):
-            execfile(base_py, dir)
+            exec(open(base_py).read(), dir)
     def report_callback_exception(self, exc, val, tb):
         """Internal function. It reports exception on sys.stderr."""
         import traceback, sys
index 84a6abd1927327fa32beb936c19ec94202227310..bae10500d34422c4957016fef1bb6a22363fc4eb 100644 (file)
@@ -874,7 +874,7 @@ class Values:
 
     def read_file(self, filename, mode="careful"):
         vars = {}
-        execfile(filename, vars)
+        exec(open(filename).read(), vars)
         self._update(vars, mode)
 
     def ensure_value(self, attr, value):
index f408bf3a460adc772b37a46cd6f23d3bc01709f6..3bbf76b25ded91a1ef9f0b9d93f14ebb69fbc1e5 100755 (executable)
@@ -1164,7 +1164,12 @@ see no sign that the breakpoint was reached.
         self._wait_for_mainpyfile = 1
         self.mainpyfile = self.canonic(filename)
         self._user_requested_quit = 0
-        statement = 'execfile( "%s")' % filename
+        fp = open(filename)
+        try:
+            script = fp.read()
+        finally:
+            fp.close()
+        statement = 'exec("%s")' % script
         self.run(statement)
 
 # Simplified interface
index 6f2eacb20f013c0677e3238f3248bce405dbbf5d..5c09e2d124d226f202fb6cc85cd1dfffde0aead7 100644 (file)
@@ -41,7 +41,7 @@ if os.path.exists(__file__):
     #
     sys.argv[0] = __file__
     del argvemulator, os, sys, _dir
-    execfile(__file__)
+    exec(open(__file__).read())
 else:
     __file__ = os.path.join(_dir, '__main__.pyc')
     if os.path.exists(__file__):
index e833addb11b31cac10eb07f756c2c9fe0bb28e8d..d8186c1d7d2df286522b63197c92c169338656f9 100755 (executable)
@@ -322,7 +322,12 @@ ARGV_EMULATOR = """\
 import argvemulator, os
 
 argvemulator.ArgvCollector().mainloop()
-execfile(os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s"))
+fp = os.path.join(os.path.split(__file__)[0], "%(realmainprogram)s")
+try:
+    script = fp.read()
+finally:
+    fp.close()
+exec(script)
 """
 
 #
index 55118b596069ceb8965d92f579f03f95082119c8..cdc247911bccbc476c08a28ac27db47fbb579142 100755 (executable)
@@ -609,7 +609,12 @@ def main():
 
     if (len(sys.argv) > 0):
         sys.path.insert(0, os.path.dirname(sys.argv[0]))
-        run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
+        fp = open(sys.argv[0])
+        try:
+            script = fp.read()
+        finally:
+            fp.close()
+        run('exec(%r)' % script, options.outfile, options.sort)
     else:
         parser.print_usage()
     return parser
index a4ae21aa5dd3199f5aec2e1ac5ab2a1747f0a507..b43082212d1da90318f5f4026cb94e59a4f7deae 100644 (file)
@@ -11,10 +11,6 @@ warnings.filterwarnings("ignore", "hex../oct.. of negative int",
 warnings.filterwarnings("ignore", "integer argument expected",
                         DeprecationWarning, "unittest")
 
-# count the number of test runs.
-# used to skip running test_execfile() multiple times
-numruns = 0
-
 class Squares:
 
     def __init__(self, max):
@@ -399,57 +395,6 @@ class BuiltinTest(unittest.TestCase):
                 return 1 # used to be 'a' but that's no longer an error
         self.assertRaises(TypeError, eval, 'dir()', globals(), C())
 
-    # Done outside of the method test_z to get the correct scope
-    z = 0
-    f = open(TESTFN, 'w')
-    f.write('z = z+1\n')
-    f.write('z = z*2\n')
-    f.close()
-    execfile(TESTFN)
-
-    def test_execfile(self):
-        global numruns
-        if numruns:
-            return
-        numruns += 1
-
-        globals = {'a': 1, 'b': 2}
-        locals = {'b': 200, 'c': 300}
-
-        self.assertEqual(self.__class__.z, 2)
-        globals['z'] = 0
-        execfile(TESTFN, globals)
-        self.assertEqual(globals['z'], 2)
-        locals['z'] = 0
-        execfile(TESTFN, globals, locals)
-        self.assertEqual(locals['z'], 2)
-
-        class M:
-            "Test mapping interface versus possible calls from execfile()."
-            def __init__(self):
-                self.z = 10
-            def __getitem__(self, key):
-                if key == 'z':
-                    return self.z
-                raise KeyError
-            def __setitem__(self, key, value):
-                if key == 'z':
-                    self.z = value
-                    return
-                raise KeyError
-
-        locals = M()
-        locals['z'] = 0
-        execfile(TESTFN, globals, locals)
-        self.assertEqual(locals['z'], 2)
-
-        unlink(TESTFN)
-        self.assertRaises(TypeError, execfile)
-        self.assertRaises(TypeError, execfile, TESTFN, {}, ())
-        import os
-        self.assertRaises(IOError, execfile, os.curdir)
-        self.assertRaises(IOError, execfile, "I_dont_exist")
-
     def test_exec(self):
         g = {}
         exec('z = 1', g)
index 32c48fbd93151c50e66b720122bb374b64c663e9..c2f34e593faa7f01feed7c31ee77c76ac538498c 100644 (file)
@@ -49,7 +49,7 @@ class Test_MultibyteCodec(unittest.TestCase):
         try:
             for enc in ALL_CJKENCODINGS:
                 print('# coding:', enc, file=io.open(TESTFN, 'w'))
-                execfile(TESTFN)
+                exec(open(TESTFN).read())
         finally:
             test_support.unlink(TESTFN)
 
index 1a3f2a96b910ff8c9ebcaf764b717f94ebaee342..907359b5b7c64d1d30bbcfe5d7bb2c1c1d05dd2d 100644 (file)
@@ -63,7 +63,7 @@ def runtest(hier, code):
         sys.path.insert(0, root)
         if verbose: print("sys.path =", sys.path)
         try:
-            execfile(fname, globals(), {})
+            exec(open(fname).read(), globals(), {})
         except:
             traceback.print_exc(file=sys.stdout)
     finally:
index ae4c4421c739df1cb8179875e4f72d4cdcaaa90c..7810caef8c4aa5e7bab7e8b3a78e5aac65b38de9 100644 (file)
@@ -78,13 +78,6 @@ class TestGenericUnivNewlines(unittest.TestCase):
         data = fp.readlines()
         self.assertEqual(data, DATA_SPLIT[1:])
 
-    def test_execfile(self):
-        namespace = {}
-        execfile(test_support.TESTFN, namespace)
-        func = namespace['line3']
-        self.assertEqual(func.__code__.co_firstlineno, 3)
-        self.assertEqual(namespace['line4'], FATX)
-
 
 class TestNativeNewlines(TestGenericUnivNewlines):
     NEWLINE = None
index d40f13c2320621984c41bf50c525105d7c16863e..645517a75fc7488feeff11962063c3f4130f6df5 100644 (file)
@@ -773,7 +773,12 @@ def main(argv=None):
                   ignoredirs=ignore_dirs, infile=counts_file,
                   outfile=counts_file)
         try:
-            t.run('execfile(%r)' % (progname,))
+            fp = open(progname)
+            try:
+                script = fp.read()
+            finally:
+                fp.close()
+            t.run('exec(%r)' % (script,))
         except IOError as err:
             _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
         except SystemExit:
index e550e52ad807a413c9cef994da690635c19052c6..99efd2d24066cc5088d8ab2b7b51c9b8e887b025 100644 (file)
@@ -12,7 +12,7 @@ that wishes to use the mechanism must execute the statement
     import user
 
 The user module looks for a file .pythonrc.py in the user's home
-directory and if it can be opened, execfile()s it in its own global
+directory and if it can be opened and read, exec()s it in its own global
 namespace.  Errors during this phase are not caught; that's up to the
 program that imports the user module, if it wishes.
 
@@ -42,4 +42,4 @@ except IOError:
     pass
 else:
     f.close()
-    execfile(pythonrc)
+    exec(open(pythonrc).read())
index 1283c1dcd2525a7a82603777682038d30ad9817e..0ea367c82fe48dcd051a97fa15188cd2418f95a9 100644 (file)
@@ -21,7 +21,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done Scanning and Generating, now doing 'import aesupport' ==="
     import aesupport
     print "=== Done 'import aesupport'.  It's up to you to compile AEmodule.c ==="
index 91c5b82efe08563481fd4d0cc962577b33ee7744..d3e1dfd09123fd8006a61545f8e45b1c0a5bdcb4 100644 (file)
@@ -213,8 +213,8 @@ module.addobject(aedescobject)
 functions = []
 aedescmethods = []
 
-execfile('aegen.py')
-##execfile('aedatamodelgen.py')
+exec(open('aegen.py').read())
+##exec(open('aedatamodelgen.py').read())
 
 # Manual generator
 AutoDispose_body = """
index 0b7fe081f860fafe45aa904d48b02cd7dcdffb2e..8768b60b315c454cf21c2320e434934dcd885b3a 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index c5f24beeeab3a6dba4dea57ab6adbc7d6d6b761b..9fa9dde2d7833e1534b00e15d74e84526a8ec2a4 100644 (file)
@@ -34,7 +34,7 @@ Function = OSErrFunctionGenerator
 
 # Create and populate the lists
 functions = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 1b04859ef2d074064ee888c32b20864a0140b53f..246d61ee2b2fcad18790157013433587b7d96a35 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 177dfd55f5bf0f32e244046cc8f74193efb2212a..73f5f1133abb609329820cfa8a6bdb71f714400d 100644 (file)
@@ -121,7 +121,7 @@ Function = OSErrWeakLinkFunctionGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index e3c72ae23def87acda72fc26a534233209cb2201..7307327fa8513b32e8602851e42d1f563170a46d 100644 (file)
@@ -20,7 +20,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "--done scanning, importing--"
     import CarbonEvtsupport
     print "done"
index 77d12b62990b0a616db78e643f9feb5e8d9f853f..2adc8cbfc0ed1682d721281f42f162e4921c7381 100644 (file)
@@ -214,7 +214,7 @@ for typ in RefObjectTypes: ## go thru all ObjectTypes as defined in CarbonEvents
     execstr = typ + 'methods = []'
     exec execstr
 
-execfile('CarbonEventsgen.py')
+exec(open('CarbonEventsgen.py').read())
 
 
 
index d2de92e2da4ea13f1b7997d4f384f17653da0d60..5ff9534bde40b49e2f90fd283e72c210c3629f39 100644 (file)
@@ -45,7 +45,7 @@ def main():
     scanner.gentypetest(SHORT+"typetest.py")
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 800581a03e353466cf81c5c07eddc7fbacff67f1..655331eb2a8b810b0bf5bbc82e1af7c213e83294 100644 (file)
@@ -529,7 +529,7 @@ CFMutableStringRef_methods = []
 CFURLRef_methods = []
 
 # ADD _methods initializer here
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 
 # add the populated lists to the generator groups
index b2e79461953be45f64787a9e53376bd2b88649df..82f491915836d8d207049b252bca2bfc8bbe6413 100755 (executable)
@@ -23,7 +23,7 @@ def main():
     scanner.gentypetest(SHORT+"typetest.py")
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 6eedfbef3f762682c09dbdb35bc358bf4e7eef5b..7fa06e2ac0c04bfe001042c3e3cc79a4e983d52f 100755 (executable)
@@ -145,7 +145,7 @@ Method = MethodGenerator
 CGContextRef_methods = []
 
 # ADD _methods initializer here
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # manual method, lives in Quickdraw.h
 f = Method(void, 'SyncCGContextOriginWithPort',
index 087f2393df6a04ae31f7c881b7b12755fd5077ec..1a1e46d6f23719082be9047a82d7995a51137d4f 100644 (file)
@@ -17,7 +17,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 4109dbabaad2768433542004676c829eb90a1111..1653bb3ab2004b3ee0a47a47f93ac227964a77c9 100644 (file)
@@ -112,7 +112,7 @@ Method = OSErrWeakLinkMethodGenerator
 functions = []
 c_methods = []
 ci_methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 25333f1fa073914610b1bb96b994ba62576fbe48..dd74d238f83744f6c68e0d816aa77393a5ef1f94 100644 (file)
@@ -15,7 +15,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now doing 'import ctlsupport' ==="
     import ctlsupport
     print "=== Done.  It's up to you to compile Ctlmodule.c ==="
index d354d94276ca1f0458f0a9390909b14297f5cf8f..04fac8be5b2e8b6a2a2070dae97af7aa3103e13c 100644 (file)
@@ -507,8 +507,8 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
-execfile('ctledit.py')
+exec(open(INPUTFILE).read())
+exec(open('ctledit.py').read())
 
 # add the populated lists to the generator groups
 for f in functions: module.add(f)
index 7fb68f7cb1f53c61bbc2b859be7afc3cb44c3117..bf37129b9e93a472ac3f4371f076f15f3d834b3a 100644 (file)
@@ -19,7 +19,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index fa1442ec37bdfe3ebeed25873e97a7468f4f0694..fcff5c03f8b9ef506bb46d68877ac65e6e14011f 100644 (file)
@@ -240,7 +240,7 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile("dlggen.py")
+exec(open("dlggen.py").read())
 
 # add the populated lists to the generator groups
 for f in functions: module.add(f)
index 923a56bd4dd62e0975c5dc917be4e83a5aed40d8..e89897a562453bcb59f53bbdb110d0d339a5856c 100644 (file)
@@ -26,7 +26,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now doing 'import dragsupport' ==="
     import dragsupport
     print "=== Done.  It's up to you to compile Dragmodule.c ==="
index 45838efde667a74de2cae8b5d4dcb98189679825..bb1a9188c67becae74424645f14dc7808d9b9333 100644 (file)
@@ -216,7 +216,7 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 for f in functions: module.add(f)
index 0d0c9ec4df25b59a2d0124cb71d4395213ca75a5..0adce8b15514cd28d4bc65ed89458b5fef88c01b 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index f58da14a661b694eeab171902fe10155bbeee030..8deef928156b66af4e732c43b9bccc27023a934e 100644 (file)
@@ -50,7 +50,7 @@ Function = OSErrWeakLinkFunctionGenerator
 
 # Create and populate the lists
 functions = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # Move TickCount here, for convenience
 f = Function(UInt32, 'TickCount',
index 8ebc69fe4e0f50feb00a83e147128e5dcc29cab6..b7c5d121e4c683a6c7495e83f89f267d7a0dcdfb 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.close()
     scanner.gentypetest(SHORT+"typetest.py")
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 37aeb508a0952790a3e6402becab8cc40240e9d1..de45ed40420170fa00bb370e4eb54adb5b86963c 100644 (file)
@@ -340,7 +340,7 @@ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
 """
 
-execfile(string.lower(MODPREFIX) + 'typetest.py')
+exec(open(string.lower(MODPREFIX) + 'typetest.py').read())
 
 # Our object types:
 class FSCatalogInfoDefinition(PEP253Mixin, ObjectDefinition):
@@ -806,7 +806,7 @@ functions = []
 alias_methods = []
 fsref_methods = []
 fsspec_methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # Manual generators:
 FSRefMakePath_body = """
index 334d5eca1565a2dd130508049a8c5da9e57a5b0c..38abcacf98b4fc9c568e2ca0cf98f2cf64034f75 100644 (file)
@@ -17,7 +17,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index e69205316c707778a11c440fdf4e8dd2d75402e7..8e2b8b31fa1877e6545d8c5cedb90e163c9fc74e 100644 (file)
@@ -70,7 +70,7 @@ Function = OSErrWeakLinkFunctionGenerator
 
 # Create and populate the lists
 functions = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 8c94893011ff07fe2131e8c3a58ca2e09aaefdc2..cccb720adb86f5986d8d0c9fd0c1832c60acd9a7 100644 (file)
@@ -19,7 +19,7 @@ def main():
     scanner.close()
     scanner.gentypetest(SHORT+"typetest.py")
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index b9b64bfb01ad5386f19a7e796bc7b47a04855960..224b5453efbc333667fb9e7719c0915cc2848034 100644 (file)
@@ -33,7 +33,7 @@ includestuff = includestuff + """
 
 """
 
-execfile(string.lower(MODPREFIX) + 'typetest.py')
+exec(open(string.lower(MODPREFIX) + 'typetest.py').read())
 
 # From here on it's basically all boiler plate...
 
@@ -45,7 +45,7 @@ Function = OSErrFunctionGenerator
 
 # Create and populate the lists
 functions = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 50e0919dc5258e7fa9265fa1604aa984d4728667..fa8dbde986b4dc021ba9ecfd1200b7b0c028d343 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 77f5c2ecc907a50adf727944be6590e034d090d8..37117ee142baa3bcb626dcd5ea1f5348735ce4f8 100644 (file)
@@ -66,7 +66,7 @@ Function = OSErrFunctionGenerator
 # Create and populate the lists
 functions = []
 ##methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 84e4f1e67255d48bbc75c6c972acc7d2c9cc332d..eb7267de15068b24eb0679ae38dd76c3df7333ec 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "--done scanning, importing--"
     import IBCarbonsupport
     print "done"
index 5f4132840e2279e0fd54a40279328efb715f34cb..8744b69bcccc441afa6ca95b980f9dc66dbb3bd8 100644 (file)
@@ -42,7 +42,7 @@ module.addobject(ibnibobject)
 functions = []
 methods = []
 
-execfile('IBCarbongen.py')
+exec(open('IBCarbongen.py').read())
 
 for f in functions: module.add(f)
 for m in methods: ibnibobject.add(m)
index bdc3b84413e7c7fa8709d34878ff63ce25bb946d..2d20062bf2f979581651cdf1daf684cd7af4c218 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 1b153854bd2643c4e8ede37ed86b2f0b43c5e434..e9a8b78c5cb1f35933ee9667742224b1929913b3 100644 (file)
@@ -78,7 +78,7 @@ Function = OSErrWeakLinkFunctionGenerator
 # Create and populate the lists
 functions = []
 ##methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 621033ba87b73ab6f9cc121e63f28670d4d742fe..dd43e37552618595dcb7577c9c03571761211c33 100644 (file)
@@ -19,7 +19,7 @@ def main():
     scanner.close()
     scanner.gentypetest(SHORT+"typetest.py")
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 34c2efbcfd5e35740bfad7dae4318c8198a5db3a..5faf4b3fa0016e06da5ce43bbaa2b895a0f8aff7 100644 (file)
@@ -75,7 +75,7 @@ LSItemInfoRecord_New(LSItemInfoRecord *it)
 """
 
 # From here on it's basically all boiler plate...
-execfile(string.lower(MODPREFIX) + 'typetest.py')
+exec(open(string.lower(MODPREFIX) + 'typetest.py').read())
 
 # Create the generator groups and link them
 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
@@ -89,7 +89,7 @@ Function = OSErrFunctionGenerator
 # Create and populate the lists
 functions = []
 ##methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 877f6cb48bcd64eb70cbe73a42021ccb5c7c0c0a..14e7dcac28b4874963dab236b0b91ab35aeddfd3 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 93baede806ad38b25f36e7023de44d3f1c49816b..2e1144a9b645d7a4d6f2277afe96f21a38bb2c28 100644 (file)
@@ -169,7 +169,7 @@ Method = ListMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # Function to convert any handle to a list and vv.
 ##f = Function(ListHandle, 'as_List', (Handle, 'h', InMode))
index ae9465ea142f76cc58a6010286642dedcb3bfd7d..46afe16532f08e037d3fe35b10ae169f493c0eab 100644 (file)
@@ -14,7 +14,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now doing 'import menusupport' ==="
     import menusupport
     print "=== Done.  It's up to you to compile Menumodule.c ==="
index a04b7553cb2c30af88e25d4cdcf963bc2ff997df..93d489b5ea1ca236de353c59a2733f5bca47657d 100644 (file)
@@ -96,8 +96,8 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
-execfile(EXTRAFILE)
+exec(open(INPUTFILE).read())
+exec(open(EXTRAFILE).read())
 
 # add the populated lists to the generator groups
 for f in functions: module.add(f)
index adecb4fbecc23b90e8c7771b071a69a69a374095..9566ad7d004004f90951a83c9f69ff4456b172b0 100644 (file)
@@ -20,7 +20,7 @@ def main():
     scanner.gentypetest(SHORT+"typetest.py")
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 8dcbed5bb631bd6373dd956e31b0683a222ff2fe..4adde0de9c318d5f440d769216c540909aadab8b 100644 (file)
@@ -128,7 +128,7 @@ OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
 UniChar = Type("UniChar", "h") # XXXX For now...
 # ADD object type here
 
-execfile("mltetypetest.py")
+exec(open("mltetypetest.py").read())
 
 # Our (opaque) objects
 
@@ -166,7 +166,7 @@ TXNObject_methods = []
 TXNFontMenuObject_methods = []
 
 # ADD _methods initializer here
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 
 # add the populated lists to the generator groups
index fb8196f67f03aa88b9b9b5411c9408cfb5e911d9..8bad4b7bd9dc7d828621d94e5f5b29acaa3629be 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.close()
     scanner.gentypetest(SHORT+"typetest.py")
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 8369932db0bf7d7cd290af916b4d9bcd5c53c4f7..3afdf4eb9dff28ec59cbbb1a4a6fa6e47bcea2ee 100644 (file)
@@ -88,12 +88,12 @@ Function = OSErrWeakLinkFunctionGenerator
 Method = OSErrWeakLinkMethodGenerator
 
 # Test which types we are still missing.
-execfile(string.lower(MODPREFIX) + 'typetest.py')
+exec(open(string.lower(MODPREFIX) + 'typetest.py').read())
 
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 85a8cdc04c1504da86528d212d63c7e460075b14..c601b0e9fd30672d2706efaaeb0d2243c6f3d3ca 100644 (file)
@@ -41,7 +41,7 @@ def main():
         ofp.close()
 
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     import qdsupport
     print "=== Done.  It's up to you to compile it now! ==="
index d078ac6cda0b0fe2727ac77612b59d00df5e09cd..28c2595284de3905cfd5ab7f6cb899488b644411 100644 (file)
@@ -269,8 +269,8 @@ functions = []
 gr_methods = []
 bm_methods = []
 #methods = []
-execfile(INPUTFILE)
-execfile(EXTRAFILE)
+exec(open(INPUTFILE).read())
+exec(open(EXTRAFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index d456e004e26f61cf47b577d089a4f20cc47f166f..7e8f3160537e06e5c198cd7c1289f1c5366ecf4a 100644 (file)
@@ -14,7 +14,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     import qdoffssupport
     print "=== Done.  It's up to you to compile it now! ==="
index 16177733d5db33b404b3af76919580c676669a27..73855a29e25d34889977885cfd1cae07d38927ab 100644 (file)
@@ -86,7 +86,7 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # A method to convert a GWorldPtr to a GrafPtr
 f = Method(GrafPtr, 'as_GrafPtr', (GWorldPtr, 'p', InMode))
index a2dba150184cd4686986d5645854855509b610a1..ac5614475973a7f4e670879066ce36ff709464e9 100644 (file)
@@ -35,7 +35,7 @@ def main():
     scanner.close()
     scanner.gentypetest(SHORT+"typetest.py")
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 132c2b4f6db96c6b0917b663ade76404f022aad4..4d7988f1af0d122a24c22a917612aefe34dabe63 100644 (file)
@@ -307,7 +307,7 @@ module.addobject(Movie_object)
 module.addobject(SGOutput_object)
 
 # Test which types we are still missing.
-execfile(string.lower(MODPREFIX) + 'typetest.py')
+exec(open(string.lower(MODPREFIX) + 'typetest.py').read())
 
 # Create the generator classes used to populate the lists
 Function = OSErrWeakLinkFunctionGenerator
@@ -323,7 +323,7 @@ Media_methods = []
 Track_methods = []
 Movie_methods = []
 SGOutput_methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 #
 # Some functions from ImageCompression.h that we need:
index 47a97e428551903963035b51cd2097a98443ea17..853fa136fdb10ef1ecd47fa015438f99dcb8ae03 100644 (file)
@@ -20,7 +20,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now doing 'import ressupport' ==="
     import ressupport
     print "=== Done 'import ressupport'.  It's up to you to compile Resmodule.c ==="
index 9e42a454232ad1b9405de7e48c3cc165edb3af0e..4eed9ec7a1d21c687b242d4a9bac33bfa8381ed4 100644 (file)
@@ -211,8 +211,8 @@ module.addobject(resobject)
 functions = []
 resmethods = []
 
-execfile('resgen.py')
-execfile('resedit.py')
+exec(open('resgen.py').read())
+exec(open('resedit.py').read())
 
 for f in functions: module.add(f)
 for f in resmethods: resobject.add(f)
index 1fc819126572c0deccd43b1d60a70ef0cb12942d..7521fba07cfb03d5a6d9407fc6b5d03c3d1095da 100644 (file)
@@ -20,7 +20,7 @@ def main():
     scanner.scan()
     scanner.close()
 ##      print "=== Testing definitions output code ==="
-##      execfile(defsoutput, {}, {})
+##      exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index 84a75d22a7b03ccd6a6829be12bced828a446e50..b4226a56544629bce29b57525f0592c2f933d9ad 100644 (file)
@@ -63,7 +63,7 @@ Method = OSErrMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index c4a82663db56f02ccc3e090e4f1e6bf39ca9a07e..bcdd0624094f79a6b65209bebd53c4a76c6bbd71 100644 (file)
@@ -17,7 +17,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now doing 'import sndsupport' ==="
     import sndsupport
     print "=== Done.  It's up to you to compile Sndmodule.c ==="
index cf0fa6ca5dedc938e9a8cc9c91632135d28c8673..5c5da5444234c314a0b7dbfadcf51d8ce4fa7481 100644 (file)
@@ -304,7 +304,7 @@ sndmethods = []
 
 # populate the lists
 
-execfile('sndgen.py')
+exec(open('sndgen.py').read())
 
 
 # add the functions and methods to the module and object, respectively
index f5b6fff4d4245028ad359cd418af5fe348428a70..c0d6e1c3105e3ea9d1ce2700c9742dab56708a20 100644 (file)
@@ -18,7 +18,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     exec "import " + SHORT + "support"
     print "=== Done.  It's up to you to compile it now! ==="
index ad6c053a46585119eeae7ed7ea8609d5b11084d6..412d5e7234682d4aecbfef348b09dc3706330855 100644 (file)
@@ -198,7 +198,7 @@ Method = TEMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # Converter from/to handle
 f = Function(TEHandle, 'as_TE', (Handle, 'h', InMode))
index f78935d0d513d9f264b9b65b967a9f03db79512a..8d2cea9a8c68ece54cb617766cc77abc002ab762 100644 (file)
@@ -14,7 +14,7 @@ def main():
     scanner.scan()
     scanner.close()
     print "=== Testing definitions output code ==="
-    execfile(defsoutput, {}, {})
+    exec(open(defsoutput).read(), {}, {})
     print "=== Done scanning and generating, now importing the generated code... ==="
     import winsupport
     print "=== Done.  It's up to you to compile it now! ==="
index 08a0379c539d15f8e87bb73d4d4ee731baee5da9..2cadbdcfb63e58b8cfec54167df48ea5f7e18cda 100644 (file)
@@ -191,7 +191,7 @@ Method = OSErrWeakLinkMethodGenerator
 # Create and populate the lists
 functions = []
 methods = []
-execfile(INPUTFILE)
+exec(open(INPUTFILE).read())
 
 # Add manual routines for converting integer WindowPtr's (as returned by
 # various event routines)  and Dialog objects to a WindowObject.
@@ -211,8 +211,8 @@ functions.append(f)
 
 # And add the routines that access the internal bits of a window struct. They
 # are currently #defined in Windows.h, they will be real routines in Copland
-# (at which time this execfile can go)
-execfile(EDITFILE)
+# (at which time this exec can go)
+exec(open(EDITFILE).read())
 
 # add the populated lists to the generator groups
 # (in a different wordl the scan program would generate this)
index 09d130200fe40a3e572f74a080c14a7c091f3668..b5a67db22d7dd3c08f9041e3656be99dd8ca14be 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -152,7 +152,7 @@ Core and Builtins
   backticks (ie, `x`), <>
 
 - Removed these Python builtins:
-  apply(), callable(), coerce(), file(), reduce(), reload()
+  apply(), callable(), coerce(), execfile(), file(), reduce(), reload()
 
 - Removed these Python methods:
   {}.has_key
index 38869312eaa16584b271e58a7a710979cc796d12..130b699a75acad1c7e3d52969436099f360f306e 100644 (file)
@@ -66,10 +66,10 @@ if exists("python_highlight_builtins")
   syn keyword pythonBuiltin    __import__ abs all any basestring bool
   syn keyword pythonBuiltin    buffer callable chr classmethod cmp
   syn keyword pythonBuiltin    complex copyright credits delattr dict
-  syn keyword pythonBuiltin    dir divmod enumerate eval execfile exit file
+  syn keyword pythonBuiltin    dir divmod enumerate eval exec exit
   syn keyword pythonBuiltin    filter float frozenset getattr globals hasattr
   syn keyword pythonBuiltin    hash help hex id int isinstance
-  syn keyword pythonBuiltin    issubclass iter len license list locals long map
+  syn keyword pythonBuiltin    issubclass iter len license list locals map
   syn keyword pythonBuiltin    max min object oct open ord pow property quit
   syn keyword pythonBuiltin    range reload repr reversed round
   syn keyword pythonBuiltin    set setattr slice sorted staticmethod str sum
index 3d344714f6f783d2c919fbfd15e4baae6fc527fc..c5304426996557c6e8a8a914d634df74b610997f 100644 (file)
@@ -282,11 +282,10 @@ None
 
 Numeric types
 
-Floats, integers and long integers.
+Floats and integers.
 
     Floats are implemented with C doubles.
-    Integers are implemented with C longs.
-    Long integers have unlimited size (only limit is system resources)
+    Integers have unlimited size (only limit is system resources)
 
 Operators on all numeric types
 
@@ -294,7 +293,6 @@ Operators on all numeric types
  Operation                    Result
 abs(x)       the absolute value of x
 int(x)       x converted to integer
-long(x)      x converted to long integer
 float(x)     x converted to floating point
 -x           x negated
 +x           x unchanged
@@ -306,7 +304,7 @@ x % y        remainder of x / y
 divmod(x, y) the tuple (x/y, x%y)
 x ** y       x to the power y (the same as pow(x, y))
 
-Bit operators on integers and long integers
+Bit operators on integers
 
               Bit operators
 Operation             >Result
@@ -948,9 +946,6 @@ enumerate(seq)      Return a iterator giving:  (0, seq[0]), (1, seq[1]), ...
 eval(s[, globals[,  Eval string s in (optional) globals, locals contexts.s must
 locals]])           have no NUL's or newlines. s can also be acode object.
                     Example: x = 1; incr_x = eval('x + 1')
-execfile(file[,     Executes a file without creating a new module, unlike
-globals[, locals]]) import.
-file()              Synonym for open().
 filter(function,    Constructs a list from those elements of sequence for which
 sequence)           function returns true. function takes one parameter.
 float(x)            Converts a number or a string to floating point.
@@ -977,9 +972,6 @@ len(obj)            (sequence, dictionary, or instance of class implementing
 list(sequence)      Converts sequence into a list. If already a list,returns a
                     copy of it.
 locals()            Returns a dictionary containing current local variables.
-                    Converts a number or a string to a long integer. Optional
-long(x[, base])     base paramenter specifies base from which to convert string
-                    values.
                     Applies function to every item of list and returns a listof
 map(function, list, the results. If additional arguments are passed,function
 ...)                must take that many arguments and it is givento function on
@@ -1167,7 +1159,7 @@ Operators
         s^=o      =  __ixor__(s,o)        s|=o       =  __ior__(s,o)
         s<<=o     =  __ilshift__(s,o)     s>>=o      =  __irshift__(s,o)
         Conversions
-        int(s)    =  __int__(s)           long(s)    =  __long__(s)
+        int(s)    =  __int__(s)
         float(s)  =  __float__(s)         complex(s)    =  __complex__(s)
         oct(s)    =  __oct__(s)           hex(s)     =  __hex__(s)
         Right-hand-side equivalents for all binary operators exist;
index 55ba60246da687b2049e536f7c1026489846b6b7..5d9af67cf43add7616e1239e6673e157fc9921c4 100644 (file)
@@ -380,7 +380,7 @@ support for features needed by `python-mode'.")
                          "bool" "buffer" "callable" "chr" "classmethod"
                          "cmp" "compile" "complex" "copyright"
                          "delattr" "dict" "dir" "divmod"
-                         "enumerate" "eval" "execfile" "exit" "file"
+                         "enumerate" "eval" "exit" "file"
                          "filter" "float" "getattr" "globals" "hasattr"
                          "hash" "hex" "id" "int"
                          "isinstance" "issubclass" "iter" "len" "license"
@@ -1262,7 +1262,7 @@ comment."
 \f
 ;; Python subprocess utilities and filters
 (defun py-execute-file (proc filename)
-  "Send to Python interpreter process PROC \"execfile('FILENAME')\".
+  "Send to Python interpreter process PROC \"exec(open('FILENAME').read())\".
 Make that process's buffer visible and force display.  Also make
 comint believe the user typed this string so that
 `kill-output-from-shell' does The Right Thing."
@@ -1270,7 +1270,7 @@ comint believe the user typed this string so that
        (procbuf (process-buffer proc))
 ;      (comint-scroll-to-bottom-on-output t)
        (msg (format "## working on region in file %s...\n" filename))
-       (cmd (format "execfile(r'%s')\n" filename)))
+       (cmd (format "exec(open(r'%s').read())\n" filename)))
     (unwind-protect
        (save-excursion
          (set-buffer procbuf)
@@ -1606,7 +1606,7 @@ specify the region to execute, and optional third argument ASYNC, if
 non-nil, specifies to run the command asynchronously in its own
 buffer.
 
-If the Python interpreter shell is running, the region is execfile()'d
+If the Python interpreter shell is running, the region is exec()'d
 in that shell.  If you try to execute regions too quickly,
 `python-mode' will queue them up and execute them one at a time when
 it sees a `>>> ' prompt from Python.  Each time this happens, the
@@ -1731,7 +1731,7 @@ subtleties, including the use of the optional ASYNC argument."
 If the file has already been imported, then do reload instead to get
 the latest version.
 
-If the file's name does not end in \".py\", then do execfile instead.
+If the file's name does not end in \".py\", then do exec instead.
 
 If the current buffer is not visiting a file, do `py-execute-buffer'
 instead.
@@ -1768,7 +1768,7 @@ This may be preferable to `\\[py-execute-buffer]' because:
                         (file-name-nondirectory file))))
                  (format "if globals().has_key('%s'):\n    reload(%s)\nelse:\n    import %s\n"
                          f f f))
-             (format "execfile(r'%s')\n" file))
+             (format "exec(open(r'%s'))\n" file))
            async))
       ;; else
       (py-execute-buffer async))))
index 34bca682d0ef5fc4a7be38c5dbe02f2eb35b7d36..8175404212711a48fc699b187625a99da9615f73 100644 (file)
@@ -317,7 +317,7 @@ Py_UniversalNewlineFgets(char *buf, int n, FILE *stream, PyObject *fobj)
                ** will cause a pause if we're reading from an
                ** interactive stream, but that is very unlikely
                ** unless we're doing something silly like
-               ** execfile("/dev/tty").
+               ** exec(open("/dev/tty").read()).
                */
                c = GETC(stream);
                if ( c != '\n' )
index 2f4e5131525aa51f1a803b6564f1a7db70953557..b6a7327d615cf993e44d8e196fde48f2b9adfc7e 100644 (file)
@@ -641,107 +641,6 @@ The globals and locals are dictionaries, defaulting to the current\n\
 globals and locals.  If only globals is given, locals defaults to it.");
 
 
-static PyObject *
-builtin_execfile(PyObject *self, PyObject *args)
-{
-       char *filename;
-       PyObject *globals = Py_None, *locals = Py_None;
-       PyObject *res;
-       FILE* fp = NULL;
-       PyCompilerFlags cf;
-       int exists;
-
-       if (!PyArg_ParseTuple(args, "s|O!O:execfile",
-                       &filename,
-                       &PyDict_Type, &globals,
-                       &locals))
-               return NULL;
-       if (locals != Py_None && !PyMapping_Check(locals)) {
-               PyErr_SetString(PyExc_TypeError, "locals must be a mapping");
-               return NULL;
-       }
-       if (globals == Py_None) {
-               globals = PyEval_GetGlobals();
-               if (locals == Py_None)
-                       locals = PyEval_GetLocals();
-       }
-       else if (locals == Py_None)
-               locals = globals;
-       if (PyDict_GetItemString(globals, "__builtins__") == NULL) {
-               if (PyDict_SetItemString(globals, "__builtins__",
-                                        PyEval_GetBuiltins()) != 0)
-                       return NULL;
-       }
-
-       exists = 0;
-       /* Test for existence or directory. */
-#if defined(PLAN9)
-       {
-               Dir *d;
-
-               if ((d = dirstat(filename))!=nil) {
-                       if(d->mode & DMDIR)
-                               werrstr("is a directory");
-                       else
-                               exists = 1;
-                       free(d);
-               }
-       }
-#elif defined(RISCOS)
-       if (object_exists(filename)) {
-               if (isdir(filename))
-                       errno = EISDIR;
-               else
-                       exists = 1;
-       }
-#else  /* standard Posix */
-       {
-               struct stat s;
-               if (stat(filename, &s) == 0) {
-                       if (S_ISDIR(s.st_mode))
-#                              if defined(PYOS_OS2) && defined(PYCC_VACPP)
-                                       errno = EOS2ERR;
-#                              else
-                                       errno = EISDIR;
-#                              endif
-                       else
-                               exists = 1;
-               }
-       }
-#endif
-
-        if (exists) {
-               Py_BEGIN_ALLOW_THREADS
-               fp = fopen(filename, "r" PY_STDIOTEXTMODE);
-               Py_END_ALLOW_THREADS
-
-               if (fp == NULL) {
-                       exists = 0;
-               }
-        }
-
-       if (!exists) {
-               PyErr_SetFromErrnoWithFilename(PyExc_IOError, filename);
-               return NULL;
-       }
-       cf.cf_flags = 0;
-       if (PyEval_MergeCompilerFlags(&cf))
-               res = PyRun_FileExFlags(fp, filename, Py_file_input, globals,
-                                  locals, 1, &cf);
-       else
-               res = PyRun_FileEx(fp, filename, Py_file_input, globals,
-                                  locals, 1);
-       return res;
-}
-
-PyDoc_STRVAR(execfile_doc,
-"execfile(filename[, globals[, locals]])\n\
-\n\
-Read and execute a Python script from a file.\n\
-The globals and locals are dictionaries, defaulting to the current\n\
-globals and locals.  If only globals is given, locals defaults to it.");
-
-
 static PyObject *
 builtin_getattr(PyObject *self, PyObject *args)
 {
@@ -1737,7 +1636,6 @@ static PyMethodDef builtin_methods[] = {
        {"divmod",      builtin_divmod,     METH_VARARGS, divmod_doc},
        {"eval",        builtin_eval,       METH_VARARGS, eval_doc},
        {"exec",        builtin_exec,       METH_VARARGS, exec_doc},
-       {"execfile",    builtin_execfile,   METH_VARARGS, execfile_doc},
        {"filter",      builtin_filter,     METH_VARARGS, filter_doc},
        {"getattr",     builtin_getattr,    METH_VARARGS, getattr_doc},
        {"globals",     (PyCFunction)builtin_globals,    METH_NOARGS, globals_doc},
diff --git a/README b/README
index 4fecd7a68f01a029d16c898fbf20bdc68fcb9b31..ef9f45222e1f44fdf1c632d5e177f083aaeca0b1 100644 (file)
--- a/README
+++ b/README
@@ -1101,7 +1101,7 @@ Modules/getpath.o.
 --with(out)-universal-newlines: enable reading of text files with
         foreign newline convention (default: enabled). In other words,
         any of \r, \n or \r\n is acceptable as end-of-line character.
-        If enabled import and execfile will automatically accept any newline
+        If enabled import will automatically accept any newline
         in files. Python code can open a file with open(file, 'U') to
         read it in universal newline mode. THIS OPTION IS UNSUPPORTED.
 
index 4f406284bd86592c525e65c3115de1d80e6a82dc..7e39d98579e5005f56cefc617aa7d58ca9c51af4 100644 (file)
@@ -23,7 +23,12 @@ def run_hotshot(filename, profile, args):
     prof = hotshot.Profile(profile)
     sys.path.insert(0, os.path.dirname(filename))
     sys.argv = [filename] + args
-    prof.run("execfile(%r)" % filename)
+    fp = open(filename)
+    try:
+        script = fp.read()
+    finally:
+        fp.close()
+    prof.run("exec(%r)" % script)
     prof.close()
     stats = hotshot.stats.load(profile)
     stats.sort_stats("time", "calls")
index a51411b042586ebcce95eef564880ea57f320a8b..1dd2eca45e4ccfc0fc0b76cacde0d128b927ff77 100644 (file)
@@ -19,7 +19,7 @@ your distribution. In stead of a single URL you can also specify a list
 of URLs. Each of these will be checked in order until one is available,
 this is handy for distributions that live in multiple places. Put the
 primary distribution site (the most up-to-date site) before others.
-The script is executed with execfile(), not imported, and the current
+The script is read and executed with exec(), not imported, and the current
 directory is the checkversion directory, so be careful with globals,
 importing, etc.
 
index 27c16e7b4448dd39b46973d03377a6d50d5ab263..ccb544d4c136b518884ddacdc696b3d5a4f4bd7e 100644 (file)
@@ -26,7 +26,7 @@ def check1dir(dummy, dir, files):
     if CHECKNAME in files:
         fullname = os.path.join(dir, CHECKNAME)
         try:
-            execfile(fullname)
+            exec(open(fullname).read())
         except:
             print('** Exception in', fullname)
 
index 9c8bd4bfff13403a7a20bc3f3558c436d866551c..f0191de175fadcc73c5334173457c62442728f5f 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1369,7 +1369,12 @@ class PyBuildExt(build_ext):
                     return False
 
             fficonfig = {}
-            execfile(ffi_configfile, globals(), fficonfig)
+            fp = open(ffi_configfile)
+            try:
+                script = fp.read()
+            finally:
+                fp.close()
+            exec(script, globals(), fficonfig)
             ffi_srcdir = os.path.join(fficonfig['ffi_srcdir'], 'src')
 
             # Add .S (preprocessed assembly) to C compiler source extensions.