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.
This commit is contained in:
parent
5a4718e1ed
commit
716cf91839
|
@ -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__':
|
||||
|
|
|
@ -277,6 +277,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -135,6 +135,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -277,6 +277,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -120,6 +120,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -154,6 +154,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -73,6 +73,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -148,6 +148,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -79,6 +79,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -140,6 +140,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -126,6 +126,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -128,6 +128,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -87,6 +87,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -277,6 +277,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -277,6 +277,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -168,6 +168,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -167,6 +167,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -168,6 +168,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -278,6 +278,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -41,6 +41,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -87,6 +87,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -97,6 +97,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -72,6 +72,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -49,6 +49,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -98,6 +98,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -76,6 +76,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -91,6 +91,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -135,6 +135,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -134,6 +134,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -121,6 +121,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -109,6 +109,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -47,6 +47,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -169,6 +169,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -164,6 +164,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -167,6 +167,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -163,6 +163,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -167,6 +167,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -164,6 +164,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -164,6 +164,4 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
|
|
@ -93,9 +93,7 @@ decoding_map.update({
|
|||
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
|
||||
### Filter API
|
||||
|
||||
|
|
|
@ -244,9 +244,7 @@ def getregentry():
|
|||
append('''
|
||||
### Encoding Map
|
||||
|
||||
encoding_map = {}
|
||||
for k,v in decoding_map.items():
|
||||
encoding_map[v] = k
|
||||
encoding_map = codecs.make_encoding_map(decoding_map)
|
||||
''')
|
||||
return string.join(l,'\n')
|
||||
|
||||
|
|
Loading…
Reference in New Issue