Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.datemas.de!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:text': 0.05; 'encode': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'character.': 0.16; 'codec': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'throw': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header :In-Reply-To:1': 0.27; 'appear': 0.29; 'correct': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'file': 0.32; 'quite': 0.32; '(most': 0.33; "can't": 0.35; 'received:google.com': 0.35; 'error.': 0.37; 'pm,': 0.38; 'recent': 0.39; 'skip:u 10': 0.60; 'between': 0.67; 'mar': 0.68; 'invalid': 0.68; '2015': 0.84; 'to:none': 0.92 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:cc :content-type; bh=PxLhtYrMC6L+1r5g49ZsJiPb8KCe8YF3byElSBjDcgo=; b=UanCN5vwZqeaknkCEdxVpntfnqD5DVDDwvYm8S8zCo5EutIj5RpkIr29qN82iB2eGW GTSPPWJ+kFJJPYz1RCHbSWEBYoaOvJo3ybIc5QgJiRT+154H8vynPxEzyoaA61EKI0gJ cDlNHGFQ48Z8Ys1ID4XD6WjdpzbVIqDLK3jwDdhIfwjK+Nh4Z12iWKXjVn4iI5SL8OGK 7yDvMIVQhCiyXkRmD/8rUJUcAZcGePhAcr8AA0XnDOdBJ/t8VA0HQFKpNiAvfwrwpUX+ VlaLPS6rQZ4baerNIVfbpmbFc9YWPweiXsZIjmGlJ6f/ZP80srNiK0Zt+9aT5VSWVvAW U8cg== MIME-Version: 1.0 X-Received: by 10.42.203.147 with SMTP id fi19mr19299243icb.12.1425800254177; Sat, 07 Mar 2015 23:37:34 -0800 (PST) In-Reply-To: <87y4n8uf9a.fsf@elektro.pacujo.net> References: <201502241957.t1OJvrJS015604@fido.openend.se> <9169f3b1-2ac7-42a3-8033-584f84b88a1f@googlegroups.com> <7a75a23c-4678-4d7a-a2ec-9e8fff4c07f8@googlegroups.com> <132d5ce6-f672-4eec-99f9-1cc9e88b94f3@googlegroups.com> <619e4cb5-1c4c-449b-a5d7-951101b32b45@googlegroups.com> <54f862ca$0$13014$c3e8da3$5496439d@news.astraweb.com> <54fadc70$0$13004$c3e8da3$5496439d@news.astraweb.com> <87twxxxbvd.fsf@elektro.pacujo.net> <54fb1bf4$0$12993$c3e8da3$5496439d@news.astraweb.com> <87twxw4xlz.fsf@elektro.pacujo.net> <54fba9d4$0$12988$c3e8da3$5496439d@news.astraweb.com> <87y4n8uf9a.fsf@elektro.pacujo.net> Date: Sun, 8 Mar 2015 18:37:34 +1100 Subject: Re: Newbie question about text encoding From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425800257 news.xs4all.nl 2866 [2001:888:2000:d::a6]:53063 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:87136 On Sun, Mar 8, 2015 at 6:20 PM, Marko Rauhamaa wrote: > * it still isn't bijective between str and bytes: > > >>> '\udd00'.encode('utf-8', errors='surrogateescape') > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'utf-8' codec can't encode character > '\udd00' in position 0: surrogates not allowed Once again, you appear to be surprised that invalid data is failing. Why is this so strange? U+DD00 is not a valid character. It is quite correct to throw this error. ChrisA