Commit ba04afa3 authored by Guido van Rossum's avatar Guido van Rossum

SF patch 1631942 by Collin Winter:

(a) "except E, V" -> "except E as V"
(b) V is now limited to a simple name (local variable)
(c) V is now deleted at the end of the except block
parent 6c3e3687
......@@ -115,7 +115,7 @@ class BCPPCompiler(CCompiler) :
# This needs to be compiled to a .res file -- do it now.
try:
self.spawn (["brcc32", "-fo", obj, src])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
continue # the 'for' loop
......@@ -139,7 +139,7 @@ class BCPPCompiler(CCompiler) :
self.spawn ([self.cc] + compile_opts + pp_opts +
[input_opt, output_opt] +
extra_postargs + [src])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
return objects
......@@ -164,7 +164,7 @@ class BCPPCompiler(CCompiler) :
pass # XXX what goes here?
try:
self.spawn ([self.lib] + lib_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LibError, msg
else:
log.debug("skipping %s (up-to-date)", output_filename)
......@@ -298,7 +298,7 @@ class BCPPCompiler(CCompiler) :
self.mkpath (os.path.dirname (output_filename))
try:
self.spawn ([self.linker] + ld_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LinkError, msg
else:
......@@ -391,7 +391,7 @@ class BCPPCompiler(CCompiler) :
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
print msg
raise CompileError, msg
......
......@@ -284,11 +284,11 @@ Your selection [default 1]: ''',
data = ''
try:
result = opener.open(req)
except urllib2.HTTPError, e:
except urllib2.HTTPError as e:
if self.show_response:
data = e.fp.read()
result = e.code, e.msg
except urllib2.URLError, e:
except urllib2.URLError as e:
result = 500, str(e)
else:
if self.show_response:
......
......@@ -333,7 +333,7 @@ class sdist (Command):
try:
self.filelist.process_template_line(line)
except DistutilsTemplateError, msg:
except DistutilsTemplateError as msg:
self.warn("%s, line %d: %s" % (template.filename,
template.current_line,
msg))
......
......@@ -184,7 +184,7 @@ class upload(Command):
http.putheader('Authorization', auth)
http.endheaders()
http.send(body)
except socket.error, e:
except socket.error as e:
self.announce(str(e), log.ERROR)
return
......
......@@ -110,7 +110,7 @@ def setup (**attrs):
# (ie. everything except distclass) to initialize it
try:
_setup_distribution = dist = klass(attrs)
except DistutilsSetupError, msg:
except DistutilsSetupError as msg:
if 'name' not in attrs:
raise SystemExit, "error in %s setup command: %s" % \
(attrs['name'], msg)
......@@ -135,7 +135,7 @@ def setup (**attrs):
# fault, so turn them into SystemExit to suppress tracebacks.
try:
ok = dist.parse_command_line()
except DistutilsArgError, msg:
except DistutilsArgError as msg:
raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
if DEBUG:
......@@ -151,7 +151,7 @@ def setup (**attrs):
dist.run_commands()
except KeyboardInterrupt:
raise SystemExit, "interrupted"
except (IOError, os.error), exc:
except (IOError, os.error) as exc:
error = grok_environment_error(exc)
if DEBUG:
......@@ -161,7 +161,7 @@ def setup (**attrs):
raise SystemExit, error
except (DistutilsError,
CCompilerError), msg:
CCompilerError) as msg:
if DEBUG:
raise
else:
......
......@@ -142,13 +142,13 @@ class CygwinCCompiler (UnixCCompiler):
# gcc needs '.res' and '.rc' compiled to object files !!!
try:
self.spawn(["windres", "-i", src, "-o", obj])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
else: # for other files use the C-compiler
try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
def link (self,
......@@ -379,7 +379,7 @@ def check_config_h():
s = f.read()
f.close()
except IOError, exc:
except IOError as exc:
# if we can't read this file, we cannot say it is wrong
# the compiler will complain later about this file as missing
return (CONFIG_H_UNCERTAIN,
......
......@@ -75,7 +75,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
try:
os.mkdir(head)
created_dirs.append(head)
except OSError, exc:
except OSError as exc:
raise DistutilsFileError, \
"could not create '%s': %s" % (head, exc[-1])
......@@ -142,7 +142,8 @@ def copy_tree (src, dst,
"cannot copy tree '%s': not a directory" % src
try:
names = os.listdir(src)
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
if dry_run:
names = []
else:
......@@ -209,7 +210,7 @@ def remove_tree (directory, verbose=0, dry_run=0):
abspath = os.path.abspath(cmd[1])
if abspath in _path_created:
del _path_created[abspath]
except (IOError, OSError), exc:
except (IOError, OSError) as exc:
log.warn(grok_environment_error(
exc, "error removing %s: " % directory))
......
......@@ -398,7 +398,7 @@ Common commands: (see '--help-commands' for more)
setattr(self, opt, strtobool(val))
else:
setattr(self, opt, val)
except ValueError, msg:
except ValueError as msg:
raise DistutilsOptionError, msg
# parse_config_files ()
......@@ -515,7 +515,7 @@ Common commands: (see '--help-commands' for more)
# it takes.
try:
cmd_class = self.get_command_class(command)
except DistutilsModuleError, msg:
except DistutilsModuleError as msg:
raise DistutilsArgError, msg
# Require that the command class be derived from Command -- want
......@@ -917,7 +917,7 @@ Common commands: (see '--help-commands' for more)
raise DistutilsOptionError, \
("error in %s: command '%s' has no such option '%s'"
% (source, command_name, option))
except ValueError, msg:
except ValueError as msg:
raise DistutilsOptionError, msg
def reinitialize_command (self, command, reinit_subcommands=0):
......
......@@ -79,13 +79,13 @@ class EMXCCompiler (UnixCCompiler):
# gcc requires '.rc' compiled to binary ('.res') files !!!
try:
self.spawn(["rc", "-r", src])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
else: # for other files use the C-compiler
try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
def link (self,
......@@ -275,7 +275,7 @@ def check_config_h():
s = f.read()
f.close()
except IOError, exc:
except IOError as exc:
# if we can't read this file, we cannot say it is wrong
# the compiler will complain later about this file as missing
return (CONFIG_H_UNCERTAIN,
......
......@@ -256,7 +256,7 @@ class FancyGetopt:
short_opts = string.join(self.short_opts)
try:
opts, args = getopt.getopt(args, short_opts, self.long_opts)
except getopt.error, msg:
except getopt.error as msg:
raise DistutilsArgError, msg
for opt, val in opts:
......
......@@ -32,27 +32,31 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
try:
try:
fsrc = open(src, 'rb')
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
raise DistutilsFileError, \
"could not open '%s': %s" % (src, errstr)
if os.path.exists(dst):
try:
os.unlink(dst)
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
raise DistutilsFileError, \
"could not delete '%s': %s" % (dst, errstr)
try:
fdst = open(dst, 'wb')
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
raise DistutilsFileError, \
"could not create '%s': %s" % (dst, errstr)
while 1:
try:
buf = fsrc.read(buffer_size)
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
raise DistutilsFileError, \
"could not read from '%s': %s" % (src, errstr)
......@@ -61,7 +65,8 @@ def _copy_file_contents (src, dst, buffer_size=16*1024):
try:
fdst.write(buf)
except os.error, (errno, errstr):
except os.error as e:
(errno, errstr) = e
raise DistutilsFileError, \
"could not write to '%s': %s" % (dst, errstr)
......@@ -146,7 +151,7 @@ def copy_file (src, dst,
import macostools
try:
macostools.copy(src, dst, 0, preserve_times)
except os.error, exc:
except os.error as exc:
raise DistutilsFileError, \
"could not copy '%s' to '%s': %s" % (src, dst, exc[-1])
......@@ -217,7 +222,8 @@ def move_file (src, dst,
copy_it = 0
try:
os.rename(src, dst)
except os.error, (num, msg):
except os.error as e:
(num, msg) = e
if num == errno.EXDEV:
copy_it = 1
else:
......@@ -228,7 +234,8 @@ def move_file (src, dst,
copy_file(src, dst)
try:
os.unlink(src)
except os.error, (num, msg):
except os.error as e:
(num, msg) = e
try:
os.unlink(dst)
except os.error:
......
......@@ -129,7 +129,7 @@ class MacroExpander:
self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
else:
self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
except KeyError, exc: #
except KeyError as exc: #
raise DistutilsPlatformError, \
("""Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
......@@ -371,7 +371,7 @@ class MSVCCompiler (CCompiler) :
try:
self.spawn ([self.rc] + pp_opts +
[output_opt] + [input_opt])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
continue
elif ext in self._mc_extensions:
......@@ -400,7 +400,7 @@ class MSVCCompiler (CCompiler) :
self.spawn ([self.rc] +
["/fo" + obj] + [rc_file])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
continue
else:
......@@ -414,7 +414,7 @@ class MSVCCompiler (CCompiler) :
self.spawn ([self.cc] + compile_opts + pp_opts +
[input_opt, output_opt] +
extra_postargs)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
return objects
......@@ -440,7 +440,7 @@ class MSVCCompiler (CCompiler) :
pass # XXX what goes here?
try:
self.spawn ([self.lib] + lib_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LibError, msg
else:
......@@ -519,7 +519,7 @@ class MSVCCompiler (CCompiler) :
self.mkpath (os.path.dirname (output_filename))
try:
self.spawn ([self.linker] + ld_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LinkError, msg
else:
......
......@@ -78,7 +78,7 @@ def _spawn_nt (cmd,
# spawn for NT requires a full path to the .exe
try:
rc = os.spawnv(os.P_WAIT, executable, cmd)
except OSError, exc:
except OSError as exc:
# this seems to happen when the command isn't found
raise DistutilsExecError, \
"command '%s' failed: %s" % (cmd[0], exc[-1])
......@@ -103,7 +103,7 @@ def _spawn_os2 (cmd,
# spawnv for OS/2 EMX requires a full path to the .exe
try:
rc = os.spawnv(os.P_WAIT, executable, cmd)
except OSError, exc:
except OSError as exc:
# this seems to happen when the command isn't found
raise DistutilsExecError, \
"command '%s' failed: %s" % (cmd[0], exc[-1])
......@@ -131,7 +131,7 @@ def _spawn_posix (cmd,
#print "cmd[0] =", cmd[0]
#print "cmd =", cmd
exec_fn(cmd[0], cmd)
except OSError, e:
except OSError as e:
sys.stderr.write("unable to execute %s: %s\n" %
(cmd[0], e.strerror))
os._exit(1)
......@@ -146,7 +146,7 @@ def _spawn_posix (cmd,
while 1:
try:
(pid, status) = os.waitpid(pid, 0)
except OSError, exc:
except OSError as exc:
import errno
if exc.errno == errno.EINTR:
continue
......
......@@ -344,7 +344,7 @@ def _init_posix():
try:
filename = get_makefile_filename()
parse_makefile(filename, g)
except IOError, msg:
except IOError as msg:
my_msg = "invalid Python installation: unable to open %s" % filename
if hasattr(msg, "strerror"):
my_msg = my_msg + " (%s)" % msg.strerror
......@@ -355,7 +355,7 @@ def _init_posix():
try:
filename = get_config_h_filename()
parse_config_h(open(filename), g)
except IOError, msg:
except IOError as msg:
my_msg = "invalid Python installation: unable to open %s" % filename
if hasattr(msg, "strerror"):
my_msg = my_msg + " (%s)" % msg.strerror
......
......@@ -162,7 +162,7 @@ class UnixCCompiler(CCompiler):
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
......@@ -172,7 +172,7 @@ class UnixCCompiler(CCompiler):
try:
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise CompileError, msg
def create_static_lib(self, objects, output_libname,
......@@ -196,7 +196,7 @@ class UnixCCompiler(CCompiler):
if self.ranlib:
try:
self.spawn(self.ranlib + [output_filename])
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LibError, msg
else:
log.debug("skipping %s (up-to-date)", output_filename)
......@@ -250,7 +250,7 @@ class UnixCCompiler(CCompiler):
linker = _darwin_compiler_fixup(linker, ld_args)
self.spawn(linker + ld_args)
except DistutilsExecError, msg:
except DistutilsExecError as msg:
raise LinkError, msg
else:
log.debug("skipping %s (up-to-date)", output_filename)
......
......@@ -229,7 +229,7 @@ def subst_vars (s, local_vars):
try:
return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, s)
except KeyError, var:
except KeyError as var:
raise ValueError, "invalid variable '$%s'" % var
# subst_vars ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment