@@ -23,28 +23,33 @@ def build_encmap(map) :
2323 dict [map [i ]] = "" + col * "." + " " + row * "."
2424 i += 1
2525 dict ['k' ] = dict ['c' ]
26- dict [' ' ] = ''
2726 return dict
2827
2928def encode_tap (text , errors = 'strict' ) :
3029 map = 'abcdefghijlmnopqrstuvwxyz'
3130 ENCMAP = build_encmap (map )
3231 encoded = ""
3332 for i , letter in enumerate (text ) :
34- encoded += ENCMAP [letter .lower ()]
33+ try :
34+ encoded += ENCMAP [letter .lower ()]
35+ except KeyError :
36+ pass
3537 if i != len (text ) - 1 and letter != ' ' :
3638 encoded += ' '
3739 return encoded , len (text )
3840
3941
40- def decode_tap (text , errors = 'strict ' ) :
42+ def decode_tap (text , errors = 'ignore ' ) :
4143 map = 'abcdefghijlmnopqrstuvwxyz'
4244 ENCMAP = build_encmap (map )
4345 decoded = ""
4446 for elem in text .split (" " ) :
45- decoded += next (key for key , value in ENCMAP .items () if value == elem )
47+ try :
48+ decoded += next (key for key , value in ENCMAP .items () if value == elem )
49+ except StopIteration :
50+ print ("Invalid character(s) in the input. This is what could be decoded :" )
4651 return decoded , len (text )
4752
4853
49- add ("tap" , encode_tap , decode_tap , ignore_case = "encode " )
54+ add ("tap" , encode_tap , decode_tap , ignore_case = "both " )
5055
0 commit comments