mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 13:11:29 +00:00 
			
		
		
		
	bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
This commit is contained in:
		
							parent
							
								
									afbb7a371f
								
							
						
					
					
						commit
						172bb39452
					
				
					 27 changed files with 249 additions and 259 deletions
				
			
		|  | @ -29,9 +29,8 @@ def strip_to_x509_cert(certfile_contents, outfile=None): | |||
|             return None | ||||
|         else: | ||||
|             tn = tempfile.mktemp() | ||||
|             fp = open(tn, "wb") | ||||
|             fp.write(m.group(1) + b"\n") | ||||
|             fp.close() | ||||
|             with open(tn, "wb") as fp: | ||||
|                 fp.write(m.group(1) + b"\n") | ||||
|             try: | ||||
|                 tn2 = (outfile or tempfile.mktemp()) | ||||
|                 status, output = subproc(r'openssl x509 -in "%s" -out "%s"' % | ||||
|  | @ -39,9 +38,8 @@ def strip_to_x509_cert(certfile_contents, outfile=None): | |||
|                 if status != 0: | ||||
|                     raise RuntimeError('OpenSSL x509 failed with status %s and ' | ||||
|                                        'output: %r' % (status, output)) | ||||
|                 fp = open(tn2, 'rb') | ||||
|                 data = fp.read() | ||||
|                 fp.close() | ||||
|                 with open(tn2, 'rb') as fp: | ||||
|                     data = fp.read() | ||||
|                 os.unlink(tn2) | ||||
|                 return data | ||||
|             finally: | ||||
|  | @ -49,9 +47,8 @@ def strip_to_x509_cert(certfile_contents, outfile=None): | |||
| 
 | ||||
|     if sys.platform.startswith("win"): | ||||
|         tfile = tempfile.mktemp() | ||||
|         fp = open(tfile, "w") | ||||
|         fp.write("quit\n") | ||||
|         fp.close() | ||||
|         with open(tfile, "w") as fp: | ||||
|             fp.write("quit\n") | ||||
|         try: | ||||
|             status, output = subproc( | ||||
|                 'openssl s_client -connect "%s:%s" -showcerts < "%s"' % | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka