[re-directed from tmda-users...]
Michael Toulouse <[EMAIL PROTECTED]> writes:
> Can anyone tell me why the value for "Errors" is set to 'ignore'
> instead of 'strict' at line 412 in PendList.py (below)? If it were
> set to 'strict' instead, I think this code would work. Or would
> that be a mistake?
[...]
> /usr/virthost/tmda-cgi/tmda-cgi-0.12/Unicode.py in
> TranslateToUTF8(CharSet='base64', Str='Zero Balance', Errors='ignore')
> 113 Uni = Decoder(Str, errors = Errors)[0]
> 114 except TypeError:
> 115 Uni = Decoder(Str)[0]
> 116
> 117 # Encode for UTF-8
> Uni undefined, Decoder = <function base64_decode>, Str = 'Zero Balance'
>
> /usr/local/lib/python2.3/encodings/base64_codec.py in base64_decode(input='Zero
> Balance', errors='ignore')
> 39
> 40 """
> 41 assert errors == 'strict'
> 42 output = base64.decodestring(input)
> 43 return (output, len(input))
> errors = 'ignore'
Gre7g, Jim, base64 can only be decoded 'strict'. In Unicode.py, on
line 113 you try to decode with the 'Errors' parameter and if it fails
with a TypeError you decode with the default. The problem with base64
is that it fails with an AssertionError. Could you just catch any
exception and retry with the default? I.e.,
try:
Uni = Decoder(Str, errors = Errors)[0]
except:
Uni = Decoder(Str)[0]
That would fix the problem Michael is having and would, I think,
better accomplish what you're trying to solve by catching the
exception in the first place.
Tim
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers