[Python-ideas] Add "htmlcharrefreplace" error handler

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Jun 14 16:31:19 CEST 2013


2013/6/14 M.-A. Lemburg <mal at egenix.com>

> >> By the way, why is it necessary to register?
> >> Since an error handler is defined by its callback function,
> >> we could allow functions for the "errors" parameter.
> >
> > For the same reason we register modules in sys.modules:
> > to be able to reference them by name, rather than by object.
> >
> > Also note that codecs expect to get the error parameter as string
> > to keep the API simple and to make short-cuts easy to implement
> > in the code (esp. in the C implementations).
>
> Here's the PEP: http://www.python.org/dev/peps/pep-0293/


yes, I can understand the argument:
"As this requires changes to lots of C prototypes, this approach was
rejected."

A callable "errors" would have avoided this whole discussion:
Implement some htmlcharrefreplace function in htmllib.py, don't register it
at all,
and let users do .encode('ascii', htmllib.htmlcharrefreplace)
or implement their own without any global change to the codecs registry.

import.c was once rewritten to accept PyObject everywhere,
maybe unicode codecs could have a double API as well?
Yes, it's a lot of work.


-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130614/148f8fb2/attachment.html>


More information about the Python-ideas mailing list