except Ex, e: --> except Ex as e:

Nudge us towards python3 compatability by converting deprecated python2 syntax.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-02-05 10:14:23 +01:00
parent 7f22d89872
commit 0844d27f9f
12 changed files with 36 additions and 36 deletions

View File

@ -231,7 +231,7 @@ class SyncableAccount(Account):
self.sync()
except (KeyboardInterrupt, SystemExit):
raise
except OfflineImapError, e:
except OfflineImapError as e:
# Stop looping and bubble up Exception if needed.
if e.severity >= OfflineImapError.ERROR.REPO:
if looping:
@ -239,7 +239,7 @@ class SyncableAccount(Account):
if e.severity >= OfflineImapError.ERROR.CRITICAL:
raise
self.ui.error(e, exc_info()[2])
except Exception, e:
except Exception as e:
self.ui.error(e, exc_info()[2], msg = "While attempting to sync"
" account '%s'" % self)
else:
@ -344,7 +344,7 @@ class SyncableAccount(Account):
self.ui.callhook("Hook return code: %d" % p.returncode)
except (KeyboardInterrupt, SystemExit):
raise
except Exception, e:
except Exception as e:
self.ui.error(e, exc_info()[2], msg = "Calling hook")
def syncfolder(account, remotefolder, quick):
@ -445,7 +445,7 @@ def syncfolder(account, remotefolder, quick):
localrepos.restore_atime()
except (KeyboardInterrupt, SystemExit):
raise
except OfflineImapError, e:
except OfflineImapError as e:
# bubble up severe Errors, skip folder otherwise
if e.severity > OfflineImapError.ERROR.FOLDER:
raise
@ -459,7 +459,7 @@ def syncfolder(account, remotefolder, quick):
# we reconstruct foldername above rather than using
# localfolder, as the localfolder var is not
# available if assignment fails.
except Exception, e:
except Exception as e:
ui.error(e, msg = "ERROR in syncfolder for %s folder %s: %s" % \
(account, remotefolder.getvisiblename(),
traceback.format_exc()))

View File

@ -321,11 +321,11 @@ class BaseFolder(object):
OfflineImapError.ERROR.MESSAGE)
except (KeyboardInterrupt): # bubble up CTRL-C
raise
except OfflineImapError, e:
except OfflineImapError as e:
if e.severity > OfflineImapError.ERROR.MESSAGE:
raise # buble severe errors up
self.ui.error(e, exc_info()[2])
except Exception, e:
except Exception as e:
self.ui.error(e, "Copying message %s [acc: %s]:\n %s" %\
(uid, self.accountname,
exc_info()[2]))
@ -474,11 +474,11 @@ class BaseFolder(object):
action(dstfolder, statusfolder)
except (KeyboardInterrupt):
raise
except OfflineImapError, e:
except OfflineImapError as e:
if e.severity > OfflineImapError.ERROR.FOLDER:
raise
self.ui.error(e, exc_info()[2])
except Exception, e:
except Exception as e:
self.ui.error(e, exc_info()[2], "Syncing folder %s [acc: %s]" %\
(self, self.accountname))
raise # raise unknown Exceptions so we can fix them

View File

@ -97,7 +97,7 @@ class IMAPFolder(BaseFolder):
# Select folder and get number of messages
restype, imapdata = imapobj.select(self.getfullname(), True,
True)
except OfflineImapError, e:
except OfflineImapError as e:
# retry on dropped connections, raise otherwise
self.imapserver.releaseconnection(imapobj, True)
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
@ -219,7 +219,7 @@ class IMAPFolder(BaseFolder):
res_type, data = imapobj.uid('fetch', str(uid),
'(BODY.PEEK[])')
fails_left = 0
except imapobj.abort, e:
except imapobj.abort as e:
# Release dropped connection, and get a new one
self.imapserver.releaseconnection(imapobj, True)
imapobj = self.imapserver.acquireconnection()
@ -314,7 +314,7 @@ class IMAPFolder(BaseFolder):
headervalue = imapobj._quote(headervalue)
try:
matchinguids = imapobj.uid('search', 'HEADER', headername, headervalue)[1][0]
except imapobj.error, err:
except imapobj.error as err:
# IMAP server doesn't implement search or had a problem.
self.ui.debug('imap', "savemessage_searchforheader: got IMAP error '%s' while attempting to UID SEARCH for message with header %s" % (err, headername))
return 0
@ -545,7 +545,7 @@ class IMAPFolder(BaseFolder):
imaputil.flagsmaildir2imap(flags),
date, content)
retry_left = 0 # Mark as success
except imapobj.abort, e:
except imapobj.abort as e:
# connection has been reset, release connection and retry.
retry_left -= 1
self.imapserver.releaseconnection(imapobj, True)
@ -557,7 +557,7 @@ class IMAPFolder(BaseFolder):
(self, self.getrepository(), str(e), dbg_output),
OfflineImapError.ERROR.MESSAGE)
self.ui.error(e, exc_info()[2])
except imapobj.error, e: # APPEND failed
except imapobj.error as e: # APPEND failed
# If the server responds with 'BAD', append()
# raise()s directly. So we catch that too.
# drop conn, it might be bad.

