[Python-bugs-list] [ python-Bugs-547037 ] base64 newlines - documentation (again)

noreply@sourceforge.net noreply@sourceforge.net
Wed, 15 May 2002 06:57:27 -0700


Bugs item #547037, was opened at 2002-04-22 07:41
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=547037&group_id=5470

Category: Documentation
Group: Python 2.2.1 candidate
Status: Open
Resolution: None
Priority: 5
Submitted By: Paul Rouse (p_rouse)
Assigned to: Barry Warsaw (bwarsaw)
Summary: base64 newlines - documentation (again)

Initial Comment:
The documentation fix for bug 463330, describing the
newline added by base64.encode and base64.encodestring
appears to be incorrect!

The "courtesy newline" is appended to the result, not
the input (at line 466 of binsacii.c), so it is *not*
true that

base64.encodestring('hello') ==
base64.encodestring('hello\n')

In fact:

   base64.encodestring('hello') == 'aGVsbG8=\n'
   base64.encodestring('hello\n') == 'aGVsbG8K\n'

This applies to documentation for 2.2 and 2.2.1, and
actual behaviour has been checked in 2.2 

----------------------------------------------------------------------

>Comment By: Barry Warsaw (bwarsaw)
Date: 2002-05-15 09:57

Message:
Logged In: YES 
user_id=12800

Actually, I realized encodestring() is a bit more subtle
than that.  I think what it actually does is "return a
string containing one or more lines of base64-encoded data"
always including an extra trailing newline.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-15 04:13

Message:
Logged In: YES 
user_id=80475

Please approve the new patch.

----------------------------------------------------------------------

Comment By: Barry Warsaw (bwarsaw)
Date: 2002-05-15 00:51

Message:
Logged In: YES 
user_id=12800

I'm not sure the patch is sufficient.  You need to at least
explain that a newline is always added to the output.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-05-14 22:40

Message:
Logged In: YES 
user_id=3066

Barry, you're the MIME guru, tell Raymond whether he should
check in his patch.  ;-)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-14 12:11

Message:
Logged In: YES 
user_id=80475

Fred, is the attached patch okay to commit to 2.3 and 
release 22-maint?

----------------------------------------------------------------------

Comment By: Barry Warsaw (bwarsaw)
Date: 2002-05-14 09:52

Message:
Logged In: YES 
user_id=12800

The intended behavior is irrelevant <wink>.  Since this is
how the base64 module works, it needs to be correctly
documented.  It's way too late to be changing this behavior,
as broken as some might think it is.:)

Note that the email package has an RFC 2045-2047 compliant
base64 encoding module called email.base64MIME.  It
currently isn't documented (but will be before 2.3 is released).

Reassigning to Fred so he can correct the base64 documentation.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-14 03:40

Message:
Logged In: YES 
user_id=80475

Barry, is this the intended behavior or should the comment 
in the docs be eliminated?  The conversation in 
www.python.org/sf/463330 was not clear to me on this point.

Confirmed:
>>> import base64
>>> v = base64.encodestring('hello!')
>>> w = base64.encodestring('hello!\n')
>>> v == w, v , w
(False, 'aGVsbG8h\n', 'aGVsbG8hCg==\n')

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=547037&group_id=5470