mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	Only close exclusive fp on Image __exit__
This commit is contained in:
		
							parent
							
								
									8194677516
								
							
						
					
					
						commit
						b1cc7df7ba
					
				|  | @ -28,3 +28,10 @@ class TestImageLoad(PillowTestCase): | |||
|             os.fstat(fn) | ||||
| 
 | ||||
|         self.assertRaises(OSError, os.fstat, fn) | ||||
| 
 | ||||
|     def test_contextmanager_non_exclusive_fp(self): | ||||
|         with open("Tests/images/hopper.gif", "rb") as fp: | ||||
|             with Image.open(fp): | ||||
|                 pass | ||||
| 
 | ||||
|             self.assertFalse(fp.closed) | ||||
|  |  | |||
|  | @ -578,7 +578,12 @@ class Image(object): | |||
|         return self | ||||
| 
 | ||||
|     def __exit__(self, *args): | ||||
|         self.close() | ||||
|         if hasattr(self, "_close__fp"): | ||||
|             self._close__fp() | ||||
|         if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') | ||||
|            and self.fp and self._exclusive_fp): | ||||
|             self.fp.close() | ||||
|         self.fp = None | ||||
| 
 | ||||
|     def close(self): | ||||
|         """ | ||||
|  | @ -610,12 +615,7 @@ class Image(object): | |||
| 
 | ||||
|     if sys.version_info.major >= 3: | ||||
|         def __del__(self): | ||||
|             if hasattr(self, "_close__fp"): | ||||
|                 self._close__fp() | ||||
|             if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') | ||||
|                and self.fp and self._exclusive_fp): | ||||
|                 self.fp.close() | ||||
|             self.fp = None | ||||
|             self.__exit__() | ||||
| 
 | ||||
|     def _copy(self): | ||||
|         self.load() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user