mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	gh-98778: Update HTTPError to initialize properly even if fp is None (gh-99966)
This commit is contained in:
		
							parent
							
								
									3c89202247
								
							
						
					
					
						commit
						dc8a86893d
					
				
					 3 changed files with 10 additions and 7 deletions
				
			
		|  | @ -10,7 +10,7 @@ | |||
| an application may want to handle an exception like a regular | ||||
| response. | ||||
| """ | ||||
| 
 | ||||
| import io | ||||
| import urllib.response | ||||
| 
 | ||||
| __all__ = ['URLError', 'HTTPError', 'ContentTooShortError'] | ||||
|  | @ -42,12 +42,9 @@ def __init__(self, url, code, msg, hdrs, fp): | |||
|         self.hdrs = hdrs | ||||
|         self.fp = fp | ||||
|         self.filename = url | ||||
|         # The addinfourl classes depend on fp being a valid file | ||||
|         # object.  In some cases, the HTTPError may not have a valid | ||||
|         # file object.  If this happens, the simplest workaround is to | ||||
|         # not initialize the base classes. | ||||
|         if fp is not None: | ||||
|             self.__super_init(fp, hdrs, url, code) | ||||
|         if fp is None: | ||||
|             fp = io.StringIO() | ||||
|         self.__super_init(fp, hdrs, url, code) | ||||
| 
 | ||||
|     def __str__(self): | ||||
|         return 'HTTP Error %s: %s' % (self.code, self.msg) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dong-hee Na
						Dong-hee Na