Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conform to pep 3110 #2064

Merged
merged 4 commits into from
Jul 4, 2012
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions IPython/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,19 @@ def __setitem__(self, key, value):
def __getattr__(self, key):
try:
return self.__getitem__(key)
except KeyError, e:
except KeyError as e:
raise AttributeError(e)

def __setattr__(self, key, value):
try:
self.__setitem__(key, value)
except KeyError, e:
except KeyError as e:
raise AttributeError(e)

def __delattr__(self, key):
try:
dict.__delitem__(self, key)
except KeyError, e:
except KeyError as e:
raise AttributeError(e)


Expand Down
2 changes: 1 addition & 1 deletion IPython/core/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def soft_define_alias(self, name, cmd):
"""Define an alias, but don't raise on an AliasError."""
try:
self.define_alias(name, cmd)
except AliasError, e:
except AliasError as e:
error("Invalid alias: %s" % e)

def define_alias(self, name, cmd):
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ def safe_execfile(self, fname, *where, **kw):
with prepended_to_syspath(dname):
try:
py3compat.execfile(fname,*where)
except SystemExit, status:
except SystemExit as status:
# If the call was made with 0 or None exit status (sys.exit(0)
# or sys.exit() ), don't bother showing a traceback, as both of
# these are considered normal by the OS:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ def parse_options(self, arg_str, opt_str, *long_opts, **kw):
# Do regular option processing
try:
opts,args = getopt(argv, opt_str, long_opts)
except GetoptError,e:
except GetoptError as e:
raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
" ".join(long_opts)))
for o,a in opts:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def edit(self, parameter_s='',last_call=['','']):
if is_temp:
try:
return open(filename).read()
except IOError,msg:
except IOError as msg:
if msg.filename == filename:
warn('File not found. Did you forget to save?')
return
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def pfile(self, parameter_s=''):
if out == 'not found':
try:
filename = get_py_filename(parameter_s)
except IOError,msg:
except IOError as msg:
print msg
return
page.page(self.shell.inspector.format(open(filename).read()))
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def page(strng, start=0, screen_lines=0, pager_cmd=None):
pager.write(strng)
pager.close()
retval = pager.close() # success returns None
except IOError,msg: # broken pipe when user quits
except IOError as msg: # broken pipe when user quits
if msg.args == (32,'Broken pipe'):
retval = None
else:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class secondtmp(tt.TempFileMixin): pass
"for i in range(5):\n"
" try:\n"
" ip.magic('run %s')\n"
" except NameError, e:\n"
" except NameError as e:\n"
" print i;break\n" % empty.fname)
self.mktmp(py3compat.doctest_refactor_print(src))
_ip.magic('run %s' % self.fname)
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def linereader(file=file, lnum=[lnum], getline=linecache.getline):
except (IndexError, UnicodeDecodeError):
# signals exit of tokenizer
pass
except tokenize.TokenError,msg:
except tokenize.TokenError as msg:
_m = ("An unexpected error occurred while tokenizing input\n"
"The following traceback may be corrupted or invalid\n"
"The error message is: %s\n" % msg)
Expand Down
14 changes: 7 additions & 7 deletions IPython/deathrow/ibrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def fetch(self, count):
break
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
have += 1
self.items.append(_BrowserCachedItem(exc))
self.exhausted = True
Expand Down Expand Up @@ -260,7 +260,7 @@ def getrow(self, i):
value = attr.value(item)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
value = exc
# only store attribute if it exists (or we got an exception)
if value is not ipipe.noitem:
Expand Down Expand Up @@ -652,7 +652,7 @@ def cmd_execute(self, browser):
break # found something
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
browser.report(exc)
curses.beep()
break # break on error
Expand All @@ -677,7 +677,7 @@ def cmd_execute(self, browser):
break # found something
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
browser.report(exc)
curses.beep()
break # break on error
Expand Down Expand Up @@ -946,7 +946,7 @@ def enter(self, item, *attrs):
)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
if not self.levels:
raise
self._calcheaderlines(oldlevels)
Expand Down Expand Up @@ -1311,7 +1311,7 @@ def cmd_detailattr(self):
item = attr.value(item)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
self.report(exc)
else:
self.report("entering detail view for attribute %s..." % attr.name())
Expand Down Expand Up @@ -1638,7 +1638,7 @@ def _dodisplay(self, scr):
value = attr.value(item)
except (SystemExit, KeyboardInterrupt):
raise
except Exception, exc:
except Exception as exc:
value = exc
if value is not ipipe.noitem:
attrstyle = ipipe.xrepr(value, "footer")
Expand Down
36 changes: 18 additions & 18 deletions IPython/deathrow/igrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def _getvalue(self, row, col):
try:
value = self.table._displayattrs[col].value(self.table.items[row])
(align, width, text) = ipipe.xformat(value, "cell", self.maxchars)
except Exception, exc:
except Exception as exc:
(align, width, text) = ipipe.xformat(exc, "cell", self.maxchars)
return (align, text)

Expand Down Expand Up @@ -292,7 +292,7 @@ def _fetch(self, count):
break
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
have += 1
self._append(exc)
self.iterator = None
Expand Down Expand Up @@ -413,7 +413,7 @@ def realkey(item):
return None
try:
self.table.items = ipipe.deque(sorted(self.table.items, key=realkey, reverse=reverse))
except TypeError, exc:
except TypeError as exc:
self.error_output("Exception encountered: %s" % exc)
return
# Find out where the object under the cursor went
Expand Down Expand Up @@ -478,7 +478,7 @@ def _getvalue(self, row, col):
(align, width, text) = ipipe.xformat(value, "cell", self.maxchars)
except IndexError:
raise IndexError
except Exception, exc:
except Exception as exc:
(align, width, text) = ipipe.xformat(exc, "cell", self.maxchars)
return text

