Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'programmer': 0.03; 'assign': 0.07; 'subject:file': 0.07; 'string': 0.09; 'assigning': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:\\ 10': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'bug': 0.12; "'test": 0.16; 'assignment.': 0.16; 'buffers,': 0.16; 'cryptic.': 0.16; 'former,': 0.16; 'latter,': 0.16; 'overwriting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:String': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'header:User- Agent:1': 0.23; 'pointer': 0.24; 'unicode': 0.24; 'mon,': 0.24; 'right.': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'url:bugs': 0.29; 'character': 0.29; 'code': 0.31; '>>>>': 0.31; 'ctypes': 0.31; 'sep': 0.31; 'workaround': 0.31; 'supposed': 0.32; 'url:python': 0.33; 'actual': 0.34; 'subject:the': 0.34; "can't": 0.35; 'created': 0.35; 'i.e.': 0.36; 'sequence': 0.36; 'url:org': 0.36; 'expected': 0.38; '8bit%:86': 0.38; 'to:addr:python-list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'ian': 0.60; 'most': 0.60; 'talking': 0.65; 'received:46': 0.66; '"one': 0.84; 'viable': 0.84; '2013,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: Chardet, file, ... and the Flexible String Representation Date: Thu, 12 Sep 2013 00:11:38 +0300 References: <4ce85ea8-4a4c-46cf-a546-ad999576a5f7@googlegroups.com> <1378486748.10472.18800565.3DE728D7@webmail.messagingengine.com> <1378751676.20097.19809157.789868C5@webmail.messagingengine.com> <1378754875.10227.19853781.2A750091@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 46.211.126.6 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 In-Reply-To: <1378754875.10227.19853781.2A750091@webmail.messagingengine.com> 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378933905 news.xs4all.nl 15943 [2001:888:2000:d::a6]:52824 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53996 09.09.13 22:27, random832@fastmail.us написав(ла): > On Mon, Sep 9, 2013, at 15:03, Ian Kelly wrote: >> Do you mean that it breaks when overwriting Python string object buffers, >> or when overwriting arbitrary C strings either received from C code or >> created with create_unicode_buffer? >> >> If the former, I think that is to be expected since ctypes ultimately >> can't >> know what is the actual type of the pointer it was handed -- much as in >> C, >> that's up to the programmer to get right. I also think it's very bad >> practice to be overwriting those anyway, since Python strings are >> supposed >> to be immutable. >> >> If the latter, that sounds like a bug in ctypes to me. > > I was talking about writing to the buffer object from python, i.e. with > slice assignment. >>>> s = 'Test \U00010000' >>>> len(s) > 6 >>>> buf = create_unicode_buffer(32) >>>> buf[:6] = s > TypeError: one character unicode string expected >>>> buf[:7] = s > ValueError: Can only assign sequence of same size >>>> buf[:7] = 'Test \ud800\udc00' >>>> buf[:7] > 'Test \U00010000' # len = 6 > > Assigning with .value works, however, which may be a viable workaround > for most situations. The "one character unicode string expected" message > is a bit cryptic. Please report a bug on http://bugs.python.org/.