Author: guido.van.rossum
Date: Tue Nov  6 01:48:31 2007
New Revision: 58872

Modified:
   python/branches/py3k-pep3137/Objects/bytesobject.c
   python/branches/py3k-pep3137/Objects/stringobject.c
   python/branches/py3k-pep3137/Objects/unicodeobject.c
Log:
Remove some tests for whether PyCodec_Encode() returns a PyString() --
it guarantees this now (unless it returns NULL).


Modified: python/branches/py3k-pep3137/Objects/bytesobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/bytesobject.c  (original)
+++ python/branches/py3k-pep3137/Objects/bytesobject.c  Tue Nov  6 01:48:31 2007
@@ -724,13 +724,7 @@
         encoded = PyCodec_Encode(arg, encoding, errors);
         if (encoded == NULL)
             return -1;
-        if (!PyString_Check(encoded)) {
-            PyErr_Format(PyExc_TypeError,
-                "encoder did not return a bytes object (type=%.400s)",
-                Py_Type(encoded)->tp_name);
-            Py_DECREF(encoded);
-            return -1;
-        }
+        assert(PyString_Check(encoded));
         new = bytes_iconcat(self, encoded);
         Py_DECREF(encoded);
         if (new == NULL)

Modified: python/branches/py3k-pep3137/Objects/stringobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/stringobject.c (original)
+++ python/branches/py3k-pep3137/Objects/stringobject.c Tue Nov  6 01:48:31 2007
@@ -2908,25 +2908,7 @@
                new = PyCodec_Encode(x, encoding, errors);
                if (new == NULL)
                        return NULL;
-               /* XXX(gb): must accept bytes here since codecs output bytes
-                  at the moment */
-               if (PyBytes_Check(new)) {
-                       PyObject *str;
-                       str = PyString_FromStringAndSize(
-                               PyBytes_AS_STRING(new), Py_Size(new));
-                       Py_DECREF(new);
-                       if (!str)
-                               return NULL;
-                       return str;
-               }
-               if (!PyString_Check(new)) {
-                       PyErr_Format(PyExc_TypeError,
-                                    "encoder did not return a bytes "
-                                    "object (type=%.400s)",
-                                    Py_Type(new)->tp_name);
-                       Py_DECREF(new);
-                       return NULL;
-               }
+               assert(PyString_Check(new));
                return new;
        }
 
@@ -2979,6 +2961,8 @@
 
        /* For iterator version, create a string object and resize as needed */
        /* XXX(gb): is 64 a good value? also, optimize if length is known */
+       /* XXX(guido): perhaps use Pysequence_Fast() -- I can't imagine the
+          input being a truly long iterator. */
        size = 64;
        new = PyString_FromStringAndSize(NULL, size);
        if (new == NULL)
@@ -3037,7 +3021,7 @@
        return new;
 
   error:
-       /* Error handling when it != NULL */
+       /* Error handling when new != NULL */
        Py_XDECREF(it);
        Py_DECREF(new);
        return NULL;

Modified: python/branches/py3k-pep3137/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/unicodeobject.c        (original)
+++ python/branches/py3k-pep3137/Objects/unicodeobject.c        Tue Nov  6 
01:48:31 2007
@@ -1222,16 +1222,7 @@
     v = PyCodec_Encode(unicode, encoding, errors);
     if (v == NULL)
         goto onError;
-    if (!PyString_Check(v)) {
-        PyErr_Format(PyExc_TypeError,
-                     "encoder did not return a bytes object "
-                     "(type=%.400s, encoding=%.20s, errors=%.20s)",
-                     v->ob_type->tp_name,
-                     encoding ? encoding : "NULL",
-                     errors ? errors : "NULL");
-        Py_DECREF(v);
-        goto onError;
-    }
+    assert(PyString_Check(v));
     return v;
 
  onError:
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to