[Python-ideas] Add "namereplace" error handler
M.-A. Lemburg
mal at egenix.com
Tue Jun 11 15:33:53 CEST 2013
On 11.06.2013 15:01, Steven D'Aprano wrote:
> On 11/06/13 22:34, M.-A. Lemburg wrote:
>>
>>
>> On 11.06.2013 13:21, Serhiy Storchaka wrote:
>>> I propose to add "namereplace" error handler which is similar to "backslashreplace" error handler
>>> but use \N escapes instead of \x/\u/\U escapes.
>>>
>>>>>> '−1'.encode('ascii', 'backslashreplace')
>>> b'\\u22121'
>>>>>> '−1'.encode('ascii', 'namereplace')
>>> b'\\N{MINUS SIGN}1'
>>>
>>> In some cases such representation is more readable.
>>>
>>> What are you think about this? Are there suggestions for better name?
>>
>> Nice idea.
>>
>> I think 'namereplace' is fine. An alternative would be
>> 'unicodenamereplace'.
>
>
> +1 on namereplace. unicodenamereplace is unnecessary, since strings in Python 3 are Unicode. Might
> as well say "stringnamereplace" :-)
The reference is to the "Unicode Name Property":
https://en.wikipedia.org/wiki/Unicode_character_property#Name
One detail such an error handler would have to define is
what to use in case no name is defined.
>>> unicodedata.lookup(unichr(13))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: "undefined character name '\r'"
Since the handler should probably be round-trip safe, I
guess falling back to the \u backslash notation would be
appropriate.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Jun 11 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 ... 20 days to go
2013-07-16: Python Meeting Duesseldorf ... 35 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/
More information about the Python-ideas
mailing list