mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Fixing the errors trigerred in test_urllib2net. Related to issue8656.
This commit is contained in:
		
							parent
							
								
									6057ba1f97
								
							
						
					
					
						commit
						18e4dd74e0
					
				
					 1 changed files with 8 additions and 5 deletions
				
			
		|  | @ -1276,13 +1276,13 @@ def open_local_file(self, req): | ||||||
|         import email.utils |         import email.utils | ||||||
|         import mimetypes |         import mimetypes | ||||||
|         host = req.get_host() |         host = req.get_host() | ||||||
|         file = req.get_selector() |         filename = req.get_selector() | ||||||
|         localfile = url2pathname(file) |         localfile = url2pathname(filename) | ||||||
|         try: |         try: | ||||||
|             stats = os.stat(localfile) |             stats = os.stat(localfile) | ||||||
|             size = stats.st_size |             size = stats.st_size | ||||||
|             modified = email.utils.formatdate(stats.st_mtime, usegmt=True) |             modified = email.utils.formatdate(stats.st_mtime, usegmt=True) | ||||||
|             mtype = mimetypes.guess_type(file)[0] |             mtype = mimetypes.guess_type(filename)[0] | ||||||
|             headers = mimetools.Message(StringIO( |             headers = mimetools.Message(StringIO( | ||||||
|                 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % |                 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % | ||||||
|                 (mtype or 'text/plain', size, modified))) |                 (mtype or 'text/plain', size, modified))) | ||||||
|  | @ -1290,8 +1290,11 @@ def open_local_file(self, req): | ||||||
|                 host, port = splitport(host) |                 host, port = splitport(host) | ||||||
|             if not host or \ |             if not host or \ | ||||||
|                 (not port and socket.gethostbyname(host) in self.get_names()): |                 (not port and socket.gethostbyname(host) in self.get_names()): | ||||||
|                 return addinfourl(open(localfile, 'rb'), |                 if host: | ||||||
|                                   headers, 'file://'+ host + file) |                     origurl = 'file://' + host + filename | ||||||
|  |                 else: | ||||||
|  |                     origurl = 'file://' + filename | ||||||
|  |                 return addinfourl(open(localfile, 'rb'), headers, origurl) | ||||||
|         except OSError, msg: |         except OSError, msg: | ||||||
|             # urllib2 users shouldn't expect OSErrors coming from urlopen() |             # urllib2 users shouldn't expect OSErrors coming from urlopen() | ||||||
|             raise URLError(msg) |             raise URLError(msg) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Senthil Kumaran
						Senthil Kumaran