mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Message.getheader(): Fixed grammatical error in docstring.
Message.getheaders(): Method to get list of all values for each instance of a named header. See docstring for more.
This commit is contained in:
		
							parent
							
								
									a4b055ff89
								
							
						
					
					
						commit
						ddf22c4243
					
				
					 1 changed files with 26 additions and 1 deletions
				
			
		|  | @ -272,7 +272,7 @@ def getrawheader(self, name): | ||||||
|     def getheader(self, name, default=None): |     def getheader(self, name, default=None): | ||||||
|         """Get the header value for a name. |         """Get the header value for a name. | ||||||
|          |          | ||||||
|         This is the normal interface: it return a stripped |         This is the normal interface: it returns a stripped | ||||||
|         version of the header value for a given header name, |         version of the header value for a given header name, | ||||||
|         or None if it doesn't exist.  This uses the dictionary |         or None if it doesn't exist.  This uses the dictionary | ||||||
|         version which finds the *last* such header. |         version which finds the *last* such header. | ||||||
|  | @ -283,6 +283,31 @@ def getheader(self, name, default=None): | ||||||
|             return default |             return default | ||||||
|     get = getheader |     get = getheader | ||||||
| 
 | 
 | ||||||
|  |     def getheaders(self, name): | ||||||
|  |         """Get all values for a header. | ||||||
|  | 
 | ||||||
|  |         This returns a list of values for headers given more than once; | ||||||
|  |         each value in the result list is stripped in the same way as the | ||||||
|  |         result of getheader().  If the header is not given, return None. | ||||||
|  |         """ | ||||||
|  |         result = [] | ||||||
|  |         current = '' | ||||||
|  |         have_header = 0 | ||||||
|  |         for s in self.getallmatchingheaders(name): | ||||||
|  |             if s[0] in string.whitespace: | ||||||
|  |                 if current: | ||||||
|  |                     current = "%s\n %s" % (current, string.strip(s)) | ||||||
|  |                 else: | ||||||
|  |                     current = string.strip(s) | ||||||
|  |             else: | ||||||
|  |                 if have_header: | ||||||
|  |                     result.append(current) | ||||||
|  |                 current = string.strip(s[string.find(s, ":") + 1:]) | ||||||
|  |                 have_header = 1 | ||||||
|  |         if have_header: | ||||||
|  |             result.append(current) | ||||||
|  |         return result or None | ||||||
|  |      | ||||||
|     def getaddr(self, name): |     def getaddr(self, name): | ||||||
|         """Get a single address from a header, as a tuple. |         """Get a single address from a header, as a tuple. | ||||||
|          |          | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Fred Drake
						Fred Drake