[Python-checkins] r86380 - in python/branches/py3k: Lib/imaplib.py Lib/test/test_imaplib.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Tue Nov 9 23:55:55 CET 2010


Author: antoine.pitrou
Date: Tue Nov  9 23:55:55 2010
New Revision: 86380

Log:
Fix IMAP.login() to work properly.
Also, add remote tests for imaplib (part of #4471).



Modified:
   python/branches/py3k/Lib/imaplib.py
   python/branches/py3k/Lib/test/test_imaplib.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/imaplib.py
==============================================================================
--- python/branches/py3k/Lib/imaplib.py	(original)
+++ python/branches/py3k/Lib/imaplib.py	Tue Nov  9 23:55:55 2010
@@ -1054,10 +1054,10 @@
 
     def _quote(self, arg):
 
-        arg = arg.replace(b'\\', b'\\\\')
-        arg = arg.replace(b'"', b'\\"')
+        arg = arg.replace('\\', '\\\\')
+        arg = arg.replace('"', '\\"')
 
-        return b'"' + arg + b'"'
+        return '"' + arg + '"'
 
 
     def _simple_command(self, name, *args):

Modified: python/branches/py3k/Lib/test/test_imaplib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_imaplib.py	(original)
+++ python/branches/py3k/Lib/test/test_imaplib.py	Tue Nov  9 23:55:55 2010
@@ -10,7 +10,7 @@
 import socketserver
 import time
 
-from test.support import reap_threads, verbose
+from test.support import reap_threads, verbose, transient_internet
 import unittest
 
 try:
@@ -192,8 +192,45 @@
     imap_class = IMAP4_SSL
 
 
-def test_main():
+class RemoteIMAPTest(unittest.TestCase):
+    host = 'cyrus.andrew.cmu.edu'
+    port = 143
+    username = 'anonymous'
+    password = 'pass'
+    imap_class = imaplib.IMAP4
+
+    def setUp(self):
+        with transient_internet(self.host):
+            self.server = self.imap_class(self.host, self.port)
+
+    def tearDown(self):
+        if self.server is not None:
+            self.server.logout()
+
+    def test_logincapa(self):
+        self.assertTrue('LOGINDISABLED' in self.server.capabilities)
+
+    def test_anonlogin(self):
+        self.assertTrue('AUTH=ANONYMOUS' in self.server.capabilities)
+        rs = self.server.login(self.username, self.password)
+        self.assertEqual(rs[0], 'OK')
+
+    def test_logout(self):
+        rs = self.server.logout()
+        self.assertEqual(rs[0], 'BYE')
+
+
+ at unittest.skipUnless(ssl, "SSL not available")
+class RemoteIMAP_SSLTest(RemoteIMAPTest):
+    port = 993
+    imap_class = IMAP4_SSL
+
+    def test_logincapa(self):
+        self.assertFalse('LOGINDISABLED' in self.server.capabilities)
+        self.assertTrue('AUTH=PLAIN' in self.server.capabilities)
 
+
+def test_main():
     tests = [TestImaplib]
 
     if support.is_resource_enabled('network'):
@@ -203,7 +240,10 @@
                                     "keycert.pem")
             if not os.path.exists(CERTFILE):
                 raise support.TestFailed("Can't read certificate files!")
-        tests.extend([ThreadedNetworkedTests, ThreadedNetworkedTestsSSL])
+        tests.extend([
+            ThreadedNetworkedTests, ThreadedNetworkedTestsSSL,
+            RemoteIMAPTest, RemoteIMAP_SSLTest,
+        ])
 
     support.run_unittest(*tests)
 

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Nov  9 23:55:55 2010
@@ -60,6 +60,8 @@
 Library
 -------
 
+- Fix IMAP.login() to work properly.
+
 - Issue #9244: multiprocessing pool worker processes could terminate
   unexpectedly if the return value of a task could not be pickled.  Only
   the ``repr`` of such errors are now sent back, wrapped in an


More information about the Python-checkins mailing list