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 alexandre.vassalotti
Recipients alexandre.vassalotti, christian.heimes, gvanrossum
Date 2007-10-14.16:17:39
SpamBayes Score 0.010119292
Marked as misclassified No
Message-id <1192378659.86.0.20481632454.issue1272@psf.upfronthosting.co.za>
In-reply-to
Content
I thought of another way to implement PyUnicode_DecodeFSDefault. If
Py_FileSystemDefaultEncoding is set, decode with the codecs module,
otherwise use UTF-8 + replace. This works because when
Py_FileSystemDefaultEncoding is initialized at the end of
Py_InitializeEx(), the codecs module is ready to be used. Here's what
it looks like:

PyObject*
PyUnicode_DecodeFSDefault(const char *s)
{
    Py_ssize_t size = (Py_ssize_t)strlen(s);

    /* During the early bootstrapping process, Py_FileSystemDefaultEncoding
       can be undefined. If it is case, decode using UTF-8. The
following assumes
       that Py_FileSystemDefaultEncoding is set to a built-in encoding
during the
       bootstrapping process where the codecs aren't ready yet.
    */
    if (Py_FileSystemDefaultEncoding) {
        return PyUnicode_Decode(s, size,
                                Py_FileSystemDefaultEncoding,
                                "replace");
    }
    else {
        return PyUnicode_DecodeUTF8(s, size, "replace");
    }
}

It is not perfect, since the extra function calls in the codecs module
causes test_profile and test_doctest to fail. However, I think this is
much simpler that the previous versions.
Files
File name Uploaded
updated_file_fsenc-5.patch alexandre.vassalotti, 2007-10-14.16:17:39
History
Date User Action Args
2007-10-14 16:17:39alexandre.vassalottisetspambayes_score: 0.0101193 -> 0.010119292
recipients: + alexandre.vassalotti, gvanrossum, christian.heimes
2007-10-14 16:17:39alexandre.vassalottisetspambayes_score: 0.0101193 -> 0.0101193
messageid: <1192378659.86.0.20481632454.issue1272@psf.upfronthosting.co.za>
2007-10-14 16:17:39alexandre.vassalottilinkissue1272 messages
2007-10-14 16:17:39alexandre.vassalotticreate