Skip to content

Commit

Permalink
SF patch 1631942 by Collin Winter:
Browse files Browse the repository at this point in the history
(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
  • Loading branch information
gvanrossum committed Jan 10, 2007
1 parent 893523e commit b940e11
Show file tree
Hide file tree
Showing 295 changed files with 817 additions and 743 deletions.
2 changes: 1 addition & 1 deletion Demo/cgi/wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@ def store(self):
f.write('\n')
f.close()
return ""
except IOError, err:
except IOError as err:
return "IOError: %s" % str(err)
2 changes: 1 addition & 1 deletion Demo/comparisons/regextest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def main():
for file in sys.argv[1:]:
try:
fp = open(file, 'r')
except IOError, msg:
except IOError as msg:
print "%s: %s" % (file, msg)
continue
lineno = 0
Expand Down
4 changes: 2 additions & 2 deletions Demo/comparisons/systemtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
def reportboguslinks(prefix):
try:
names = os.listdir('.')
except os.error, msg:
except os.error as msg:
print "%s%s: can't list: %s" % (prefix, '.', msg)
return
names.sort()
Expand All @@ -62,7 +62,7 @@ def reportboguslinks(prefix):
elif S_ISDIR(mode):
try:
os.chdir(name)
except os.error, msg:
except os.error as msg:
print "%s%s: can't chdir: %s" % \
(prefix, name, msg)
continue
Expand Down
2 changes: 1 addition & 1 deletion Demo/parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def testChunk(t, fileName):
# against a large source file like Tkinter.py.
ast = None
new = parser.tuple2ast(tup)
except parser.ParserError, err:
except parser.ParserError as err:
print
print 'parser module raised exception on input file', fileName + ':'
traceback.print_exc()
Expand Down
2 changes: 1 addition & 1 deletion Demo/parser/unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def testdir(a):
print 'Testing %s' % fullname
try:
roundtrip(fullname, output)
except Exception, e:
except Exception as e:
print ' Failed to compile, exception is %s' % repr(e)
elif os.path.isdir(fullname):
testdir(fullname)
Expand Down
2 changes: 1 addition & 1 deletion Demo/pdist/FSProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def visible(self, name):
fs = macfs.FSSpec(name)
c, t = fs.GetCreatorType()
if t != 'TEXT': return 0
except macfs.error, msg:
except macfs.error as msg:
print "***", name, msg
return 0
else:
Expand Down
4 changes: 2 additions & 2 deletions Demo/pdist/cmdfw.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self, args = None):
if args is None: args = sys.argv[1:]
try:
opts, args = getopt.getopt(args, self.GlobalFlags)
except getopt.error, msg:
except getopt.error as msg:
return self.usage(msg)
self.options(opts)
if not args:
Expand All @@ -62,7 +62,7 @@ def run(self, args = None):
flags = ''
try:
opts, args = getopt.getopt(args[1:], flags)
except getopt.error, msg:
except getopt.error as msg:
return self.usage(
"subcommand %s: " % cmd + str(msg))
self.ready()
Expand Down
4 changes: 2 additions & 2 deletions Demo/pdist/cmptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def compare(local, remote, mode):
def sendfile(local, remote, name):
try:
remote.create(name)
except (IOError, os.error), msg:
except (IOError, os.error) as msg:
print "cannot create:", msg
return

Expand Down Expand Up @@ -171,7 +171,7 @@ def recvfile(local, remote, name):
def recvfile_real(local, remote, name):
try:
local.create(name)
except (IOError, os.error), msg:
except (IOError, os.error) as msg:
print "cannot create:", msg
return

Expand Down
4 changes: 2 additions & 2 deletions Demo/pdist/cvslock.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def setlockdir(self):
self.lockdir = self.cvslck
os.mkdir(self.cvslck, 0777)
return
except os.error, msg:
except os.error as msg:
self.lockdir = None
if msg[0] == EEXIST:
try:
Expand Down Expand Up @@ -234,7 +234,7 @@ def MultipleWriteLock(repositories, delay = DELAY):
for r in repositories:
try:
locks.append(WriteLock(r, 0))
except Locked, instance:
except Locked as instance:
del locks
break
else:
Expand Down
4 changes: 2 additions & 2 deletions Demo/pdist/rrcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
raise getopt.error, "unknown command"
coptset, func = commands[cmd]
copts, files = getopt.getopt(rest, coptset)
except getopt.error, msg:
except getopt.error as msg:
print msg
print "usage: rrcs [options] command [options] [file] ..."
print "where command can be:"
Expand All @@ -41,7 +41,7 @@ def main():
for fn in files:
try:
func(x, copts, fn)
except (IOError, os.error), msg:
except (IOError, os.error) as msg:
print "%s: %s" % (fn, msg)

