mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	asynchat: PEP8-ify the code
This commit is contained in:
		
							parent
							
								
									d9e810a870
								
							
						
					
					
						commit
						fd5d1b51d6
					
				
					 2 changed files with 68 additions and 57 deletions
				
			
		|  | @ -5,9 +5,12 @@ | |||
| # If this fails, the test will be skipped. | ||||
| thread = support.import_module('_thread') | ||||
| 
 | ||||
| import asyncore, asynchat, socket, time | ||||
| import unittest | ||||
| import asynchat | ||||
| import asyncore | ||||
| import socket | ||||
| import sys | ||||
| import time | ||||
| import unittest | ||||
| try: | ||||
|     import threading | ||||
| except ImportError: | ||||
|  | @ -28,8 +31,8 @@ def __init__(self, event): | |||
|             self.event = event | ||||
|             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||||
|             self.port = support.bind_port(self.sock) | ||||
|             # This will be set if the client wants us to wait before echoing data | ||||
|             # back. | ||||
|             # This will be set if the client wants us to wait before echoing | ||||
|             # data back. | ||||
|             self.start_resend_event = None | ||||
| 
 | ||||
|         def run(self): | ||||
|  | @ -52,8 +55,8 @@ def run(self): | |||
| 
 | ||||
|             # re-send entire set of collected data | ||||
|             try: | ||||
|                 # this may fail on some tests, such as test_close_when_done, since | ||||
|                 # the client closes the channel when it's done sending | ||||
|                 # this may fail on some tests, such as test_close_when_done, | ||||
|                 # since the client closes the channel when it's done sending | ||||
|                 while self.buffer: | ||||
|                     n = conn.send(self.buffer[:self.chunk_size]) | ||||
|                     time.sleep(0.001) | ||||
|  | @ -96,7 +99,7 @@ def start_echo_server(): | |||
|         s.start() | ||||
|         event.wait() | ||||
|         event.clear() | ||||
|         time.sleep(0.01) # Give server time to start accepting. | ||||
|         time.sleep(0.01)   # Give server time to start accepting. | ||||
|         return s, event | ||||
| 
 | ||||
| 
 | ||||
|  | @ -104,10 +107,10 @@ def start_echo_server(): | |||
| class TestAsynchat(unittest.TestCase): | ||||
|     usepoll = False | ||||
| 
 | ||||
|     def setUp (self): | ||||
|     def setUp(self): | ||||
|         self._threads = support.threading_setup() | ||||
| 
 | ||||
|     def tearDown (self): | ||||
|     def tearDown(self): | ||||
|         support.threading_cleanup(*self._threads) | ||||
| 
 | ||||
|     def line_terminator_check(self, term, server_chunk): | ||||
|  | @ -117,7 +120,7 @@ def line_terminator_check(self, term, server_chunk): | |||
|         s.start() | ||||
|         event.wait() | ||||
|         event.clear() | ||||
|         time.sleep(0.01) # Give server time to start accepting. | ||||
|         time.sleep(0.01)   # Give server time to start accepting. | ||||
|         c = echo_client(term, s.port) | ||||
|         c.push(b"hello ") | ||||
|         c.push(b"world" + term) | ||||
|  | @ -136,17 +139,17 @@ def line_terminator_check(self, term, server_chunk): | |||
| 
 | ||||
|     def test_line_terminator1(self): | ||||
|         # test one-character terminator | ||||
|         for l in (1,2,3): | ||||
|         for l in (1, 2, 3): | ||||
|             self.line_terminator_check(b'\n', l) | ||||
| 
 | ||||
|     def test_line_terminator2(self): | ||||
|         # test two-character terminator | ||||
|         for l in (1,2,3): | ||||
|         for l in (1, 2, 3): | ||||
|             self.line_terminator_check(b'\r\n', l) | ||||
| 
 | ||||
|     def test_line_terminator3(self): | ||||
|         # test three-character terminator | ||||
|         for l in (1,2,3): | ||||
|         for l in (1, 2, 3): | ||||
|             self.line_terminator_check(b'qqq', l) | ||||
| 
 | ||||
|     def numeric_terminator_check(self, termlen): | ||||
|  | @ -269,11 +272,13 @@ def test_push(self): | |||
| class TestAsynchat_WithPoll(TestAsynchat): | ||||
|     usepoll = True | ||||
| 
 | ||||
| 
 | ||||
| class TestHelperFunctions(unittest.TestCase): | ||||
|     def test_find_prefix_at_end(self): | ||||
|         self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1) | ||||
|         self.assertEqual(asynchat.find_prefix_at_end("qwertydkjf", "\r\n"), 0) | ||||
| 
 | ||||
| 
 | ||||
| class TestFifo(unittest.TestCase): | ||||
|     def test_basic(self): | ||||
|         f = asynchat.fifo() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner