Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: base64.b64encode(data) Date: Sun, 12 Jun 2016 23:20:57 -0400 Lines: 22 Message-ID: References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de mCmZUzYePz9P+TYCbAPZxQ2t6oAeO0nqNhbCk0QAoSYw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'binary': 0.05; 'subject:skip:b 10': 0.07; 'base64': 0.09; 'bytes,': 0.09; 'naturally': 0.09; 'protocols.': 0.09; 'received:internal': 0.09; 'output': 0.13; 'encoding': 0.15; 'ebcdic': 0.16; 'manner,': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'peek': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.212': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; 'byte': 0.18; 'bytes': 0.18; 'variable': 0.18; 'arguments': 0.22; 'seems': 0.23; 'header:In- Reply-To:1': 0.24; 'specifically': 0.28; 'values': 0.28; 'convenience': 0.29; 'idea?': 0.29; 'convert': 0.29; 'print': 0.30; 'e.g.': 0.30; 'choosing': 0.33; "d'aprano": 0.33; 'displayed': 0.33; 'steven': 0.33; 'except': 0.34; 'text': 0.35; 'exist': 0.35; 'unicode': 0.35; 'but': 0.36; 'needed': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'display': 0.37; '12,': 0.37; 'received:66': 0.38; 'represent': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'is.': 0.63; 'safe': 0.63; 'wish': 0.71; 'nonsense.': 0.84; 'absolutely': 0.88 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=c/6cgUFY1YTbepCk/cIqnOP7ONM=; b=GAQ40i WCb4Wk2CxJHXP7QTXwEYI3Dvub6TbmGcYRUAxST+RhsGJ26GPURMoqv8mCBCfyWl f13OduWvxS+j72iXdlsvZu6sC0Kq1XtG2t1qS9slr5exMv4h7caL8uou+tgNs1Qs FX5Xr0+QiGAJtU3NHMymNSamCnH9qQP0p0PQg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=c/6cgUFY1YTbepC k/cIqnOP7ONM=; b=P+nytbeWVp1vl+Wm2AIERxAym/E8YjJkuCMY2nPiefFGNRv tPA+wCfNpOCsBrcTlzmKSxp13JqNt/Ls/nQiWdOJCh25ilOqh5IUfzLD4ZLkw5WT RMGDTzJNgs2ml8KOZPVIZlvnp7DIfH2DojQMvzo8qIm1G5ow2BQOZpb+pXAk= X-Sasl-Enc: ra//SmK7dm8NxFE8aA74g/6e6rUZ0KsqMzrrIFdaal1I 1465788057 X-Mailer: MessagingEngine.com Webmail Interface - ajax-aff28cd1 In-Reply-To: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1465788057.2854167.635655857.445F242C@webmail.messagingengine.com> X-Mailman-Original-References: <575e18f1$0$1588$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:109881 On Sun, Jun 12, 2016, at 22:22, Steven D'Aprano wrote: > That's because base64 is a bytes-to-bytes transformation. It has > nothing to do with unicode encodings. Nonsense. base64 is a binary-to-text encoding scheme. The output range is specifically chosen to be safe to transmit in text protocols. > > That is, the b64_encoded_data variable is of type 'bytes' and when > > you peek inside it's a string (made up of what seems to be only > > characters that exist in Base 64). > > If you print or otherwise display bytes, for the convenience of human > beings, those bytes are displayed as if they were ASCII. E.g. the byte > 0x61 is displayed as 'a'. Good idea? Bad idea? I can see arguments > either way, but that's how it is. There's absolutely no rational basis for choosing "0x41-0x5A, 0x61-0x7A, 0x30-0x39, 0x2B, 0x2F" as the output range except for what characters those values represent in ASCII. And if you needed to smuggle some binary data through an EBCDIC system in the same manner, you would naturally wish to convert it to the EBCDIC bytes corresponding to those same characters.