View File

@ -79,7 +79,7 @@ class LocalStatusFolder(BaseFolder):
uid, flags = line.split(':')
uid = long(uid)
flags = set(flags)
except ValueError, e:
except ValueError as e:
errstr = "Corrupt line '%s' in cache file '%s'" % \
(line, self.filename)
self.ui.warn(errstr)

View File

@ -257,7 +257,7 @@ class MaildirFolder(BaseFolder):
try:
fd = os.open(os.path.join(tmpdir, messagename),
os.O_EXCL|os.O_CREAT|os.O_WRONLY, 0666)
except OSError, e:
except OSError as e:
if e.errno == 17:
#FILE EXISTS ALREADY
severity = OfflineImapError.ERROR.MESSAGE
@ -313,7 +313,7 @@ class MaildirFolder(BaseFolder):
try:
os.rename(os.path.join(self.getfullname(), oldfilename),
os.path.join(self.getfullname(), newfilename))
except OSError, e:
except OSError as e:
raise OfflineImapError("Can't rename file '%s' to '%s': %s" % (
oldfilename, newfilename, e[1]),
OfflineImapError.ERROR.FOLDER)

View File

@ -53,7 +53,7 @@ class UsefulIMAPMixIn(object):
del self.untagged_responses[:]
try:
result = super(UsefulIMAPMixIn, self).select(mailbox, readonly)
except self.abort, e:
except self.abort as e:
# self.abort is raised when we are supposed to retry
errstr = "Server '%s' closed connection, error on SELECT '%s'. Ser"\
"ver said: %s" % (self.host, mailbox, e.args[0])

View File

@ -153,7 +153,7 @@ class IMAPServer:
rc = kerberos.authGSSClientWrap(self.gss_vc, response,
self.username)
response = kerberos.authGSSClientResponse(self.gss_vc)
except kerberos.GSSError, err:
except kerberos.GSSError as err:
# Kerberos errored out on us, respond with None to cancel the
# authentication
self.ui.debug('imap', '%s: %s' % (err[0][0], err[1][0]))
@ -232,7 +232,7 @@ class IMAPServer:
'Attempting GSSAPI authentication')
try:
imapobj.authenticate('GSSAPI', self.gssauth)
except imapobj.error, val:
except imapobj.error as val:
self.gssapi = False
self.ui.debug('imap',
'GSSAPI Authentication failed')
@ -258,7 +258,7 @@ class IMAPServer:
try:
imapobj.authenticate('CRAM-MD5',
self.md5handler)
except imapobj.error, val:
except imapobj.error as val:
self.plainauth(imapobj)
else:
# Use plaintext login, unless
@ -271,7 +271,7 @@ class IMAPServer:
# Would bail by here if there was a failure.
success = 1
self.goodpassword = self.password
except imapobj.error, val:
except imapobj.error as val:
self.passworderror = str(val)
raise
@ -304,7 +304,7 @@ class IMAPServer:
self.lastowner[imapobj] = get_ident()
self.connectionlock.release()
return imapobj
except Exception, e:
except Exception as e:
"""If we are here then we did not succeed in getting a
connection - we should clean up and then re-raise the
error..."""
@ -540,7 +540,7 @@ class IdleThread(object):
imapobj = self.parent.acquireconnection()
try:
imapobj.select(self.folder)
except OfflineImapError, e:
except OfflineImapError as e:
if e.severity == OfflineImapError.ERROR.FOLDER_RETRY:
# Connection closed, release connection and retry
self.ui.error(e, exc_info()[2])

