summaryrefslogtreecommitdiffstats
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-05-16 09:41:45 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2001-05-16 09:41:45 (GMT)
commit716cf918390f86c69fb1525e13273570521da759 (patch)
treebf08e82c0f2dada12119fa31a5e23912ac5046bc /Lib/codecs.py
parent5a4718e1ed82ad378f464097d86e0d00fffe2b80 (diff)
downloadcpython-716cf918390f86c69fb1525e13273570521da759.zip
cpython-716cf918390f86c69fb1525e13273570521da759.tar.gz
cpython-716cf918390f86c69fb1525e13273570521da759.tar.bz2
Moved the encoding map building logic from the individual mapping
codec files to codecs.py and added logic so that multi mappings in the decoding maps now result in mappings to None (undefined mapping) in the encoding maps.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index b2eab1d..bdc8d02 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -554,6 +554,27 @@ def make_identity_dict(rng):
res[i]=i
return res
+def make_encoding_map(decoding_map):
+
+ """ Creates an encoding map from a decoding map.
+
+ If a target mapping in the decoding map occurrs multiple
+ times, then that target is mapped to None (undefined mapping),
+ causing an exception when encountered by the charmap codec
+ during translation.
+
+ One example where this happens is cp875.py which decodes
+ multiple character to \u001a.
+
+ """
+ m = {}
+ for k,v in decoding_map.items():
+ if not m.has_key(v):
+ m[v] = k
+ else:
+ m[v] = None
+ return m
+
### Tests
if __name__ == '__main__':