-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the "namereplace" error handler #63875
Comments
The proposed patch adds the "namereplace" error handler. This error handler is almost same as the "backslashreplace" error handler, but use \N{...} escape sequences if there is a character name in Unicode database. Result is a little more human-readable (but less portable) than with "backslashreplace". >>> '∀ x∈ℜ'.encode('ascii', 'namereplace')
b'\\N{FOR ALL} x\\N{ELEMENT OF}\\N{BLACK-LETTER CAPITAL R}' The proposition was discussed and bikeshedded on Python-Ideas: http://comments.gmane.org/gmane.comp.python.ideas/21296 . |
See also issue bpo-18234. |
Ping. |
The patch looks good to me. |
The patch looks good. One nit: the name buffer length should be NAME_MAXLEN instead of 100. |
Patch looks good to me, too. As far as Amaury's question goes, isn't the general reverse operation the same as for the existing backslashreplace handler? That is, decode with the appropriate ASCII compatible encoding (since ASCII compatibility is needed for the escape sequences to be valid), then run the result through ast.literal_eval? (I'll grant we don't currently provide guidance on reversing backslashreplace either, but addressing that sounds like a separate question from this change) |
New changeset 32d08aacffe0 by Serhiy Storchaka in branch 'default': |
Thank you all for reviews.
NAME_MAXLEN is private name available only in Modules/unicodedata.c. Making it public name would be other issue. I have increased buffer size to 256. |
New changeset b6fab008d63a by Berker Peksag in branch 'default': |
New changeset 21d1571c0533 by Serhiy Storchaka in branch 'default': |
Thank you Berker. |
../../source/Python/codecs.c:1022:16: error: use of undeclared identifier 'out'; did you |
Fixed in ce8a8531d29a |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: