Mercurial > cpython-lru_cache-weakref
comparison Python/codecs.c @ 42025:36b8d74deb9e
Short-cut lookup of utf-8 codec, to make import work
on OSX.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Mon, 11 Jun 2007 04:19:13 +0000 |
| parents | 089f449a20cd |
| children | 3473a685e5e7 |
comparison
equal
deleted
inserted
replaced
| 42019:f5b65731bd6c | 42025:36b8d74deb9e |
|---|---|
| 316 const char *errors) | 316 const char *errors) |
| 317 { | 317 { |
| 318 PyObject *encoder = NULL; | 318 PyObject *encoder = NULL; |
| 319 PyObject *args = NULL, *result = NULL; | 319 PyObject *args = NULL, *result = NULL; |
| 320 PyObject *v; | 320 PyObject *v; |
| 321 | |
| 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 | |
| 321 | 338 |
| 322 encoder = PyCodec_Encoder(encoding); | 339 encoder = PyCodec_Encoder(encoding); |
| 323 if (encoder == NULL) | 340 if (encoder == NULL) |
| 324 goto onError; | 341 goto onError; |
| 325 | 342 |
