mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Patch #1681153: the wave module now closes a file object it opened if
initialization failed.
This commit is contained in:
		
							parent
							
								
									8784bae65d
								
							
						
					
					
						commit
						ab1f4674ad
					
				
					 2 changed files with 15 additions and 2 deletions
				
			
		
							
								
								
									
										14
									
								
								Lib/wave.py
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								Lib/wave.py
									
										
									
									
									
								
							|  | @ -159,7 +159,12 @@ def __init__(self, f): | |||
|             f = __builtin__.open(f, 'rb') | ||||
|             self._i_opened_the_file = f | ||||
|         # else, assume it is an open file object already | ||||
|         self.initfp(f) | ||||
|         try: | ||||
|             self.initfp(f) | ||||
|         except: | ||||
|             if self._i_opened_the_file: | ||||
|                 f.close() | ||||
|             raise | ||||
| 
 | ||||
|     def __del__(self): | ||||
|         self.close() | ||||
|  | @ -297,7 +302,12 @@ def __init__(self, f): | |||
|         if isinstance(f, basestring): | ||||
|             f = __builtin__.open(f, 'wb') | ||||
|             self._i_opened_the_file = f | ||||
|         self.initfp(f) | ||||
|         try: | ||||
|             self.initfp(f) | ||||
|         except: | ||||
|             if self._i_opened_the_file: | ||||
|                 f.close() | ||||
|             raise | ||||
| 
 | ||||
|     def initfp(self, file): | ||||
|         self._file = file | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Georg Brandl
						Georg Brandl