Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 641d5cc

Browse files
committed
Short-cut lookup of utf-8 codec, to make import work
on OSX.
1 parent 9b9905b commit 641d5cc

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Python/codecs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,23 @@ PyObject *PyCodec_Encode(PyObject *object,
319319
PyObject *args = NULL, *result = NULL;
320320
PyObject *v;
321321

322+
/* XXX short-cut a few common file system
323+
encodings for now, as otherwise the import
324+
code can't load the codec registry. */
325+
if (strcmp(encoding, "utf-8") == 0 && PyUnicode_Check(object)) {
326+
return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(object),
327+
PyUnicode_GET_SIZE(object),
328+
errors);
329+
}
330+
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
331+
if (strcmp(encoding, "mbcs") == 0 && PyUnicode_Check(object)) {
332+
return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(object),
333+
PyUnicode_GET_SIZE(object),
334+
errors);
335+
}
336+
#endif
337+
338+
322339
encoder = PyCodec_Encoder(encoding);
323340
if (encoder == NULL)
324341
goto onError;

0 commit comments

Comments
 (0)