Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(9224)

Delta Between Two Patch Sets: Lib/test/test_poplib.py

Issue 21804: Implement thr UTF8 command (RFC 6856) in poplib.
Left Patch Set: Created 5 years, 4 months ago
Right Patch Set: Created 5 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/poplib.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 """Test script for poplib module.""" 1 """Test script for poplib module."""
2 2
3 # Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL 3 # Modified by Giampaolo Rodola' to give poplib.POP3 and poplib.POP3_SSL
4 # a real test suite 4 # a real test suite
5 5
6 import poplib 6 import poplib
7 import asyncore 7 import asyncore
8 import asynchat 8 import asynchat
9 import socket 9 import socket
10 import os 10 import os
(...skipping 29 matching lines...) Expand all
40 \r\n\ 40 \r\n\
41 line1\r\n\ 41 line1\r\n\
42 line2\r\n\ 42 line2\r\n\
43 line3\r\n\ 43 line3\r\n\
44 .\r\n""" 44 .\r\n"""
45 45
46 46
47 class DummyPOP3Handler(asynchat.async_chat): 47 class DummyPOP3Handler(asynchat.async_chat):
48 48
49 CAPAS = {'UIDL': [], 'IMPLEMENTATION': ['python-testlib-pop-server']} 49 CAPAS = {'UIDL': [], 'IMPLEMENTATION': ['python-testlib-pop-server']}
50 enable_UTF8 = False
50 51
51 def __init__(self, conn): 52 def __init__(self, conn):
52 asynchat.async_chat.__init__(self, conn) 53 asynchat.async_chat.__init__(self, conn)
53 self.set_terminator(b"\r\n") 54 self.set_terminator(b"\r\n")
54 self.in_buffer = [] 55 self.in_buffer = []
55 self.push('+OK dummy pop3 server ready. <timestamp>') 56 self.push('+OK dummy pop3 server ready. <timestamp>')
56 self.tls_active = False 57 self.tls_active = False
57 self.tls_starting = False 58 self.tls_starting = False
58 59
59 def collect_incoming_data(self, data): 60 def collect_incoming_data(self, data):
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 self.push('+OK Capability list follows') 140 self.push('+OK Capability list follows')
140 if self._get_capas(): 141 if self._get_capas():
141 for cap, params in self._get_capas().items(): 142 for cap, params in self._get_capas().items():
142 _ln = [cap] 143 _ln = [cap]
143 if params: 144 if params:
144 _ln.extend(params) 145 _ln.extend(params)
145 self.push(' '.join(_ln)) 146 self.push(' '.join(_ln))
146 self.push('.') 147 self.push('.')
147 148
148 def cmd_utf8(self, arg): 149 def cmd_utf8(self, arg):
149 self.push('+OK I know RFC6856') 150 self.push('+OK I know RFC6856'
151 if self.enable_UTF8
152 else '-ERR What is UTF8?!')
150 153
151 if SUPPORTS_SSL: 154 if SUPPORTS_SSL:
152 155
153 def cmd_stls(self, arg): 156 def cmd_stls(self, arg):
154 if self.tls_active is False: 157 if self.tls_active is False:
155 self.push('+OK Begin TLS negotiation') 158 self.push('+OK Begin TLS negotiation')
156 tls_sock = ssl.wrap_socket(self.socket, certfile=CERTFILE, 159 tls_sock = ssl.wrap_socket(self.socket, certfile=CERTFILE,
157 server_side=True, 160 server_side=True,
158 do_handshake_on_connect=False, 161 do_handshake_on_connect=False,
159 suppress_ragged_eofs=False) 162 suppress_ragged_eofs=False)
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 [b'From: postmaster@python.org', b'Content-Type: text/plain ', 311 [b'From: postmaster@python.org', b'Content-Type: text/plain ',
309 b'MIME-Version: 1.0', b'Subject: Dummy', b'', 312 b'MIME-Version: 1.0', b'Subject: Dummy', b'',
310 b'line1', b'line2', b'line3'], 313 b'line1', b'line2', b'line3'],
311 113) 314 113)
312 self.assertEqual(self.client.top(1, 1), expected) 315 self.assertEqual(self.client.top(1, 1), expected)
313 316
314 def test_uidl(self): 317 def test_uidl(self):
315 self.client.uidl() 318 self.client.uidl()
316 self.client.uidl('foo') 319 self.client.uidl('foo')
317 320
321 def test_utf8_raises_if_unsupported(self):
322 self.server.handler.enable_UTF8 = False
323 self.assertRaises(poplib.error_proto, self.client.utf8)
324
318 def test_utf8(self): 325 def test_utf8(self):
326 self.server.handler.enable_UTF8 = True
319 expected = b'+OK I know RFC6856' 327 expected = b'+OK I know RFC6856'
320 result = self.client.utf8() 328 result = self.client.utf8()
321 self.assertEqual(result, expected) 329 self.assertEqual(result, expected)
322 330
323 def test_capa(self): 331 def test_capa(self):
324 capa = self.client.capa() 332 capa = self.client.capa()
325 self.assertTrue('IMPLEMENTATION' in capa.keys()) 333 self.assertTrue('IMPLEMENTATION' in capa.keys())
326 334
327 def test_quit(self): 335 def test_quit(self):
328 resp = self.client.quit() 336 resp = self.client.quit()
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 TestPOP3_SSLClass, TestPOP3_TLSClass] 509 TestPOP3_SSLClass, TestPOP3_TLSClass]
502 thread_info = test_support.threading_setup() 510 thread_info = test_support.threading_setup()
503 try: 511 try:
504 test_support.run_unittest(*tests) 512 test_support.run_unittest(*tests)
505 finally: 513 finally:
506 test_support.threading_cleanup(*thread_info) 514 test_support.threading_cleanup(*thread_info)
507 515
508 516
509 if __name__ == '__main__': 517 if __name__ == '__main__':
510 test_main() 518 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+