[Python-checkins] CVS: python/dist/src/Lib codecs.py,1.17,1.18

M.-A. Lemburg lemburg@users.sourceforge.net
Wed, 16 May 2001 02:41:47 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv23495/Lib

Modified Files:
	codecs.py 
Log Message:
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.



Index: codecs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** codecs.py	2001/05/15 17:19:16	1.17
--- codecs.py	2001/05/16 09:41:45	1.18
***************
*** 555,558 ****
--- 555,579 ----
      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