def checkin(x, copts, fn):
Expand Down
10 changes: 5 additions & 5 deletions Demo/pysvr/pysvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def main():
opts, args = getopt.getopt(sys.argv[1:], "")
if len(args) > 1:
raise getopt.error, "Too many arguments."
except getopt.error, msg:
except getopt.error as msg:
usage(msg)
for o, a in opts:
pass
if args:
try:
port = string.atoi(args[0])
except ValueError, msg:
except ValueError as msg:
usage(msg)
else:
port = PORT
Expand Down Expand Up @@ -83,7 +83,7 @@ def run_interpreter(stdin, stdout):
source = source + line
try:
code = compile_command(source)
except SyntaxError, err:
except SyntaxError as err:
source = ""
traceback.print_exception(SyntaxError, err, None, file=stdout)
continue
Expand All @@ -92,7 +92,7 @@ def run_interpreter(stdin, stdout):
source = ""
try:
run_command(code, stdin, stdout, globals)
except SystemExit, how:
except SystemExit as how:
if how:
try:
how = str(how)
Expand All @@ -109,7 +109,7 @@ def run_command(code, stdin, stdout, globals):
sys.stdin = stdin
try:
exec(code, globals)
except SystemExit, how:
except SystemExit as how:
raise SystemExit, how, sys.exc_info()[2]
except:
type, value, tb = sys.exc_info()
Expand Down
3 changes: 1 addition & 2 deletions Demo/rpc/nfsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ def test():
fh = sf[1]
if fh:
ncl = NFSClient(host)
as = ncl.Getattr(fh)
print as
print ncl.Getattr(fh)
list = ncl.Listdir(fh)
for item in list: print item
mcl.Umnt(filesys)
7 changes: 4 additions & 3 deletions Demo/rpc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def bindresvport(sock, host):
try:
sock.bind((host, i))
return last_resv_port_tried
except socket.error, (errno, msg):
except socket.error as e:
(errno, msg) = e
if errno != 114:
raise socket.error, (errno, msg)
raise RuntimeError, 'can\'t assign reserved port'
Expand Down Expand Up @@ -765,7 +766,7 @@ def session(self, connection):
call = recvrecord(sock)
except EOFError:
break
except socket.error, msg:
except socket.error as msg:
print 'socket error:', msg
break
reply = self.handle(call)
Expand Down Expand Up @@ -866,7 +867,7 @@ def handle_1(self):
s = S('', 0x20000000, 1, 0)
try:
s.unregister()
except RuntimeError, msg:
except RuntimeError as msg:
print 'RuntimeError:', msg, '(ignored)'
s.register()
print 'Service started...'
Expand Down
12 changes: 6 additions & 6 deletions Demo/scripts/eqfix.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def recursedown(dirname):
bad = 0
try:
names = os.listdir(dirname)
except os.error, msg:
except os.error as msg:
err('%s: cannot list directory: %r\n' % (dirname, msg))
return 1
names.sort()
Expand All @@ -83,7 +83,7 @@ def fix(filename):
## dbg('fix(%r)\n' % (dirname,))
try:
f = open(filename, 'r')
except IOError, msg:
except IOError as msg:
err('%s: cannot open: %r\n' % (filename, msg))
return 1
head, tail = os.path.split(filename)
Expand Down Expand Up @@ -120,7 +120,7 @@ def fix(filename):
if g is None:
try:
g = open(tempname, 'w')
except IOError, msg:
except IOError as msg:
f.close()
err('%s: cannot create: %r\n' % (tempname, msg))
return 1
Expand All @@ -144,17 +144,17 @@ def fix(filename):
try:
statbuf = os.stat(filename)
os.chmod(tempname, statbuf[ST_MODE] & 07777)
except os.error, msg:
except os.error as msg:
err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
# Then make a backup of the original file as filename~
try:
os.rename(filename, filename + '~')
except os.error, msg:
except os.error as msg:
err('%s: warning: backup failed (%r)\n' % (filename, msg))
# Now move the temp file to the original file
try:
os.rename(tempname, filename)
except os.error, msg:
except os.error as msg:
err('%s: rename failed (%r)\n' % (filename, msg))
return 1
# Return succes
Expand Down
4 changes: 2 additions & 2 deletions Demo/scripts/ftpstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
search = None
try:
opts, args = getopt.getopt(sys.argv[1:], 'm:s:')
except getopt.error, msg:
except getopt.error as msg:
print msg
print 'usage: ftpstats [-m maxitems] [file]'
sys.exit(2)
Expand All @@ -41,7 +41,7 @@ def main():
else:
try:
f = open(file, 'r')
except IOError, msg:
except IOError as msg:
print file, ':', msg
sys.exit(1)
bydate = {}
Expand Down
6 changes: 3 additions & 3 deletions Demo/scripts/mboxconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def main():
dofile = mmdf
try:
opts, args = getopt.getopt(sys.argv[1:], 'f')
except getopt.error, msg:
except getopt.error as msg:
sys.stderr.write('%s\n' % msg)
sys.exit(2)
for o, a in opts:
Expand All @@ -33,7 +33,7 @@ def main():
elif os.path.isfile(arg):
try:
f = open(arg)
except IOError, msg:
except IOError as msg:
sys.stderr.write('%s: %s\n' % (arg, msg))
sts = 1
continue
Expand All @@ -56,7 +56,7 @@ def mh(dir):
fn = os.path.join(dir, msg)
try:
f = open(fn)
except IOError, msg:
except IOError as msg:
sys.stderr.write('%s: %s\n' % (fn, msg))
sts = 1
continue
Expand Down
2 changes: 1 addition & 1 deletion Demo/scripts/newslist.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def main():
else:
s = NNTP(newshost)
connected = 1
except (nntplib.error_temp, nntplib.error_perm), x:
except (nntplib.error_temp, nntplib.error_perm) as x:
print 'Error connecting to host:', x
print 'I\'ll try to use just the local list.'
connected = 0
Expand Down
2 changes: 1 addition & 1 deletion Demo/scripts/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

