summaryrefslogtreecommitdiffstats
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-09-19 11:24:48 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-09-19 11:24:48 (GMT)
commitaa32c5aa7ca9ce842628d90c2d0fb4406ab5ff82 (patch)
tree47a6f03d83d620dadbef956f19ffa7bebbc7aca6 /Lib/codecs.py
parent5e6007c5dbb14a6c64d4b7ee95793465f544bca6 (diff)
downloadcpython-aa32c5aa7ca9ce842628d90c2d0fb4406ab5ff82.zip
cpython-aa32c5aa7ca9ce842628d90c2d0fb4406ab5ff82.tar.gz
cpython-aa32c5aa7ca9ce842628d90c2d0fb4406ab5ff82.tar.bz2
Added new helpers for easy access to codecs. Docs will follow.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 827719b..df203c6 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -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):