REPOST: Suggested tweak to base64.py

Tim Roberts timr at probo.com
Sun Dec 30 22:21:43 CET 2001


Once in a while, I use the base64.py standard library module as a
standalone Base64 decoder.  However, there is a slight problem with this.
Most base64 attachments are encoded because they were binary files to begin
with.  The base64.py test() module writes its results to stdout, which on
Windows is a text file by default.  CR/LF and Ctrl-Z confusion ensues.

I'd like to suggest the following four lines be inserted just before the
end of base64.test():

    ...
        if o == '-t': test1(); return
+   if func == decode and sys.platform == 'win32':
+       import os
+       import msvcrt
+       msvcrt.setmode( sys.stdout.fileno(), os.O_BINARY )
    if args and args[0] != '-':
        func(open(args[0], 'rb'), sys.stdout)
    else:
        func(sys.stdin, sys.stdout)
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-nwblwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!upp1.onvoy!onvoy.com!nntp1.phx1.gblx.net!nntp.gblx.net!nntp.gblx.net!hub1.nntpserver.com!news-out.spamkiller.net!propagator-la!news-in-la.newsfeeds.com!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Tim Roberts <timr at probo.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <r21v2u4cqti58i2269bqr8nh0a1i7s3ct5 at 4ax.com>
Control: cancel <r21v2u4cqti58i2269bqr8nh0a1i7s3ct5 at 4ax.com>
Date: Mon, 31 Dec 2001 02:31:15 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.r21v2u4cqti58i2269bqr8nh0a1i7s3ct5 at 4ax.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009774069 27193 211.57.49.2 (31 Dec 2001 04:47:49 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 04:47:49 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.



More information about the Python-list mailing list