try:
optlist, ARGS = getopt.getopt(sys.argv[1:], 'acde:F:np')
except getopt.error, msg:
except getopt.error as msg:
sys.stderr.write(sys.argv[0] + ': ' + msg + '\n')
sys.exit(2)

Expand Down
6 changes: 3 additions & 3 deletions Demo/scripts/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, filename):
self.changed = 0
try:
self.lines = open(filename, 'r').readlines()
except IOError, msg:
except IOError as msg:
print '*** Can\'t open "%s":' % filename, msg
self.lines = None
return
Expand All @@ -32,7 +32,7 @@ def finish(self):
try:
os.rename(self.filename, self.filename + '~')
fp = open(self.filename, 'w')
except (os.error, IOError), msg:
except (os.error, IOError) as msg:
print '*** Can\'t rewrite "%s":' % self.filename, msg
return
print 'writing', self.filename
Expand Down Expand Up @@ -67,7 +67,7 @@ def main():
if sys.argv[1:]:
try:
fp = open(sys.argv[1], 'r')
except IOError, msg:
except IOError as msg:
print 'Can\'t open "%s":' % sys.argv[1], msg
sys.exit(1)
else:
Expand Down
10 changes: 5 additions & 5 deletions Demo/sockets/gopher.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def browser(*args):
raise RuntimeError, 'too many args'
try:
browse_menu(selector, host, port)
except socket.error, msg:
except socket.error as msg:
print 'Socket error:', msg
sys.exit(1)
except KeyboardInterrupt:
Expand Down Expand Up @@ -202,7 +202,7 @@ def browse_textfile(selector, host, port):
p = os.popen('${PAGER-more}', 'w')
x = SaveLines(p)
get_alt_textfile(selector, host, port, x.writeln)
except IOError, msg:
except IOError as msg:
print 'IOError:', msg
if x:
x.close()
Expand All @@ -213,7 +213,7 @@ def browse_textfile(selector, host, port):
try:
get_alt_textfile(selector, host, port, x.writeln)
print 'Done.'
except IOError, msg:
except IOError as msg:
print 'IOError:', msg
x.close()

Expand Down Expand Up @@ -311,7 +311,7 @@ def open_savefile():
cmd = savefile[1:].strip()
try:
p = os.popen(cmd, 'w')
except IOError, msg:
except IOError as msg:
print repr(cmd), ':', msg
return None
print 'Piping through', repr(cmd), '...'
Expand All @@ -320,7 +320,7 @@ def open_savefile():
savefile = os.path.expanduser(savefile)
try:
f = open(savefile, 'w')
except IOError, msg:
except IOError as msg:
print repr(savefile), ':', msg
return None
print 'Saving to', repr(savefile), '...'
Expand Down
Loading

0 comments on commit b940e11

Please sign in to comment.