py3: raise exceptions using six module

There is no other way to make Python2 and Python3 happy, because syntax
raise E, V, T is incompatible with the latter.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Łukasz Żarnowiecki
2016-05-17 19:56:52 +02:00
committed by Nicolas Sebrecht
parent 83539f8601
commit 0addcbabf0
13 changed files with 70 additions and 49 deletions

View File

@ -22,6 +22,9 @@ import os
from sys import exc_info
from .Base import BaseFolder
from threading import Lock
import six
try:
from hashlib import md5
except ImportError:
@ -309,8 +312,8 @@ class MaildirFolder(BaseFolder):
time.sleep(0.23)
continue
severity = OfflineImapError.ERROR.MESSAGE
raise OfflineImapError("Unique filename %s already exists."%
filename, severity), None, exc_info()[2]
six.reraise(OfflineImapError("Unique filename %s already exists."%
filename, severity), None, exc_info()[2])
else:
raise
@ -430,10 +433,9 @@ class MaildirFolder(BaseFolder):
os.rename(os.path.join(self.getfullname(), oldfilename),
os.path.join(self.getfullname(), newfilename))
except OSError as e:
raise OfflineImapError("Can't rename file '%s' to '%s': %s" % (
six.reraise(OfflineImapError("Can't rename file '%s' to '%s': %s" % (
oldfilename, newfilename, e[1]),
OfflineImapError.ERROR.FOLDER), \
None, exc_info()[2]
OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
self.messagelist[uid]['flags'] = flags
self.messagelist[uid]['filename'] = newfilename
@ -511,10 +513,10 @@ class MaildirFolder(BaseFolder):
try:
os.rename(filename, newfilename)
except OSError as e:
raise OfflineImapError(
six.reraise(OfflineImapError(
"Can't rename file '%s' to '%s': %s" % (
filename, newfilename, e[1]),
OfflineImapError.ERROR.FOLDER), None, exc_info()[2]
OfflineImapError.ERROR.FOLDER), None, exc_info()[2])
elif match.group(1) != self._foldermd5:
self.ui.warn(("Inconsistent FMD5 for file `%s':"
" Neither `%s' nor `%s' found")