Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63445

Re: [Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'example:': 0.03; 'subject:: [': 0.04; 'broken': 0.04; 'subject:Python': 0.06; 'suppose': 0.07; 'ascii': 0.09; 'compact': 0.09; 'latter': 0.09; 'logic': 0.09; 'subject: [': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; "wouldn't": 0.14; '8-bit': 0.16; 'be:': 0.16; 'equal.': 0.16; 'equivalences': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'invoked.': 0.16; 'mapped': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'non-ascii': 0.16; 'received:192.168.1.4': 0.16; 'subject:ideas': 0.16; 'subject:type': 0.16; 'surrogate': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'subject:] ': 0.20; 'cc:addr:python.org': 0.22; 'header :User-Agent:1': 0.23; 'byte': 0.24; 'bytes': 0.24; 'interpret': 0.24; 'unicode': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'compare': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'character': 0.29; "doesn't": 0.30; 'andrew': 0.30; "skip:' 10": 0.31; "d'aprano": 0.31; 'steven': 0.31; 'class': 0.32; 'not.': 0.33; 'skip:b 30': 0.33; 'could': 0.34; 'problem': 0.35; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'introducing': 0.36; 'should': 0.36; 'represent': 0.38; 'subject:new': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'read': 0.60; 'hope': 0.61; 'new': 0.61; 'entire': 0.61; 'range': 0.61; 'first': 0.61; 'here:': 0.62; 'name': 0.63; 'more': 0.64; 'here': 0.66; 'low': 0.83; '2014,': 0.84; 'confusing': 0.84; 'presumably': 0.84; 'returns.': 0.84; 'sfxlen:4': 0.84; "they'd": 0.84; 'pfxlen:big': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=dujiVTQ4 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=1STzrndQctQA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=icG0M43-6L8A:10 a=kZ7UWmmPAAAA:8 a=YtQnL2R9YmRhDyn9_M8A:9 a=QEXdDO2ut3YA:10 a=pyH5b1fOeEsA:10
X-AUTH mrabarnett:2500
Date Tue, 07 Jan 2014 18:22:28 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
CC python-list@python.org
Subject Re: [Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]
References <52C9B39F.6060205@stoneleaf.us> <CADbA=FXFah=pJq1jHME5P6E2_YV8Xr_i-YHavXEXg+38LYYdFg@mail.gmail.com> <87fvp1idip.fsf@uwakimon.sk.tsukuba.ac.jp> <CADbA=FUjeHzF46-fsBQxRNKzXF+pzTxyF-LHpueVmP8FVZVsqQ@mail.gmail.com> <1389009153.31778.YahooMailNeo@web181001.mail.ne1.yahoo.com> <87bnzphs7j.fsf@uwakimon.sk.tsukuba.ac.jp> <20140107154401.GK29356@ando> <FAE8F24A-C18A-4CC7-BE9D-06804BC99A3A@yahoo.com>
In-Reply-To <FAE8F24A-C18A-4CC7-BE9D-06804BC99A3A@yahoo.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5147.1389119135.18130.python-list@python.org> (permalink)
Lines 90
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389119135 news.xs4all.nl 2962 [2001:888:2000:d::a6]:60257
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63445

Show key headers only | View raw


On 2014-01-07 17:46, Andrew Barnert wrote:
 > I think Stephen's name "7-bit" is confusing people. If you try to
 > interpret the name sensibly, you get Steven's broken interpretation.
 > But if you read it as a nonsense word and work through the logic, it
 > all makes sense.
 >
 > On Jan 7, 2014, at 7:44, Steven D'Aprano <steve@pearwood.info> wrote:
 >
I was thinking about Ethan's suggestion of introducing a new bytestring
class and a lot of these suggestions are what I thought the bytestring
class could do.

[snip]
 >>
 >> Suppose we take a pure-ASCII byte-string and decode it:
 >>
 >>    b'abcd'.decode('ascii-compatible')
 >>
That would be:

     bytestring(b'abcd')

or even:

     bytestring('abcd')

[snip]
 >
 >> Suppose we take a byte-string with a non-ASCII byte:
 >>
 >>    b'abc\xFF'.decode('ascii-compatible')
 >>
That would be:

     bytestring(b'abc\xFF')

Bytes outside the ASCII range would be mapped to Unicode low
surrogates:

     bytestring(b'abc\xFF') == bytestring('abc\uDCFF')

[snip]
 >> Presumably they will compare equal, yes?
 >
 > I would hope not. One of them has the Unicode character U+FF, the
 > other has smuggled byte 0xFF, so they'd better not compare equal.
 >
 > However, the latter should compare equal to 'abc\uDCFF'. That's the
 > entire key here: the new representation is nothing but a more compact
 > way to represent strings that contain nothing but ASCII and surrogate
 > escapes.
 >
[snip]
 >>
 >> A concrete example:
 >>
 >>    s = b'abcd'.decode('ascii-compatible')
 >>    t = 'x'  # ASCII-compatible
 >>    s + t
 >>    => returns 'abcdx', with the "7-bit repr" flag cleared.

     s = bytestring(b'abcd')
     t = 'x'  # ASCII-compatible
     s + t
     => returns 'abcdx'
 >
 > Right. Here both s and t are normal 8-bit strings reprs in the first
 > place, so the new logic doesn't even get invoked. So yes, that's what
 > it returns.
 >
 >>    s = b'abcd'.decode('ascii-compatible')
 >>    t = 'ÿ'  # U+00FF, non-ASCII.
 >>
 >>    s + t
 >>    => returns 'abcd\uDCFF', with the "7-bit repr" flag set

     s = bytestring(b'abcd')
     t = 'ÿ'  # U+00FF, non-ASCII.
     s + t
     => returns 'abcd\xFF'

[snip]
There were also some other equivalences I was considering:

     bytestring(b'abc') == b'abc'
     bytestring(b'abc') == 'abc'

The problem there is that it wouldn't be transitive because:

     b'abc' != 'abc'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?] MRAB <python@mrabarnett.plus.com> - 2014-01-07 18:22 +0000

csiph-web