classification
Title: unicode.translate() doesn't error out on invalid translation table
Type: behavior Stage:
Components: Unicode Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: lemburg Nosy List: georg.brandl, lemburg, loewis
Priority: normal Keywords: patch

Created on 2007-08-31 10:30 by georg.brandl, last changed 2007-10-23 06:53 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
uni_xlate.diff georg.brandl, 2007-09-01 15:32
uni_xlate2.diff georg.brandl, 2007-09-03 07:44
Messages (7)
msg55530 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-31 10:30
While it's documented that unicode.translate()s table maps ordinals to
strings/ordinals/None, if you give a unicode key in the table it will
just be ignored. This is quite surprising.
msg55560 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-01 15:32
Here's a patch that should make unicode.translate() more robust, and
also allows unicode characters to be passed in the mapping.
msg55568 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2007-09-02 01:11
Nice idea, but why don't you use a dictionary iterator (PyDict_Next())
for the fixup ?
msg55576 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-02 07:08
Marc-Andre Lemburg schrieb:
> Marc-Andre Lemburg added the comment:
> 
> Nice idea, but why don't you use a dictionary iterator (PyDict_Next())
> for the fixup ?

I thought that is unsafe to use when the dictionary is mutated while
iterating.
msg55581 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2007-09-02 10:15
Ah, I hadn't noticed that you're actually manipulating the input
dictionary. You should create a copy and fix that instead of changing
the dict that the user passed in to the function.

You can then use PyDict_Next() for fast iteration over the original
dictionary.
msg55613 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-09-03 07:44
Yes, that makes sense.
New patch attached, copying the dict and using PyDict_Next.
msg56673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-10-23 06:53
Committed to Py3k as r58603.
History
Date User Action Args
2007-10-23 06:53:21georg.brandlsetstatus: open -> closed
resolution: accepted
messages: + msg56673
2007-09-03 07:44:06georg.brandlsetfiles: + uni_xlate2.diff
messages: + msg55613
2007-09-02 20:11:39loewissetkeywords: + patch
2007-09-02 10:15:54lemburgsetmessages: + msg55581
2007-09-02 07:08:36georg.brandlsetmessages: + msg55576
2007-09-02 01:11:01lemburgsetmessages: + msg55568
2007-09-01 15:32:24georg.brandlsetfiles: + uni_xlate.diff
messages: + msg55560
2007-08-31 10:30:33georg.brandlcreate