Well, CPython at least still enforces the padding, even if it's ignoring the 
invalid characters.

Here's Seo's repro 'simplified' to go straight to binascii (just to get to the 
root API):

>>> import binascii
>>> binascii.a2b_base64('%')
''

And then sending a valid character, invalid padding:

>>> binascii.a2b_base64('A')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
binascii.Error: Incorrect padding

and then throwing in random invalid characters, and CPython ignores the invalid 
characters:

>>> binascii.a2b_base64('ABC=')
'\x00\x10'
>>> binascii.a2b_base64('%%ABC=')
'\x00\x10'
>>> binascii.a2b_base64('[EMAIL PROTECTED]')
'\x00\x10'
>>> binascii.a2b_base64('[EMAIL PROTECTED]()')
'\x00\x10'

The documentation for binascii.a2b_base64 doesn't specify if it throws for 
anything either.

I would suspect that there's a reason why CPython is ignoring the invalid 
characters here.  If this is the expected behavior then I'm happy to make 
IronPython match this.  And at the very least we HAVE to fix the exception that 
gets thrown - I'm with Seo that it should be a ValueError but line between 
ValueError and TypeError is blurry at times anyway, and TypeError is what's 
documented.


Do you want to help develop Dynamic languages on CLR? 
(http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sanghyeon Seo
Sent: Wednesday, April 05, 2006 10:45 PM
To: python-dev@python.org; users@lists.ironpython.com
Subject: [IronPython] base64 module

Hello,

base64 module documentation for b64decode function says, "TypeError is
raised if s were incorrectly padded or if there are non-alphabet
characters present in the string." But this doesn't seem to be the
case. Testcase:

import base64
base64.b64decode('%')

Since % is a non-alphabet character, this should raise TypeError (btw,
shouldn't this be ValueError instead?), but Python 2.4.3 silently
ignores.

I found this while experimenting with IronPython. IronPython 1.0 Beta 5 gives:

Traceback (most recent call last):
  File base64, line unknown, in b64decode
SystemError: cannot decode byte: '%'

It's not TypeError, but it doesn't silently ignore either.

Seo Sanghyeon
_______________________________________________
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to