Expand All @@ -505,7 +505,7 @@ def searchexpression(self, searchexp, startrow=None, search_forward=True ):
break
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
frame.SetStatusText(str(exc))
wx.Bell()
break # break on error
Expand All @@ -529,7 +529,7 @@ def searchexpression(self, searchexp, startrow=None, search_forward=True ):
break
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
frame.SetStatusText(str(exc))
wx.Bell()
break # break on error
Expand Down Expand Up @@ -739,7 +739,7 @@ def _doenter(self, value, *attrs):
for i in xrange(count-1, current, -1): # some tabs don't close if we don't close in *reverse* order
nb.DeletePage(i)
frame._add_notebook(value)
except TypeError, exc:
except TypeError as exc:
if exc.__class__.__module__ == "exceptions":
msg = "%s: %s" % (exc.__class__.__name__, exc)
else:
Expand All @@ -750,7 +750,7 @@ def enterattr(self, row, col):
try:
attr = self.table._displayattrs[col]
value = attr.value(self.table.items[row])
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self._doenter(value)
Expand All @@ -762,7 +762,7 @@ def set_footer(self, item):
def enter(self, row):
try:
value = self.table.items[row]
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self._doenter(value)
Expand All @@ -774,7 +774,7 @@ def detail(self, row, col):
try:
attr = self.table._displayattrs[col]
item = self.table.items[row]
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")]
Expand All @@ -784,7 +784,7 @@ def detail_attr(self, row, col):
try:
attr = self.table._displayattrs[col]
item = attr.value(self.table.items[row])
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")]
Expand Down Expand Up @@ -819,15 +819,15 @@ def pick(self, row):
"""
try:
value = self.table.items[row]
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self.quit(value)

def pickinput(self, row):
try:
value = self.table.items[row]
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
api = ipapi.get()
Expand All @@ -838,7 +838,7 @@ def pickinputattr(self, row, col):
try:
attr = self.table._displayattrs[col]
value = attr.value(self.table.items[row])
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
api = ipapi.get()
Expand All @@ -851,7 +851,7 @@ def pickrows(self, rows):
"""
try:
value = [self.table.items[row] for row in rows]
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self.quit(value)
Expand All @@ -870,7 +870,7 @@ def pickrowsattr(self, rows, col):
raise
except Exception:
raise #pass
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self.quit(values)
Expand All @@ -879,7 +879,7 @@ def pickattr(self, row, col):
try:
attr = self.table._displayattrs[col]
value = attr.value(self.table.items[row])
except Exception, exc:
except Exception as exc:
self.error_output(str(exc))
else:
self.quit(value)
Expand Down Expand Up @@ -959,7 +959,7 @@ def refresh_interval(self, event):
if dlg.ShowModal() == wx.ID_OK:
try:
milliseconds = int(dlg.GetValue())
except ValueError, exc:
except ValueError as exc:
self.SetStatusText(str(exc))
else:
table.timer.Start(milliseconds=milliseconds, oneShot=False)
Expand Down
8 changes: 4 additions & 4 deletions IPython/deathrow/ipipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,7 @@ def test(item):
ok += 1
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
if self.errors == "drop":
pass # Ignore errors
elif self.errors == "keep":
Expand Down Expand Up @@ -1869,7 +1869,7 @@ def do(item):
yield do(item)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
if self.errors == "drop":
pass # Ignore errors
elif self.errors == "keep":
Expand Down Expand Up @@ -2040,7 +2040,7 @@ def display(self):
pager.write("\n")
finally:
pager.close()
except Exception, exc:
except Exception as exc:
print "%s: %s" % (exc.__class__.__name__, str(exc))


Expand Down Expand Up @@ -2187,7 +2187,7 @@ def display(self):
value = attr.value(item)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, exc:
except Exception as exc:
value = exc
(align, width, text) = xformat(value, "cell", self.maxattrlength)
colwidths[attr] = max(colwidths[attr], width)
Expand Down
2 changes: 1 addition & 1 deletion IPython/deathrow/oldfrontend/frontendbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def execute(self, block, blockID=None):

try:
result = self.shell.execute(block)
except Exception,e:
except Exception as e:
e = self._add_block_id_for_failure(e, blockID=blockID)
e = self.update_cell_prompt(e, blockID=blockID)
e = self.render_error(e)
Expand Down
2 changes: 1 addition & 1 deletion IPython/deathrow/oldfrontend/linefrontendbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def is_complete(self, string):
is_complete = codeop.compile_command(clean_string,
"<string>", "exec")
self.release_output()
except Exception, e:
except Exception as e:
# XXX: Hack: return True so that the
# code gets executed and the error captured.
is_complete = True
Expand Down
2 changes: 1 addition & 1 deletion IPython/deathrow/oldfrontend/wx/ipythonx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
import wx
except ImportError, e:
except ImportError as e:
e.args[0] = """%s
________________________________________________________________________________
You need wxPython to run this application.
Expand Down
2 changes: 1 addition & 1 deletion IPython/extensions/tests/test_octavemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy.testing as npt

from IPython.extensions import octavemagic
except Exception, e:
except Exception as e:
__test__ = False

global octave
Expand Down