[Python-bugs-list] [ python-Bugs-498124 ] base64 mishandles binary on Win32
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 05 Jan 2002 03:00:52 -0800
Bugs item #498124, was opened at 2001-12-31 09:56
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=498124&group_id=5470
Category: Python Library
Group: Platform-specific
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Tim Roberts (timroberts)
Assigned to: Nobody/Anonymous (nobody)
Summary: base64 mishandles binary on Win32
Initial Comment:
I'm using ActiveState Python 2.1.1 on Windows 2000
Service Pack 2, but I believe the problem happens on
any recent Win32 Python.
I use base64.py as a stand-alone tool for decoding
Base64 attachments. This produces incorrect results
with binary attachments on Win32, because it writes to
sys.stdout, which is open in text mode by default.
Thus, CR/LF and Ctrl-Z characters get botched. It is
safe to assume that a base64 attachment will result in
a binary file. A similar problem happens when
encoding.
The following patch towards the end of the test()
function in base64.py should fix this.
if o == '-t': test1(); return
+ if func == decode and sys.platform == 'win32':
+ import os, msvcrt
+ msvcrt.setmode( sys.stdout.fileno(),
os.O_BINARY )
if args and args[0] != '-':
! func(open(args[0], 'rb'), sys.stdout)
(Note I've changed 'r' to 'rb' in that last line;
that's safe on Win32 and ignored on Linux.)
----------------------------------------------------------------------
>Comment By: Martin v. Löwis (loewis)
Date: 2002-01-05 03:00
Message:
Logged In: YES
user_id=21627
This is not a bug. base64 is not intended as a stand-alone
program except for testing purposes.
If you still need this feature, and cannot write your own
script that imports base64, please submit a patch that
accepts an optional second file argument. I'd rather not
import msvcrt in this way in base64.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=498124&group_id=5470