FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-153521: Preserve bytes message sets in imaplib by cuishuang · Pull Request #153907 · python/cpython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Lib/imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def _seq_range(item):


def _format_sequence_set(arg):
if isinstance(arg, (bytes, bytearray)):
return str(arg, 'ascii')
if isinstance(arg, (int, str)):
return str(arg)
# A sequence of message numbers and ranges.
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ def test_sequence_set(self):
# A scalar is passed through as a string.
self.assertEqual(m._sequence_set(5), '5')
self.assertEqual(m._sequence_set('1:3,7'), '1:3,7')
self.assertEqual(m._sequence_set(b'1:3,7'), '1:3,7')
self.assertEqual(m._sequence_set(bytearray(b'1:3,7')), '1:3,7')
# A sequence of numbers and ranges is formatted as a sequence set.
self.assertEqual(m._sequence_set([1, 2, 5]), '1,2,5')
self.assertEqual(m._sequence_set([1, (3, 5), (8, '*')]), '1,3:5,8:*')
Expand Down Expand Up @@ -333,6 +335,7 @@ def test_substitute(self):
r'(\Seen \Answered)')
# '?s' formats a message sequence set.
self.assertEqual(sub('?s', [[1, (3, 5), (8, '*')]]), '1,3:5,8:*')
self.assertEqual(sub('?s', [b'1:3,7']), '1:3,7')
# '??' is a literal '?'.
self.assertEqual(sub('a?? b', []), 'a? b')

Expand Down Expand Up @@ -1574,6 +1577,16 @@ def cmd_FETCH(self, tag, args):
])
self.assertEqual(server.args, ['2:4', '(FLAGS)'])

# A preformatted message set may be passed as bytes.
typ, data = client.fetch(b'2:4', '(FLAGS)')
self.assertEqual(typ, 'OK')
self.assertEqual(data, [
br'2 (FLAGS (\Seen))',
br'3 (FLAGS (\Seen))',
br'4 (FLAGS (\Seen))',
])
self.assertEqual(server.args, ['2:4', '(FLAGS)'])

# A comma-separated set with an open range up to '*'.
typ, data = client.fetch('1,3:*', '(FLAGS)')
self.assertEqual(typ, 'OK')
Expand Down
Loading

Back | FazBrowse Home | New Git URL