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


Groups > comp.lang.python > #56431

Re: Encoding of surrogate code points to UTF-8

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'encoding': 0.05; 'reject': 0.07; 'strict': 0.07; 'subject:code': 0.07; 'utf-8': 0.07; 'string': 0.09; 'encode': 0.09; 'indicates': 0.09; 'url:unicode': 0.09; 'python': 0.11; 'bug': 0.12; '16-bit': 0.16; 'bullet': 0.16; 'codec': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'handling,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'pairs': 0.16; 'pairs,': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'sequence.': 0.16; 'subject:UTF': 0.16; 'sure.': 0.16; 'surrogate': 0.16; 'units,': 0.16; 'wrote:': 0.18; "python's": 0.19; 'header:User-Agent:1': 0.23; 'byte': 0.24; 'own.': 0.24; 'unicode': 0.24; '(see': 0.26; 'handling': 0.26; 'second': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'raise': 0.29; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; "skip:' 10": 0.31; '"",': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'writes:': 0.31; 'file': 0.32; '(most': 0.33; 'table': 0.34; 'could': 0.34; "can't": 0.35; 'received:84': 0.35; 'but': 0.35; 'sequence': 0.36; 'url:org': 0.36; 'should': 0.36; 'error.': 0.37; 'example,': 0.37; 'unit': 0.37; 'too': 0.37; 'two': 0.37; 'being': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'consists': 0.60; 'units': 0.60; 'first': 0.61; 'url:0': 0.67; 'header:Reply-To:1': 0.67; 'url:pdf': 0.68; 'invalid': 0.68; 'reply-to:no real name:2**0': 0.71; 'isolated': 0.84; 'lone': 0.84; 'reply- to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=PIY2p5aC c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=LqG8EI-UCiYA:10 a=--1n041xzFwA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=hDd6L7yn1Q0A:10 a=kZ7UWmmPAAAA:8 a=te1EGT4yAAAA:8 a=GFQ2S68NnonzV-S-6toA:9 a=wPNLvfGTeEIA:10 a=pyH5b1fOeEsA:10
X-AUTH mrabarnett:2500
Date Tue, 08 Oct 2013 18:00:58 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Encoding of surrogate code points to UTF-8
References <52540e03$0$29984$c3e8da3$5496439d@news.astraweb.com> <86mwmjlraq.fsf@gmail.com>
In-Reply-To <86mwmjlraq.fsf@gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.867.1381251660.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1381251660 news.xs4all.nl 15931 [2001:888:2000:d::a6]:38863
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:56431

Show key headers only | View raw


On 08/10/2013 16:23, Pete Forman wrote:
> Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:
>
>> I think this is a bug in Python's UTF-8 handling, but I'm not sure.
> [snip]
>> py> s = '\ud800\udc01'
>> py> s.encode('utf-8')
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800' in
>> position 0: surrogates not allowed
>>
>>
>> Have I misunderstood? I think that Python is being too strict about
>> rejecting surrogate code points. It should only reject lone surrogates,
>> or invalid pairs, not valid pairs. Have I misunderstood the Unicode FAQs,
>> or is this a bug in Python's handling of UTF-8?
>
> http://www.unicode.org/versions/Unicode6.2.0/ch03.pdf
>
> D75 Surrogate pair: A representation for a single abstract character
>    that consists of a sequence of two 16-bit code units, where the first
>    value of the pair is a high-surrogate code unit and the second value
>    is a low-surrogate code unit.
>
> * Surrogate pairs are used only in UTF-16. (See Section 3.9, Unicode
>    EncodingForms.)
>
> * Isolated surrogate code units have no interpretation on their own.
>    Certain other isolated code units in other encoding forms also have no
>    interpretation on their own. For example, the isolated byte [\x80] has
>    no interpretation in UTF-8; it can be used only as part of a multibyte
>    sequence. (See Table 3-7). It could be argued that this line by itself
>    should raise an error.
>
>
> That first bullet indicates that it is indeed illegal to use surrogate
> pairs in UTF-8 or UTF-32.
>
The only time you should get a surrogate pair in a Unicode string is in
a narrow build, which doesn't exist in Python 3.3 and later.

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


Thread

Encoding of surrogate code points to UTF-8 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 13:52 +0000
  Re: Encoding of surrogate code points to UTF-8 Neil Cerutti <neilc@norwich.edu> - 2013-10-08 15:14 +0000
    Re: Encoding of surrogate code points to UTF-8 Neil Cerutti <neilc@norwich.edu> - 2013-10-08 15:54 +0000
    Re: Encoding of surrogate code points to UTF-8 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 22:30 +0000
      Re: Encoding of surrogate code points to UTF-8 Terry Reedy <tjreedy@udel.edu> - 2013-10-08 21:28 -0400
        Re: Encoding of surrogate code points to UTF-8 Steven D'Aprano <steve@pearwood.info> - 2013-10-09 06:20 +0000
          Re: Encoding of surrogate code points to UTF-8 wxjmfauth@gmail.com - 2013-10-09 01:22 -0700
            Re: Encoding of surrogate code points to UTF-8 Ned Batchelder <ned@nedbatchelder.com> - 2013-10-09 06:22 -0400
              Re: Encoding of surrogate code points to UTF-8 Neil Cerutti <neilc@norwich.edu> - 2013-10-09 12:55 +0000
  Re: Encoding of surrogate code points to UTF-8 Pete Forman <petef4+usenet@gmail.com> - 2013-10-08 16:23 +0100
    Re: Encoding of surrogate code points to UTF-8 MRAB <python@mrabarnett.plus.com> - 2013-10-08 18:00 +0100
      Re: Encoding of surrogate code points to UTF-8 wxjmfauth@gmail.com - 2013-10-08 11:24 -0700
      Re: Encoding of surrogate code points to UTF-8 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 22:20 +0000
  Re: Encoding of surrogate code points to UTF-8 Terry Reedy <tjreedy@udel.edu> - 2013-10-08 17:47 -0400
  Re: Encoding of surrogate code points to UTF-8 Terry Reedy <tjreedy@udel.edu> - 2013-10-08 18:17 -0400

csiph-web