Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'resulting': 0.04; 'suppose': 0.07; 'utf-8': 0.07; 'string': 0.09; '*is*': 0.09; 'area)': 0.09; 'fixed,': 0.09; 'hiding': 0.09; 'mind,': 0.09; 'python': 0.11; 'bug': 0.12; '1234': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handler.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'possible,': 0.19; 'thu,': 0.19; 'error': 0.23; 'byte': 0.24; 'bytes': 0.24; 'closely': 0.24; 'unicode': 0.24; 'skip:" 30': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'feature': 0.29; 'character': 0.29; 'points': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; '25,': 0.31; 'about.': 0.31; 'libraries': 0.31; 'sense': 0.34; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; "i'll": 0.36; 'should': 0.36; 'application': 0.37; 'two': 0.37; 'represent': 0.38; '8bit%:86': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'referred': 0.60; 'free': 0.61; 'length': 0.61; 'such': 0.63; 'talking': 0.65; 'results': 0.69; 'incoming': 0.72; 'jul': 0.74; 'conscious': 0.84; 'demand': 0.91; 'exposing': 0.91; 'imagine': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=heY5LJSQ34LuS91+quPbkH5N8w/fWaIJam/u+F3lH2Y=; b=nBr5Q4CSNSs7TiB49W9UF3dAT7DD3Nd3K1uR0vVd61jrVWlf13GVxX5aC8jKn+bnSX q6jgk8HLZr6nDN71iudIACfb8c3OYrKexwEcdgLrkkcfvCSwdxI4SywFyS30FUt5AJ/M CNnq6MtDOXzNPo01OLULOwbUZrglWsV/u2c/9CuBabT3i4ICUohmLZdkHfs61M8xW0SM aEUloVahlpa6fhhnRH2qtIsR9KklTH/Qs/XJgBmHMtfXGGWV3bOHpvLGM141l0Ta+6Sd 440ZCNvG8T8Yp8yPRtGs9+Bd7N3xSi4OTNU3U0bSrcOrlzsHpzrMyYAuHbEh4yHcNPAW Zb6w== MIME-Version: 1.0 X-Received: by 10.52.103.84 with SMTP id fu20mr9492422vdb.51.1374731914306; Wed, 24 Jul 2013 22:58:34 -0700 (PDT) In-Reply-To: References: <571a6dfe-fd66-42cf-92fc-8b97cbe6e9e4@googlegroups.com> <51DFDE65.5040001@Gmail.com> <4f1067f6-bc99-42ad-9166-37fb228b90e8@googlegroups.com> <51EFEC17.90303@gmail.com> Date: Thu, 25 Jul 2013 15:58:34 +1000 Subject: Re: RE Module Performance From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374732265 news.xs4all.nl 15907 [2001:888:2000:d::a6]:49544 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51194 On Thu, Jul 25, 2013 at 3:49 PM, Serhiy Storchaka wro= te: > 24.07.13 21:15, Chris Angelico =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=B2= (=D0=BB=D0=B0): > >> To my mind, exposing UTF-16 >> surrogates to the application is a bug to be fixed, not a feature to >> be maintained. > > > Python 3 uses code points from U+DC80 to U+DCFF (which are in surrogates > area) to represent undecodable bytes with surrogateescape error handler. That's a deliberate and conscious use of the codepoints; that's not what I'm talking about here. Suppose you read a UTF-8 stream of bytes from a file, and decode them into your language's standard string type. At this point, you should be working with a string of Unicode codepoints: "\22\341\210\264\360\222\215\205" --> "\x12\u1234\U00012345" The incoming byte stream has a length of 8, the resulting character stream has a length of 3. Now, if the language wants to use UTF-16 internally, it's free to do so: 0012 1234 d808 df45 When I referred to exposing surrogates to the application, this is what I'm talking about. If decoding the above byte stream results in a length 4 string where the last two are \xd808 and \xdf45, then it's exposing them. If it's a length 3 string where the last is \U00012345, then it's hiding them. To be honest, I don't imagine I'll ever see a language that stores strings in UTF-16 and then exposes them to the application as UTF-32; there's very little point. But such *is* possible, and if it's working closely with libraries that demand UTF-16, it might well make sense to do things that way. ChrisA