This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients ezio.melotti, josh.r, pitrou, python-dev, serhiy.storchaka, vstinner
Date 2014-04-05.12:49:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAMpsgwZ26uPrE=cu5hdiex8FJ1xECvD+rtj3x2FaPuLov=ARmg@mail.gmail.com>
In-reply-to <3g1HMh5J2nz7Ljp@mail.python.org>
Content
Serhiy wrote:
> fast_translate.patch works only with ASCII input string and ASCII 1:1 mapping. Is this actually typical case?

I just checked the Python stdlib: as expected, all usages of
str.translate() except of email.quoprimime use ASCII 1:1. My
optimization is only used if the input string is ASCII, but I expect
that most strings are just ASCI.

** distutils: ASCII => ASCII (1:1)

   longopt_xlate = str.maketrans('-', '_')
and
   WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace};
.. text = text.translate(WS_TRANS)

** email.quoprimes:

    encoded = header_bytes.decode('latin1').translate(_QUOPRI_HEADER_MAP)
and
    body = body.translate(_QUOPRI_BODY_ENCODE_MAP)

=> my optimization is used if the input string contains "safe header
characters" (a-z, A-Z, 0-9, space and "-!*+/"). It should be the
common case for emails.

** rot13 encoding: ASCII 1:1

** idlelib.PyParse: ASCII 1:1

        str = str.translate(_tran)

** textwrap: ASCII 1:1

            text = text.translate(self.unicode_whitespace_trans)

** zipfile: ASCII 1:1

        arcname = arcname.translate(table)
History
Date User Action Args
2014-04-05 12:49:22vstinnersetrecipients: + vstinner, pitrou, ezio.melotti, python-dev, serhiy.storchaka, josh.r
2014-04-05 12:49:22vstinnerlinkissue21118 messages
2014-04-05 12:49:21vstinnercreate