bpo-26543: Fix IMAP4.noop when debug mode is enabled (GH-15206)

This commit is contained in:
Sanyam Khurana 2020-06-02 06:47:45 +05:30 committed by GitHub
parent fe5dd78182
commit 8a3d2af997
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 7 deletions

View File

@ -1251,13 +1251,12 @@ class IMAP4:
sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s)) sys.stderr.write(' %s.%02d %s\n' % (tm, (secs*100)%100, s))
sys.stderr.flush() sys.stderr.flush()
def _dump_ur(self, dict): def _dump_ur(self, untagged_resp_dict):
# Dump untagged responses (in `dict'). if not untagged_resp_dict:
l = dict.items() return
if not l: return items = (f'{key}: {value!r}'
t = '\n\t\t' for key, value in untagged_resp_dict.items())
l = map(lambda x:'%s: "%s"' % (x[0], x[1][0] and '" "'.join(x[1]) or ''), l) self._mesg('untagged responses dump:' + '\n\t\t'.join(items))
self._mesg('untagged responses dump:%s%s' % (t, t.join(l)))
def _log(self, line): def _log(self, line):
# Keep log of last `_cmd_log_len' interactions for debugging. # Keep log of last `_cmd_log_len' interactions for debugging.

View File

@ -933,6 +933,20 @@ class ThreadedNetworkedTests(unittest.TestCase):
self.assertIsNone(server.logged) self.assertIsNone(server.logged)
self.assertIsNone(server.logged) self.assertIsNone(server.logged)
@threading_helper.reap_threads
@cpython_only
def test_dump_ur(self):
# See: http://bugs.python.org/issue26543
untagged_resp_dict = {'READ-WRITE': [b'']}
with self.reaped_server(SimpleIMAPHandler) as server:
with self.imap_class(*server.server_address) as imap:
with mock.patch.object(imap, '_mesg') as mock_mesg:
imap._dump_ur(untagged_resp_dict)
mock_mesg.assert_called_with(
"untagged responses dump:READ-WRITE: [b'']"
)
@unittest.skipUnless(ssl, "SSL not available") @unittest.skipUnless(ssl, "SSL not available")
class ThreadedNetworkedTestsSSL(ThreadedNetworkedTests): class ThreadedNetworkedTestsSSL(ThreadedNetworkedTests):

View File

@ -0,0 +1 @@
Fix :meth:`IMAP4.noop()` when debug mode is enabled (ex: ``imaplib.Debug = 3``).