[Python-Dev] PEP 409 and the stdlib
Terry Jan Reedy
tjreedy at udel.edu
Mon May 20 20:32:53 CEST 2013
On 5/20/2013 11:39 AM, Steven D'Aprano wrote:
> On 21/05/13 00:12, Ethan Furman wrote:
>> As a case in point, base64.py is currently getting a bug fix, and also
>> contains this code:
>> def b32decode(s, casefold=False, map01=None):
>> for i in range(0, len(s), 8):
>> quanta = s[i: i + 8]
>> acc = 0
>> for c in quanta:
>> acc = (acc << 5) + b32rev[c]
>> except KeyError:
>> raise binascii.Error('Non-base32 digit found')
>> raise binascii.Error('Incorrect padding')
>> Does the KeyError qualify as irrelevant noise?
> IMO, it is irrelevant noise, and obviously so. The binascii.Error raised
> is not a bug to be fixed, it is a deliberate exception and part of the
> API of the binascii module. That it occurs inside an "except KeyError"
> block is a mere implementation detail.
Yes, the code could be revised to make a check on c before the indexing.
This would be redundant (and a slowdown) in that the check is already
done by the indexing mechanism. The whole point of the above is to
*replace* the default KeyError with a custom binascii.Error for
And I agree with Georg, please say which bad digit was found.
More information about the Python-Dev