mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Added new helpers for easy access to codecs. Docs will follow.
This commit is contained in:
		
							parent
							
								
									5e6007c5db
								
							
						
					
					
						commit
						aa32c5aa7c
					
				
					 1 changed files with 42 additions and 0 deletions
				
			
		|  | @ -539,6 +539,48 @@ def EncodedFile(file, data_encoding, file_encoding=None, errors='strict'): | |||
|     sr.file_encoding = file_encoding | ||||
|     return sr | ||||
| 
 | ||||
| ### Helpers for codec lookup | ||||
| 
 | ||||
| def getencoder(encoding): | ||||
| 
 | ||||
|     """ Lookup up the codec for the given encoding and return | ||||
|         its encoder function. | ||||
| 
 | ||||
|         Raises a LookupError in case the encoding cannot be found. | ||||
| 
 | ||||
|     """ | ||||
|     return lookup(encoding)[0] | ||||
| 
 | ||||
| def getdecoder(encoding): | ||||
| 
 | ||||
|     """ Lookup up the codec for the given encoding and return | ||||
|         its decoder function. | ||||
| 
 | ||||
|         Raises a LookupError in case the encoding cannot be found. | ||||
| 
 | ||||
|     """ | ||||
|     return lookup(encoding)[1] | ||||
| 
 | ||||
| def getreader(encoding): | ||||
| 
 | ||||
|     """ Lookup up the codec for the given encoding and return | ||||
|         its StreamReader class or factory function. | ||||
| 
 | ||||
|         Raises a LookupError in case the encoding cannot be found. | ||||
| 
 | ||||
|     """ | ||||
|     return lookup(encoding)[2] | ||||
| 
 | ||||
| def getwriter(encoding): | ||||
| 
 | ||||
|     """ Lookup up the codec for the given encoding and return | ||||
|         its StreamWriter class or factory function. | ||||
| 
 | ||||
|         Raises a LookupError in case the encoding cannot be found. | ||||
| 
 | ||||
|     """ | ||||
|     return lookup(encoding)[3] | ||||
| 
 | ||||
| ### Helpers for charmap-based codecs | ||||
| 
 | ||||
| def make_identity_dict(rng): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Marc-André Lemburg
						Marc-André Lemburg