Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def select(self, mailbox='INBOX', readonly=False):
if __debug__:
if self.debug >= 1:
self._dump_ur(self.untagged_responses)
raise self.readonly('%s is not writable' % mailbox)
raise self.readonly('%r is not writable' % (mailbox,))
return typ, self.untagged_responses.get('EXISTS', [None])


Expand Down Expand Up @@ -921,7 +921,7 @@ def uid(self, command, *args):
"""
command = command.upper()
if not command in Commands:
raise self.error("Unknown IMAP4 UID command: %s" % command)
raise self.error("Unknown IMAP4 UID command: %r" % (command,))
if self.state not in Commands[command]:
raise self.error("command %s illegal in state %s, "
"only allowed in states %s" %
Expand Down
26 changes: 26 additions & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,32 @@ def cmd_CAPABILITY(self, tag, args):
client.login('user', 'pass')
self.assertIn('ENABLE', client.capabilities)

def test_readonly_error_reports_mailbox(self):
# The read-only error reports the mailbox via repr(), which also
# avoids BytesWarning for a bytes mailbox under -bb.
class ReadOnlyHandler(SimpleIMAPHandler):
def cmd_SELECT(self, tag, args):
self._send_line(b'* 2 EXISTS')
self._send_tagged(tag, 'OK', '[READ-ONLY] SELECT completed.')
client, _ = self._setup(ReadOnlyHandler)
client.login('user', 'pass')
for mailbox, expected in [('INBOX', "'INBOX'"), (b'INBOX', r"b'INBOX'")]:
with self.subTest(mailbox=mailbox):
with self.assertRaisesRegex(imaplib.IMAP4.readonly,
r"%s is not writable" % expected):
client.select(mailbox)

def test_uid_unknown_command_reports_command(self):
# The unknown-UID-command error reports the command via repr(), which
# also avoids BytesWarning for a bytes command under -bb.
client, _ = self._setup(SimpleIMAPHandler)
for command, expected in [('BOGUS', "'BOGUS'"), (b'BOGUS', r"b'BOGUS'")]:
with self.subTest(command=command):
with self.assertRaisesRegex(
imaplib.IMAP4.error,
r"Unknown IMAP4 UID command: %s" % expected):
client.uid(command, '1')

def test_logout(self):
client, _ = self._setup(SimpleIMAPHandler)
typ, data = client.login('user', 'pass')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error messages from :meth:`imaplib.IMAP4.select` and :meth:`imaplib.IMAP4.uid`
no longer raise :exc:`BytesWarning` under :option:`!-bb`
when the mailbox or command argument is :class:`bytes`.
Loading