[Python-checkins] r69677 - python/branches/io-c/Modules/_textio.c
benjamin.peterson
python-checkins at python.org
Mon Feb 16 17:31:04 CET 2009
Author: benjamin.peterson
Date: Mon Feb 16 17:31:03 2009
New Revision: 69677
Log:
reduce ImportError catching code duplication
I'm not sure this makes the code clearer with its new gotos, but
at least I added a big fat comment
Modified:
python/branches/io-c/Modules/_textio.c
Modified: python/branches/io-c/Modules/_textio.c
==============================================================================
--- python/branches/io-c/Modules/_textio.c (original)
+++ python/branches/io-c/Modules/_textio.c Mon Feb 16 17:31:03 2009
@@ -774,14 +774,8 @@
if (encoding == NULL && self->encoding == NULL) {
if (state->locale_module == NULL) {
state->locale_module = PyImport_ImportModule("locale");
- if (state->locale_module == NULL) {
- if (PyErr_ExceptionMatches(PyExc_ImportError)) {
- PyErr_Clear();
- self->encoding = PyUnicode_FromString("ascii");
- }
- else
- goto error;
- }
+ if (state->locale_module == NULL)
+ goto catch_ImportError;
else
goto use_locale;
}
@@ -790,6 +784,13 @@
self->encoding = PyObject_CallMethod(
state->locale_module, "getpreferredencoding", NULL);
if (self->encoding == NULL) {
+ catch_ImportError:
+ /*
+ Importing locale can raise a ImportError because of
+ _functools, and locale.getpreferredencoding can raise a
+ ImportError if _locale is not available. These will happen
+ during module building.
+ */
if (PyErr_ExceptionMatches(PyExc_ImportError)) {
PyErr_Clear();
self->encoding = PyUnicode_FromString("ascii");
More information about the Python-checkins
mailing list