aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/codecs.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Python/codecs.c b/Python/codecs.c
index 265f5214e5b..caf8d9d5f3c 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -540,11 +540,19 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
Py_DECREF(attr);
if (is_text_codec <= 0) {
Py_DECREF(codec);
- if (!is_text_codec)
- PyErr_Format(PyExc_LookupError,
- "'%.400s' is not a text encoding; "
- "use %s to handle arbitrary codecs",
- encoding, alternate_command);
+ if (!is_text_codec) {
+ if (alternate_command != NULL) {
+ PyErr_Format(PyExc_LookupError,
+ "'%.400s' is not a text encoding; "
+ "use %s to handle arbitrary codecs",
+ encoding, alternate_command);
+ }
+ else {
+ PyErr_Format(PyExc_LookupError,
+ "'%.400s' is not a text encoding",
+ encoding);
+ }
+ }
return NULL;
}
}