MCPcopy Index your code
hub / github.com/python/cpython / test_bracket_flags

Method test_bracket_flags

Lib/test/test_imaplib.py:781–827  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

779
780 @threading_helper.reap_threads
781 def test_bracket_flags(self):
782
783 # This violates RFC 3501, which disallows ']' characters in tag names,
784 # but imaplib has allowed producing such tags forever, other programs
785 # also produce them (eg: OtherInbox's Organizer app as of 20140716),
786 # and Gmail, for example, accepts them and produces them. So we
787 # support them. See issue #21815.
788
789 class BracketFlagHandler(SimpleIMAPHandler):
790
791 def handle(self):
792 self.flags = ['Answered', 'Flagged', 'Deleted', 'Seen', 'Draft']
793 super().handle()
794
795 def cmd_AUTHENTICATE(self, tag, args):
796 self._send_textline('+')
797 self.server.response = yield
798 self._send_tagged(tag, 'OK', 'FAKEAUTH successful')
799
800 def cmd_SELECT(self, tag, args):
801 flag_msg = ' \\'.join(self.flags)
802 self._send_line(('* FLAGS (%s)' % flag_msg).encode('ascii'))
803 self._send_line(b'* 2 EXISTS')
804 self._send_line(b'* 0 RECENT')
805 msg = ('* OK [PERMANENTFLAGS %s \\*)] Flags permitted.'
806 % flag_msg)
807 self._send_line(msg.encode('ascii'))
808 self._send_tagged(tag, 'OK', '[READ-WRITE] SELECT completed.')
809
810 def cmd_STORE(self, tag, args):
811 new_flags = args[2].strip('(').strip(')').split()
812 self.flags.extend(new_flags)
813 flags_msg = '(FLAGS (%s))' % ' \\'.join(self.flags)
814 msg = '* %s FETCH %s' % (args[0], flags_msg)
815 self._send_line(msg.encode('ascii'))
816 self._send_tagged(tag, 'OK', 'STORE completed.')
817
818 with self.reaped_pair(BracketFlagHandler) as (server, client):
819 code, data = client.authenticate('MYAUTH', lambda x: b'fake')
820 self.assertEqual(code, 'OK')
821 self.assertEqual(server.response, b'ZmFrZQ==\r\n')
822 client.select('test')
823 typ, [data] = client.store(b'1', "+FLAGS", "[test]")
824 self.assertIn(b'[test]', data)
825 client.select('test')
826 typ, [data] = client.response('PERMANENTFLAGS')
827 self.assertIn(b'[test]', data)
828
829 @threading_helper.reap_threads
830 def test_issue5949(self):

Callers

nothing calls this directly

Calls 7

reaped_pairMethod · 0.95
authenticateMethod · 0.80
assertInMethod · 0.80
responseMethod · 0.80
assertEqualMethod · 0.45
selectMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected