[Python-checkins] CVS: python/dist/src/Lib codecs.py,1.22,1.23
M.-A. Lemburg
lemburg@users.sourceforge.net
Wed, 19 Sep 2001 04:24:51 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv21543/Lib
Modified Files:
codecs.py
Log Message:
Added new helpers for easy access to codecs. Docs will follow.
Index: codecs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** codecs.py 2001/09/18 20:29:48 1.22
--- codecs.py 2001/09/19 11:24:48 1.23
***************
*** 540,543 ****
--- 540,585 ----
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