Author prikryl
Recipients BreamoreBoy, amaury.forgeotdarc, belopolsky, eryksun, jcea, msmhrt, ocean-city, prikryl, vstinner
Date 2015-09-19.18:34:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1442687695.57.0.898543521385.issue16322@psf.upfronthosting.co.za>
In-reply-to
Content
I have worked around a bit differently -- the snippet from the code:

    result = time.tzname[0]    # simplified version of the original code.

    # Because of the bug in Windows libraries, Python 3.3 tried to work around
    # some issues. However, the shit hit the fan, and the bug bubbled here.
    # The `time.tzname` elements are (unicode) strings; however, they were
    # filled with bad content. See https://bugs.python.org/issue16322 for details.
    # Actually, wrong characters were passed instead of the good ones.
    # This code should be skipped later by versions of Python that will fix
    # the issue.
    import platform
    if platform.system() == 'Windows':
        # The concrete example for Czech locale:
        # - cp1250 (windows-1250) is used as native encoding
        # - the time.tzname[0] should start with 'Střední Evropa'
        # - the ascii('Střední Evropa') should return "'St\u0159edn\xed Evropa'"
        # - because of the bug it returns "'St\xf8edn\xed Evropa'"
        #
        # The 'ř' character has unicode code point `\u0159` (that is hex)
        # and the `\xF8` code in cp1250. The `\xF8` was wrongly used
        # as a Unicode code point `\u00F8` -- this is for the Unicode
        # character 'ø' that is observed in the string.
        #
        # To fix it, the `result` string must be reinterpreted with a different
        # encoding. When working with Python 3 strings, it can probably
        # done only through the string representation and `eval()`. Here
        # the `eval()` is not very dangerous because the string was obtained
        # from the OS library, and the values are limited to certain subset.
        #
        # The `ascii()` literal is prefixed by `binary` type prefix character,
        # `eval`uated, and the binary result is decoded to the correct string.
        local_encoding = locale.getdefaultlocale()[1]
        b = eval('b' + ascii(result))
        result = b.decode(local_encoding)
History
Date User Action Args
2015-09-19 18:34:55prikrylsetrecipients: + prikryl, jcea, amaury.forgeotdarc, belopolsky, vstinner, ocean-city, BreamoreBoy, eryksun, msmhrt
2015-09-19 18:34:55prikrylsetmessageid: <1442687695.57.0.898543521385.issue16322@psf.upfronthosting.co.za>
2015-09-19 18:34:55prikryllinkissue16322 messages
2015-09-19 18:34:55prikrylcreate