Bug#588348: better patch for PYTHONOPTIMIZE bug
The attached patch solves the problem in a better way:
It replaces all asserts with "if ...: raise AssertionError"
constructions. It needs also testing.
diff -Nru offlineimap-6.2.0.2/offlineimap/folder/Gmail.py offlineimap-6.2.0.3/offlineimap/folder/Gmail.py
--- offlineimap-6.2.0.2/offlineimap/folder/Gmail.py 2009-08-12 22:25:27.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/folder/Gmail.py 2010-07-17 23:05:34.000000000 +0200
@@ -59,8 +59,8 @@
result = imapobj.uid('copy',
imaputil.listjoin(uidlist),
self.trash_folder)
- assert result[0] == 'OK', \
- "Bad IMAPlib result: %s" % result[0]
+ if result[0] != 'OK':
+ raise AssertionError("Bad IMAPlib result: %s" % result[0])
finally:
self.imapserver.releaseconnection(imapobj)
for uid in uidlist:
@@ -89,7 +89,8 @@
imaputil.listjoin(uidlist),
operation + 'FLAGS',
imaputil.flagsmaildir2imap(flags))
- assert r[0] == 'OK', 'Error with store: ' + '. '.join(r[1])
+ if r[0] != 'OK':
+ raise AssertionError('Error with store: ' + '. '.join(r[1]))
r = r[1]
finally:
self.imapserver.releaseconnection(imapobj)
diff -Nru offlineimap-6.2.0.2/offlineimap/folder/IMAP.py offlineimap-6.2.0.3/offlineimap/folder/IMAP.py
--- offlineimap-6.2.0.2/offlineimap/folder/IMAP.py 2010-06-29 23:49:59.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/folder/IMAP.py 2010-07-17 23:19:10.000000000 +0200
@@ -336,12 +336,14 @@
ui.debug('imap', 'savemessage: new content length is ' + \
str(len(content)))
- assert(imapobj.append(self.getfullname(),
+ if imapobj.append(self.getfullname(),
imaputil.flagsmaildir2imap(flags),
- date, content)[0] == 'OK')
+ date, content)[0] != 'OK':
+ raise AssertionError
# Checkpoint. Let it write out the messages, etc.
- assert(imapobj.check()[0] == 'OK')
+ if imapobj.check()[0] != 'OK':
+ raise AssertionError
# Keep trying until we get the UID.
ui.debug('imap', 'savemessage: first attempt to get new UID')
@@ -350,7 +352,8 @@
# See docs for savemessage in Base.py for explanation of this and other return values
if uid <= 0:
ui.debug('imap', 'savemessage: first attempt to get new UID failed. Going to run a NOOP and try again.')
- assert(imapobj.noop()[0] == 'OK')
+ if imapobj.noop()[0] != 'OK':
+ raise AssertionError
uid = self.savemessage_searchforheader(imapobj, headername,
headervalue)
finally:
@@ -372,7 +375,8 @@
return
result = imapobj.uid('store', '%d' % uid, 'FLAGS',
imaputil.flagsmaildir2imap(flags))
- assert result[0] == 'OK', 'Error with store: ' + '. '.join(r[1])
+ if result[0] != 'OK':
+ raise AssertionError('Error with store: ' + '. '.join(r[1]))
finally:
self.imapserver.releaseconnection(imapobj)
result = result[1][0]
@@ -418,7 +422,8 @@
imaputil.listjoin(uidlist),
operation + 'FLAGS',
imaputil.flagsmaildir2imap(flags))
- assert r[0] == 'OK', 'Error with store: ' + '. '.join(r[1])
+ if r[0] != 'OK':
+ raise AssertionError('Error with store: ' + '. '.join(r[1]))
r = r[1]
finally:
self.imapserver.releaseconnection(imapobj)
@@ -474,7 +479,8 @@
UIBase.getglobalui().deletereadonly(self, uidlist)
return
if self.expunge:
- assert(imapobj.expunge()[0] == 'OK')
+ if imapobj.expunge()[0] != 'OK':
+ raise AssertionError
finally:
self.imapserver.releaseconnection(imapobj)
for uid in uidlist:
diff -Nru offlineimap-6.2.0.2/offlineimap/folder/LocalStatus.py offlineimap-6.2.0.3/offlineimap/folder/LocalStatus.py
--- offlineimap-6.2.0.2/offlineimap/folder/LocalStatus.py 2010-06-29 23:49:59.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/folder/LocalStatus.py 2010-07-17 23:03:14.000000000 +0200
@@ -74,7 +74,8 @@
# but somehow did.
file.close()
return
- assert(line == magicline)
+ if line != magicline:
+ raise AssertionError
for line in file.xreadlines():
line = line.strip()
uid, flags = line.split(':')
diff -Nru offlineimap-6.2.0.2/offlineimap/folder/Maildir.py offlineimap-6.2.0.3/offlineimap/folder/Maildir.py
--- offlineimap-6.2.0.2/offlineimap/folder/Maildir.py 2010-06-29 23:49:59.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/folder/Maildir.py 2010-07-17 23:02:26.000000000 +0200
@@ -290,7 +290,8 @@
# By now, the message had better not be in tmp/ land!
final_dir, final_name = os.path.split(self.messagelist[uid]['filename'])
- assert final_dir != tmpdir
+ if final_dir == tmpdir:
+ raise AssertionError
def deletemessage(self, uid):
if not uid in self.messagelist:
diff -Nru offlineimap-6.2.0.2/offlineimap/init.py offlineimap-6.2.0.3/offlineimap/init.py
--- offlineimap-6.2.0.2/offlineimap/init.py 2010-06-29 23:49:59.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/init.py 2010-07-17 23:18:02.000000000 +0200
@@ -48,7 +48,8 @@
ui.terminate(1)
def startup(versionno):
- assert versionno == version.versionstr, "Revision of main program (%s) does not match that of library (%s). Please double-check your PYTHONPATH and installation locations." % (versionno, version.versionstr)
+ if versionno != version.versionstr:
+ raise AssertionError("Revision of main program (%s) does not match that of library (%s). Please double-check your PYTHONPATH and installation locations." % (versionno, version.versionstr))
options = {}
options['-k'] = []
if '--help' in sys.argv[1:]:
diff -Nru offlineimap-6.2.0.2/offlineimap/repository/Maildir.py offlineimap-6.2.0.3/offlineimap/repository/Maildir.py
--- offlineimap-6.2.0.2/offlineimap/repository/Maildir.py 2008-09-30 01:07:45.000000000 +0200
+++ offlineimap-6.2.0.3/offlineimap/repository/Maildir.py 2010-07-17 23:17:24.000000000 +0200
@@ -75,10 +75,13 @@
if self.getsep() == '/':
for invalid in ['new', 'cur', 'tmp', 'offlineimap.uidvalidity']:
for component in foldername.split('/'):
- assert component != invalid, "When using nested folders (/ as a separator in the account config), your folder names may not contain 'new', 'cur', 'tmp', or 'offlineimap.uidvalidity'."
+ if component == invalid:
+ raise AssertionError("When using nested folders (/ as a separator in the account config), your folder names may not contain 'new', 'cur', 'tmp', or 'offlineimap.uidvalidity'.")
- assert foldername.find('./') == -1, "Folder names may not contain ../"
- assert not foldername.startswith('/'), "Folder names may not begin with /"
+ if not foldername.find('./') == -1:
+ raise AssertionError("Folder names may not contain ../")
+ if foldername.startswith('/'):
+ raise AssertionError("Folder names may not begin with /")
oldcwd = os.getcwd()
os.chdir(self.root)
@@ -93,9 +96,9 @@
self.debug("makefolder: %s already is a directory" % foldername)
# Already exists. Sanity-check that it's not a Maildir.
for subdir in ['cur', 'new', 'tmp']:
- assert not os.path.isdir(os.path.join(foldername, subdir)), \
- "Tried to create folder %s but it already had dir %s" %\
- (foldername, subdir)
+ if os.path.isdir(os.path.join(foldername, subdir)):
+ raise AssertionError("Tried to create folder %s but it already had dir %s" %\
+ (foldername, subdir))
else:
self.debug("makefolder: calling makedirs %s" % foldername)
os.makedirs(foldername, 0700)
Reply to: