On 14.06.2013 01:37, Ezio Melotti wrote:
Hi,
On Tue, Jun 11, 2013 at 5:49 PM, Serhiy Storchaka <storchaka@gmail.com> wrote:
I propose to add "htmlcharrefreplace" error handler which is similar to "xmlcharrefreplace" error handler but use html entity names if possible.
'∀ x∈ℜ'.encode('ascii', 'xmlcharrefreplace') b'∀ x∈ℜ' '∀ x∈ℜ'.encode('ascii', 'htmlcharrefreplace') b'∀ x∈ℜ'
Do you have any use cases for this, or is it just for completeness since we already have xmlcharrefreplace?
The purpose is the same, but in a different, also very common context. As for use cases, you already pointed out quite a few below and I'm adding a few more.
IMHO character references (named or numerical) should never be used in HTML (with the exception of " > and <). They exist mainly for three reasons: 1) provide a way to include characters that are not available in the used encoding (e.g. if you are using an obsolete encoding like windows-1252 but still want to use "fancy" characters); 2) to keep the HTML source ASCII-only;
This is the main reason for using them. HTML's default encoding is Latin-1, unlike XML.
3) to specify a character by name if it's not possible to enter it directly (e.g. you don't know the keys combinations);
They exist for the same reason you have named Unicode characters: to make it obvious which character you are using without having to rely on a specific encoding. Another reason to use them is that a user might not have the needed fonts to display the characters in question. And in some cases, you also need to use the references to escape certain characters from being interpreted using their HTML meaning, e.g. & and the ones you've given above. But that's not the use case for the error handler. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jun 14 2013)
Python Projects, Consulting and Support ... http://www.egenix.com/ mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
2013-07-01: EuroPython 2013, Florence, Italy ... 17 days to go 2013-07-16: Python Meeting Duesseldorf ... 32 days to go ::::: Try our mxODBC.Connect Python Database Interface for free ! :::::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/