mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-22831: Use "with" to avoid possible fd leaks in distutils. (GH-10921)
This commit is contained in:
		
							parent
							
								
									71f82a2f20
								
							
						
					
					
						commit
						c5d5dfdb22
					
				
					 5 changed files with 63 additions and 67 deletions
				
			
		|  | @ -106,15 +106,14 @@ def _check_compiler(self): | |||
| 
 | ||||
|     def _gen_temp_sourcefile(self, body, headers, lang): | ||||
|         filename = "_configtest" + LANG_EXT[lang] | ||||
|         file = open(filename, "w") | ||||
|         if headers: | ||||
|             for header in headers: | ||||
|                 file.write("#include <%s>\n" % header) | ||||
|             file.write("\n") | ||||
|         file.write(body) | ||||
|         if body[-1] != "\n": | ||||
|             file.write("\n") | ||||
|         file.close() | ||||
|         with open(filename, "w") as file: | ||||
|             if headers: | ||||
|                 for header in headers: | ||||
|                     file.write("#include <%s>\n" % header) | ||||
|                 file.write("\n") | ||||
|             file.write(body) | ||||
|             if body[-1] != "\n": | ||||
|                 file.write("\n") | ||||
|         return filename | ||||
| 
 | ||||
|     def _preprocess(self, body, headers, include_dirs, lang): | ||||
|  | @ -203,17 +202,16 @@ def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, | |||
|         if isinstance(pattern, str): | ||||
|             pattern = re.compile(pattern) | ||||
| 
 | ||||
|         file = open(out) | ||||
|         match = False | ||||
|         while True: | ||||
|             line = file.readline() | ||||
|             if line == '': | ||||
|                 break | ||||
|             if pattern.search(line): | ||||
|                 match = True | ||||
|                 break | ||||
|         with open(out) as file: | ||||
|             match = False | ||||
|             while True: | ||||
|                 line = file.readline() | ||||
|                 if line == '': | ||||
|                     break | ||||
|                 if pattern.search(line): | ||||
|                     match = True | ||||
|                     break | ||||
| 
 | ||||
|         file.close() | ||||
|         self._clean() | ||||
|         return match | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka