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

Side by Side Diff: Lib/test/test_ftplib.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_fcntl.py ('k') | Lib/test/test_future5.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Test script for ftplib module.""" 1 """Test script for ftplib module."""
2 2
3 # Modified by Giampaolo Rodola' to test FTP class, IPv6 and TLS 3 # Modified by Giampaolo Rodola' to test FTP class, IPv6 and TLS
4 # environment 4 # environment
5 5
6 import ftplib 6 import ftplib
7 import asyncore 7 import asyncore
8 import asynchat 8 import asynchat
9 import socket 9 import socket
10 import io 10 import io
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 CERTFILE = os.path.join(os.path.dirname(__file__), "keycert.pem") 297 CERTFILE = os.path.join(os.path.dirname(__file__), "keycert.pem")
298 298
299 class SSLConnection(asyncore.dispatcher): 299 class SSLConnection(asyncore.dispatcher):
300 """An asyncore.dispatcher subclass supporting TLS/SSL.""" 300 """An asyncore.dispatcher subclass supporting TLS/SSL."""
301 301
302 _ssl_accepting = False 302 _ssl_accepting = False
303 _ssl_closing = False 303 _ssl_closing = False
304 304
305 def secure_connection(self): 305 def secure_connection(self):
306 self.del_channel()
306 socket = ssl.wrap_socket(self.socket, suppress_ragged_eofs=False, 307 socket = ssl.wrap_socket(self.socket, suppress_ragged_eofs=False,
307 certfile=CERTFILE, server_side=True, 308 certfile=CERTFILE, server_side=True,
308 do_handshake_on_connect=False, 309 do_handshake_on_connect=False,
309 ssl_version=ssl.PROTOCOL_SSLv23) 310 ssl_version=ssl.PROTOCOL_SSLv23)
310 self.del_channel()
311 self.set_socket(socket) 311 self.set_socket(socket)
312 self._ssl_accepting = True 312 self._ssl_accepting = True
313 313
314 def _do_ssl_handshake(self): 314 def _do_ssl_handshake(self):
315 try: 315 try:
316 self.socket.do_handshake() 316 self.socket.do_handshake()
317 except ssl.SSLError as err: 317 except ssl.SSLError as err:
318 if err.args[0] in (ssl.SSL_ERROR_WANT_READ, 318 if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
319 ssl.SSL_ERROR_WANT_WRITE): 319 ssl.SSL_ERROR_WANT_WRITE):
320 return 320 return
(...skipping 14 matching lines...) Expand all
335 if err.args[0] in (ssl.SSL_ERROR_WANT_READ, 335 if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
336 ssl.SSL_ERROR_WANT_WRITE): 336 ssl.SSL_ERROR_WANT_WRITE):
337 return 337 return
338 except socket.error as err: 338 except socket.error as err:
339 # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return 339 # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
340 # from OpenSSL's SSL_shutdown(), corresponding to a 340 # from OpenSSL's SSL_shutdown(), corresponding to a
341 # closed socket condition. See also: 341 # closed socket condition. See also:
342 # http://www.mail-archive.com/openssl-users@openssl.org/msg60710 .html 342 # http://www.mail-archive.com/openssl-users@openssl.org/msg60710 .html
343 pass 343 pass
344 self._ssl_closing = False 344 self._ssl_closing = False
345 if getattr(self, '_ccc', False) == False: 345 super(SSLConnection, self).close()
346 super(SSLConnection, self).close()
347 else:
348 pass
349 346
350 def handle_read_event(self): 347 def handle_read_event(self):
351 if self._ssl_accepting: 348 if self._ssl_accepting:
352 self._do_ssl_handshake() 349 self._do_ssl_handshake()
353 elif self._ssl_closing: 350 elif self._ssl_closing:
354 self._do_ssl_shutdown() 351 self._do_ssl_shutdown()
355 else: 352 else:
356 super(SSLConnection, self).handle_read_event() 353 super(SSLConnection, self).handle_read_event()
357 354
358 def handle_write_event(self): 355 def handle_write_event(self):
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 403
407 404
408 class DummyTLS_FTPHandler(SSLConnection, DummyFTPHandler): 405 class DummyTLS_FTPHandler(SSLConnection, DummyFTPHandler):
409 """A DummyFTPHandler subclass supporting TLS/SSL.""" 406 """A DummyFTPHandler subclass supporting TLS/SSL."""
410 407
411 dtp_handler = DummyTLS_DTPHandler 408 dtp_handler = DummyTLS_DTPHandler
412 409
413 def __init__(self, conn): 410 def __init__(self, conn):
414 DummyFTPHandler.__init__(self, conn) 411 DummyFTPHandler.__init__(self, conn)
415 self.secure_data_channel = False 412 self.secure_data_channel = False
416 self._ccc = False
417 413
418 def cmd_auth(self, line): 414 def cmd_auth(self, line):
419 """Set up secure control channel.""" 415 """Set up secure control channel."""
420 self.push('234 AUTH TLS successful') 416 self.push('234 AUTH TLS successful')
421 self.secure_connection() 417 self.secure_connection()
422 418
423 def cmd_ccc(self, line):
424 self.push('220 Reverting back to clear-text')
425 self._ccc = True
426 self._do_ssl_shutdown()
427
428 def cmd_pbsz(self, line): 419 def cmd_pbsz(self, line):
429 """Negotiate size of buffer for secure data transfer. 420 """Negotiate size of buffer for secure data transfer.
430 For TLS/SSL the only valid value for the parameter is '0'. 421 For TLS/SSL the only valid value for the parameter is '0'.
431 Any other value is accepted but ignored. 422 Any other value is accepted but ignored.
432 """ 423 """
433 self.push('200 PBSZ=0 successful.') 424 self.push('200 PBSZ=0 successful.')
434 425
435 def cmd_prot(self, line): 426 def cmd_prot(self, line):
436 """Setup un/secure data channel.""" 427 """Setup un/secure data channel."""
437 arg = line.upper() 428 arg = line.upper()
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 self.client.connect(self.server.host, self.server.port) 864 self.client.connect(self.server.host, self.server.port)
874 self.assertNotIsInstance(self.client.sock, ssl.SSLSocket) 865 self.assertNotIsInstance(self.client.sock, ssl.SSLSocket)
875 self.client.auth() 866 self.client.auth()
876 self.assertIs(self.client.sock.context, ctx) 867 self.assertIs(self.client.sock.context, ctx)
877 self.assertIsInstance(self.client.sock, ssl.SSLSocket) 868 self.assertIsInstance(self.client.sock, ssl.SSLSocket)
878 869
879 self.client.prot_p() 870 self.client.prot_p()
880 with self.client.transfercmd('list') as sock: 871 with self.client.transfercmd('list') as sock:
881 self.assertIs(sock.context, ctx) 872 self.assertIs(sock.context, ctx)
882 self.assertIsInstance(sock, ssl.SSLSocket) 873 self.assertIsInstance(sock, ssl.SSLSocket)
883
884 def test_ccc(self):
885 self.assertRaises(ValueError, self.client.ccc)
886 self.client.login(secure=True)
887 self.assertIsInstance(self.client.sock, ssl.SSLSocket)
888 self.client.ccc()
889 self.assertRaises(ValueError, self.client.sock.unwrap)
890 874
891 875
892 class TestTimeouts(TestCase): 876 class TestTimeouts(TestCase):
893 877
894 def setUp(self): 878 def setUp(self):
895 self.evt = threading.Event() 879 self.evt = threading.Event()
896 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 880 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
897 self.sock.settimeout(3) 881 self.sock.settimeout(3)
898 self.port = support.bind_port(self.sock) 882 self.port = support.bind_port(self.sock)
899 threading.Thread(target=self.server, args=(self.evt,self.sock)).start() 883 threading.Thread(target=self.server, args=(self.evt,self.sock)).start()
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 976
993 thread_info = support.threading_setup() 977 thread_info = support.threading_setup()
994 try: 978 try:
995 support.run_unittest(*tests) 979 support.run_unittest(*tests)
996 finally: 980 finally:
997 support.threading_cleanup(*thread_info) 981 support.threading_cleanup(*thread_info)
998 982
999 983
1000 if __name__ == '__main__': 984 if __name__ == '__main__':
1001 test_main() 985 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_fcntl.py ('k') | Lib/test/test_future5.py » ('j') | no next file with comments »

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