View File

@ -351,7 +351,7 @@ class OfflineImap:
self.ui.terminate()
except (SystemExit):
raise
except Exception, e:
except Exception as e:
self.ui.error(e)
self.ui.terminate()

View File

@ -165,7 +165,7 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
try:
dst_repo.makefolder(src_name)
dst_haschanged = True # Need to refresh list
except OfflineImapError, e:
except OfflineImapError as e:
self.ui.error(e, exc_info()[2],
"Creating folder %s on repository %s" %\
(src_name, dst_repo))
@ -212,7 +212,7 @@ class BaseRepository(object, CustomConfig.ConfigHelperMixin):
try:
src_repo.makefolder(newsrc_name)
src_haschanged = True # Need to refresh list
except OfflineImapError, e:
except OfflineImapError as e:
self.ui.error(e, exc_info()[2], "Creating folder %s on "
"repository %s" % (newsrc_name, src_repo))
raise

View File

@ -95,7 +95,7 @@ class IMAPRepository(BaseRepository):
host = self.getconf('remotehosteval')
try:
host = self.localeval.eval(host)
except Exception, e:
except Exception as e:
raise OfflineImapError("remotehosteval option for repository "\
"'%s' failed:\n%s" % (self, e),
OfflineImapError.ERROR.REPO)
@ -128,7 +128,7 @@ class IMAPRepository(BaseRepository):
try:
netrcentry = netrc.netrc().authenticators(self.gethost())
except IOError, inst:
except IOError as inst:
if inst.errno != errno.ENOENT:
raise
else:
@ -137,7 +137,7 @@ class IMAPRepository(BaseRepository):
try:
netrcentry = netrc.netrc('/etc/netrc').authenticators(self.gethost())
except IOError, inst:
except IOError as inst:
if inst.errno not in (errno.ENOENT, errno.EACCES):
raise
else:
@ -223,7 +223,7 @@ class IMAPRepository(BaseRepository):
# 4. read password from ~/.netrc
try:
netrcentry = netrc.netrc().authenticators(self.gethost())
except IOError, inst:
except IOError as inst:
if inst.errno != errno.ENOENT:
raise
else:
@ -234,7 +234,7 @@ class IMAPRepository(BaseRepository):
# 5. read password from /etc/netrc
try:
netrcentry = netrc.netrc('/etc/netrc').authenticators(self.gethost())
except IOError, inst:
except IOError as inst:
if inst.errno not in (errno.ENOENT, errno.EACCES):
raise
else:
@ -297,7 +297,7 @@ class IMAPRepository(BaseRepository):
for foldername in self.folderincludes:
try:
imapobj.select(foldername, readonly = True)
except OfflineImapError, e:
except OfflineImapError as e:
# couldn't select this folderinclude, so ignore folder.
if e.severity > OfflineImapError.ERROR.FOLDER:
raise

View File

@ -98,7 +98,7 @@ class MaildirRepository(BaseRepository):
self.debug("makefolder: calling makedirs '%s'" % full_path)
try:
os.makedirs(full_path, 0700)
except OSError, e:
except OSError as e:
if e.errno == 17 and os.path.isdir(full_path):
self.debug("makefolder: '%s' already a directory" % foldername)
else:
@ -106,7 +106,7 @@ class MaildirRepository(BaseRepository):
for subdir in ['cur', 'new', 'tmp']:
try:
os.mkdir(os.path.join(full_path, subdir), 0700)
except OSError, e:
except OSError as e:
if e.errno == 17 and os.path.isdir(full_path):
self.debug("makefolder: '%s' already has subdir %s" %
(foldername, subdir))

View File

@ -165,7 +165,7 @@ class ExitNotifyThread(Thread):
pass
prof.dump_stats(os.path.join(ExitNotifyThread.profiledir,
"%s_%s.prof" % (self.threadid, self.getName())))
except Exception, e:
except Exception as e:
# Thread exited with Exception, store it
tb = traceback.format_exc()
self.set_exit_exception(e, tb)