>From eb7de6bda850bb1aa79fa679a359f7fb2a1ca830 Mon Sep 17 00:00:00 2001
From: Allan Wind <allan_wind@lifeintegrity.com>
Date: Tue, 17 Apr 2012 01:08:03 -0400
Subject: [PATCH 2/2] Partial support for Python 3.1

---
 offlineimap/imaplib2.py |   38 +++++++++++++++++++++-----------------
 1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/offlineimap/imaplib2.py b/offlineimap/imaplib2.py
index ffa2676..c3ddc9e 100644
--- a/offlineimap/imaplib2.py
+++ b/offlineimap/imaplib2.py
@@ -44,7 +44,11 @@ __author__ = "Piers Lauder <piers@janeelix.com>"
 __URL__ = "http://imaplib2.sourceforge.net"
 __license__ = "Python License"
 
-import binascii, errno, os, Queue, random, re, select, socket, sys, time, threading, zlib
+import binascii, errno, os, random, re, select, socket, sys, time, threading, zlib
+try:
+	import queue
+except:
+	import Queue
 
 select_module = select
 
@@ -373,7 +377,7 @@ class IMAP4(object):
             elif self._get_untagged_response('OK'):
                 if __debug__: self._log(1, 'state => NONAUTH')
             else:
-                raise self.error('unrecognised server welcome message: %s' % `self.welcome`)
+                raise self.error('unrecognised server welcome message: %s' % (self.welcome))
 
             typ, dat = self.capability()
             if dat == [None]:
@@ -426,19 +430,19 @@ class IMAP4(object):
             af, socktype, proto, canonname, sa = res
             try:
                 s = socket.socket(af, socktype, proto)
-            except socket.error, msg:
+            except socket.error as msg:
                 continue
             try:
                 for i in (0, 1):
                     try:
                         s.connect(sa)
                         break
-                    except socket.error, msg:
+                    except socket.error as msg:
                         if len(msg.args) < 2 or msg.args[0] != errno.EINTR:
                             raise
                 else:
                     raise socket.error(msg)
-            except socket.error, msg:
+            except socket.error as msg:
                 s.close()
                 continue
             break
@@ -1369,7 +1373,7 @@ class IMAP4(object):
         return typ, dat
 
 
-    def _command_completer(self, (response, cb_arg, error)):
+    def _command_completer(self, response, cb_arg, error):
 
         # Called for callback commands
         rqb, kw = cb_arg
@@ -1584,7 +1588,7 @@ class IMAP4(object):
             tag = rqb.tag
         self.tagged_commands[tag] = rqb
         self.commands_lock.release()
-        if __debug__: self._log(4, '_request_push(%s, %s, %s) = %s' % (tag, name, `kw`, rqb.tag))
+        if __debug__: self._log(4, '_request_push(%s, %s, %s) = %s' % (tag, name, kw, rqb.tag))
         return rqb
 
 
@@ -1683,7 +1687,7 @@ class IMAP4(object):
 
         self.Terminate = True
 
-        if __debug__: self._log(1, 'terminating: %s' % `val`)
+        if __debug__: self._log(1, 'terminating: %s' % (val))
 
         while not self.ouq.empty():
             try:
@@ -1736,7 +1740,7 @@ class IMAP4(object):
                 timeout = read_poll_timeout
             try:
                 r = poll.poll(timeout)
-                if __debug__: self._log(5, 'poll => %s' % `r`)
+                if __debug__: self._log(5, 'poll => %s' % (r))
                 if not r:
                     continue                                    # Timeout
 
@@ -2296,7 +2300,7 @@ if __name__ == '__main__':
 
     try:
         optlist, args = getopt.getopt(sys.argv[1:], 'd:l:s:p:')
-    except getopt.error, val:
+    except getopt.error as val:
         optlist, args = (), ()
 
     debug, debug_buf_lvl, port, stream_command, keyfile, certfile = (None,)*6
@@ -2357,7 +2361,7 @@ if __name__ == '__main__':
 
     AsyncError = None
 
-    def responder((response, cb_arg, error)):
+    def responder(response, cb_arg, error):
         global AsyncError
         cmd, args = cb_arg
         if error is not None:
@@ -2447,11 +2451,11 @@ if __name__ == '__main__':
             run('append', (None, None, None, test_mesg), cb=False)
             num = run('search', (None, 'ALL'), cb=False)[0].split()[0]
             dat = run('fetch', (num, '(FLAGS INTERNALDATE RFC822)'), cb=False)
-            M._mesg('fetch %s => %s' % (num, `dat`))
+            M._mesg('fetch %s => %s' % (num, dat))
             run('idle', (2,))
             run('store', (num, '-FLAGS', '(\Seen)'), cb=False),
             dat = run('fetch', (num, '(FLAGS INTERNALDATE RFC822)'), cb=False)
-            M._mesg('fetch %s => %s' % (num, `dat`))
+            M._mesg('fetch %s => %s' % (num, dat))
             run('uid', ('STORE', num, 'FLAGS', '(\Deleted)'))
             run('expunge', ())
 
@@ -2464,15 +2468,15 @@ if __name__ == '__main__':
             M._mesg('unused untagged responses in order, most recent last:')
             for typ,dat in M.pop_untagged_responses(): M._mesg('\t%s %s' % (typ, dat))
 
-        print 'All tests OK.'
+        print('All tests OK.')
 
     except:
-        print 'Tests failed.'
+        print('Tests failed.')
 
         if not debug:
-            print '''
+            print('''
 If you would like to see debugging output,
 try: %s -d5
-''' % sys.argv[0]
+''' % sys.argv[0])
 
         raise
-- 
1.7.2.5

