<div dir="ltr"><div><div><div>Error handlers are quite orthogonal to this problem. If you try to solve this problem with an error handler, you will have a different problem.<br><br></div>Suppose you made "c1-control-passthrough" or whatever into an error handler, similar to "replace" or "ignore", and then you encounter an unassigned character that's *not* in the range 0x80 to 0x9f. (Many encodings have these.) Do you replace it? Do you ignore it? You don't know because you just replaced the error handler with something that's not about error handling.<br><br></div>I will also repeat that having these encodings (in both directions) will provide more ways for Python to *reduce* the amount of mojibake that exists. If acknowledging that mojibake exists offends your sense of purity, and you'd rather just destroy all mojibake at the source... that's great, and please get back to me after you've fixed Microsoft Excel.<br><br></div>I hope to make a pull request shortly that implements these mappings as new encodings that work just like the other ones.<br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, 19 Jan 2018 at 11:54 M.-A. Lemburg <<a href="mailto:mal@egenix.com">mal@egenix.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 19.01.2018 17:20, Guido van Rossum wrote:<br>
> On Fri, Jan 19, 2018 at 5:30 AM, M.-A. Lemburg <<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a><br>
> <mailto:<a href="mailto:mal@egenix.com" target="_blank">mal@egenix.com</a>>> wrote:<br>
><br>
>     On 19.01.2018 05:38, Nathaniel Smith wrote:<br>
>     > On Thu, Jan 18, 2018 at 7:51 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a> <mailto:<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>>> wrote:<br>
>     >> Can someone explain to me why this is such a controversial issue?<br>
>     ><br>
>     > I guess practicality versus purity is always controversial :-)<br>
>     ><br>
>     >> It seems reasonable to me to add new encodings to the stdlib that do the<br>
>     >> roundtripping requested in the first message of the thread. As long as they<br>
>     >> have new names that seems to fall under "practicality beats purity".<br>
><br>
>     There are a few issues here:<br>
><br>
>     * WHATWG encodings are mostly for decoding content in order to<br>
>       show it in the browser, accepting broken encoding data.<br>
><br>
><br>
> And sometimes Python apps that pull data from the web.<br>
>  <br>
><br>
>       Python already has support for this by using one of the available<br>
>       error handlers, or adding new ones to suit the needs.<br>
><br>
><br>
> This seems cumbersome though.<br>
  <br>
Why is that ?<br>
<br>
Python 3 uses such error handlers for most of the I/O that's done<br>
with the OS already and for very similar reasons: dealing with<br>
broken data or broken configurations.<br>
<br>
>       If we'd add the encodings, people will start creating more<br>
>       broken data, since this is what the WHATWG codecs output<br>
>       when encoding Unicode.<br>
><br>
><br>
> That's FUD. Only apps that specifically use the new WHATWG encodings<br>
> would be able to consume that data. And surely the practice of web<br>
> browsers will have a much bigger effect than Python's choice.<br>
  <br>
It's not FUD. I don't think we ought to encourage having<br>
Python create more broken data. The purpose of the WHATWG<br>
encodings is to help browsers deal with decoding broken<br>
data in a uniform way. It's not to generate more such data.<br>
<br>
That may be regarded as purists view, but also has a very<br>
practical meaning. The output of the codecs will only readable<br>
by browsers implementing the WHATWG encodings. Other tools<br>
receiving the data will run into the same decoding problems.<br>
<br>
Once you have Unicode, it's better to stay there and use<br>
UTF-8 for encoding to avoid any such issues.<br>
<br>
>       As discussed, this could be addressed by making the WHATWG<br>
>       codecs decode-only.<br>
><br>
><br>
> But that would defeat the point of roundtripping, right?<br>
<br>
Yes, intentionally. Once you have Unicode, the data should<br>
be encoded correctly back into UTF-8 or whatever legacy encoding<br>
is needed, fixing any issues while in Unicode.<br>
<br>
As always, it's better to explicitly address such problems than<br>
to simply punt on them and write back broken data.<br>
<br>
>     * The use case seems limited to implementing browsers or headless<br>
>       implementations working like browsers.<br>
><br>
>       That's not really general enough to warrant adding lots of<br>
>       new codecs to the stdlib. A PyPI package is better suited<br>
>       for this.<br>
><br>
><br>
> Perhaps, but such a package already exists and its author (who surely<br>
> has read a lot of bug reports from its users) says that this is cumbersome.<br>
  <br>
The only critique I read was that registering the codecs<br>
is not explicit enough, but that's really only a nit, since<br>
you can easily have the codec package expose a register<br>
function which you then call explicitly in the code using<br>
the codecs.<br>
<br>
>     * The WHATWG codecs do not only cover simple mapping codecs,<br>
>       but also many multi-byte ones for e.g. Asian languages.<br>
><br>
>       I doubt that we'd want to maintain such codecs in the stdlib,<br>
>       since this will increase the download sizes of the installers<br>
>       and also require people knowledgeable about these variants<br>
>       to work on them and fix any issues.<br>
><br>
><br>
> Really? Why is adding a bunch of codecs so much effort? Surely the<br>
> translation tables contain data that compresses well? And surely we<br>
> don't need a separate dedicated piece of C code for each new codec?<br>
  <br>
For the simple charmap style codecs that's true. Not so for the<br>
Asian ones and the latter also do require dedicated C code (see<br>
Modules/cjkcodecs).<br>
<br>
>     Overall, I think either pointing people to error handlers<br>
>     or perhaps adding a new one specifically for the case of<br>
>     dealing with control character mappings would provide a better<br>
>     maintenance / usefulness ratio than adding lots of new<br>
>     legacy codecs to the stdlib.<br>
><br>
><br>
> Wouldn't error handlers be much slower? And to me it seems a new error<br>
> handler is a much *bigger* deal than some new encodings -- error<br>
> handlers must work for *all* encodings.<br>
  <br>
Error handlers have a standard interface and so they will work<br>
for all codecs. Some codecs limits the number of handlers that<br>
can be used, but most accept all registered handlers.<br>
<br>
If a handler is too slow in Python, it can be coded in C for<br>
speed.<br>
<br>
>     BTW: WHATWG pushes for always using UTF-8 as far as I can tell<br>
>     from their website.<br>
><br>
><br>
> As does Python. But apparently it will take decades more to get there.<br>
<br>
Yes indeed, so let's not add even more confusion by adding more<br>
variants of the legacy encodings.<br>
<br>
--<br>
Marc-Andre Lemburg<br>
eGenix.com<br>
<br>
Professional Python Services directly from the Experts (#1, Jan 19 2018)<br>
>>> Python Projects, Coaching and Consulting ...  <a href="http://www.egenix.com/" rel="noreferrer" target="_blank">http://www.egenix.com/</a><br>
>>> Python Database Interfaces ...           <a href="http://products.egenix.com/" rel="noreferrer" target="_blank">http://products.egenix.com/</a><br>
>>> Plone/Zope Database Interfaces ...           <a href="http://zope.egenix.com/" rel="noreferrer" target="_blank">http://zope.egenix.com/</a><br>
________________________________________________________________________<br>
<br>
::: We implement business ideas - efficiently in both time and costs :::<br>
<br>
   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48<br>
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg<br>
           Registered at Amtsgericht Duesseldorf: HRB 46611<br>
               <a href="http://www.egenix.com/company/contact/" rel="noreferrer" target="_blank">http://www.egenix.com/company/contact/</a><br>
                      <a href="http://www.malemburg.com/" rel="noreferrer" target="_blank">http://www.malemburg.com/</a><br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>