[I18n-sig] Re: [Python-Dev] Pre-PEP: Python Character Model

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed, 7 Feb 2001 08:25:04 +0100

>     Python already has a rule that allows the automatic conversion
>     of characters up to 255 into their C equivalents. Once the Python
>     character type is expanded, characters outside of that range should
>     trigger an exception (just as converting a large long integer to a
>     C int triggers an exception).
> > For example, f.write would use the s# conversion (since the file was
> > opened in binary). What exactly would that do?
> Answer above.

So every s and s# conversion would trigger a copying of the
string. How is that implemented? Currently, every Unicode object has a
reference to a string object that is produced by converting to the
default character set. Would it grow another reference to a string
object that is carrying the Latin-1-conversion?

> Is it a requirement that PyString_AS_STRING return a pointer to the
> internal representation instead of a narrowed equivalent?

Certainly. Applications expect to write to the resulting memory, and
expect to change the underlying string; this is valid only if one had
been passing NULL to PyString_FromStringAndSize.