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:
Marc-André Lemburg 2001-05-16 09:41:45 +00:00
parent 5a4718e1ed
commit 716cf91839
55 changed files with 75 additions and 162 deletions

View File

@ -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__':

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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')