[Python-3000-checkins] r58770 - python/branches/py3k-pep3137/Python/codecs.c

guido.van.rossum python-3000-checkins at python.org
Fri Nov 2 15:04:00 CET 2007


Author: guido.van.rossum
Date: Fri Nov  2 15:03:59 2007
New Revision: 58770

Modified:
   python/branches/py3k-pep3137/Python/codecs.c
Log:
Add a warning when a codec returns PyBytes instead of PyString.


Modified: python/branches/py3k-pep3137/Python/codecs.c
==============================================================================
--- python/branches/py3k-pep3137/Python/codecs.c	(original)
+++ python/branches/py3k-pep3137/Python/codecs.c	Fri Nov  2 15:03:59 2007
@@ -334,7 +334,7 @@
     if (args == NULL)
 	goto onError;
 
-    result = PyEval_CallObject(encoder,args);
+    result = PyEval_CallObject(encoder, args);
     if (result == NULL)
 	goto onError;
 
@@ -345,8 +345,17 @@
 	goto onError;
     }
     v = PyTuple_GET_ITEM(result, 0);
-    if (PyBytes_Check(v))
+    if (PyBytes_Check(v)) {
+        char msg[100];
+        PyOS_snprintf(msg, sizeof(msg),
+                      "encoder %s returned buffer instead of bytes",
+                      encoding);
+        if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 1) < 0) {
+            v = NULL;
+            goto onError;
+        }
         v = PyString_FromStringAndSize(PyBytes_AS_STRING(v), Py_Size(v));
+    }
     else if (PyString_Check(v))
         Py_INCREF(v);
     else {


More information about the Python-3000-checkins mailing list