diff --git a/Objects/stringobject.c b/Objects/stringobject.c index d13599160a6..c33332ee22b 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -517,11 +517,6 @@ string_getbuffer(register PyObject *op) Py_ssize_t PyString_Size(register PyObject *op) { - if (PyUnicode_Check(op)) { - op = _PyUnicode_AsDefaultEncodedString(op, NULL); - if (!op) - return -1; - } if (!PyString_Check(op)) return string_getsize(op); return Py_Size(op); @@ -530,11 +525,6 @@ PyString_Size(register PyObject *op) /*const*/ char * PyString_AsString(register PyObject *op) { - if (PyUnicode_Check(op)) { - op = _PyUnicode_AsDefaultEncodedString(op, NULL); - if (!op) - return NULL; - } if (!PyString_Check(op)) return string_getbuffer(op); return ((PyStringObject *)op) -> ob_sval; @@ -551,18 +541,9 @@ PyString_AsStringAndSize(register PyObject *obj, } if (!PyString_Check(obj)) { - if (PyUnicode_Check(obj)) { - obj = _PyUnicode_AsDefaultEncodedString(obj, NULL); - if (obj == NULL) - return -1; - } - else - { - PyErr_Format(PyExc_TypeError, - "expected string, " - "%.200s found", Py_Type(obj)->tp_name); - return -1; - } + PyErr_Format(PyExc_TypeError, + "expected string, %.200s found", Py_Type(obj)->tp_name); + return -1; } *s = PyString_AS_STRING(obj); @@ -1250,8 +1231,6 @@ string_partition(PyStringObject *self, PyObject *sep_obj) sep = PyString_AS_STRING(sep_obj); sep_len = PyString_GET_SIZE(sep_obj); } - else if (PyUnicode_Check(sep_obj)) - return PyUnicode_Partition((PyObject *) self, sep_obj); else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len)) return NULL; @@ -1280,8 +1259,6 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj) sep = PyString_AS_STRING(sep_obj); sep_len = PyString_GET_SIZE(sep_obj); } - else if (PyUnicode_Check(sep_obj)) - return PyUnicode_Partition((PyObject *) self, sep_obj); else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len)) return NULL; @@ -1585,9 +1562,6 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir) sub = PyString_AS_STRING(subobj); sub_len = PyString_GET_SIZE(subobj); } - else if (PyUnicode_Check(subobj)) - return PyUnicode_Find( - (PyObject *)self, subobj, start, end, dir); else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len)) /* XXX - the "expected a character buffer object" is pretty confusing for a non-expert. remap to something else ? */ @@ -1836,14 +1810,6 @@ string_count(PyStringObject *self, PyObject *args) sub = PyString_AS_STRING(sub_obj); sub_len = PyString_GET_SIZE(sub_obj); } - else if (PyUnicode_Check(sub_obj)) { - Py_ssize_t count; - count = PyUnicode_Count((PyObject *)self, sub_obj, start, end); - if (count == -1) - return NULL; - else - return PyInt_FromSsize_t(count); - } else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len)) return NULL; @@ -1888,17 +1854,6 @@ string_translate(PyStringObject *self, PyObject *args) table = NULL; tablen = 256; } - else if (PyUnicode_Check(tableobj)) { - /* Unicode .translate() does not support the deletechars - parameter; instead a mapping to None will cause characters - to be deleted. */ - if (delobj != NULL) { - PyErr_SetString(PyExc_TypeError, - "deletions are implemented differently for unicode"); - return NULL; - } - return PyUnicode_Translate((PyObject *)self, tableobj, NULL); - } else if (PyObject_AsCharBuffer(tableobj, &table, &tablen)) return NULL; @@ -2594,9 +2549,6 @@ string_replace(PyStringObject *self, PyObject *args) from_s = PyString_AS_STRING(from); from_len = PyString_GET_SIZE(from); } - else if (PyUnicode_Check(from)) - return PyUnicode_Replace((PyObject *)self, - from, to, count); else if (PyObject_AsCharBuffer(from, &from_s, &from_len)) return NULL; @@ -2604,9 +2556,6 @@ string_replace(PyStringObject *self, PyObject *args) to_s = PyString_AS_STRING(to); to_len = PyString_GET_SIZE(to); } - else if (PyUnicode_Check(to)) - return PyUnicode_Replace((PyObject *)self, - from, to, count); else if (PyObject_AsCharBuffer(to, &to_s, &to_len)) return NULL; @@ -2634,9 +2583,6 @@ _string_tailmatch(PyStringObject *self, PyObject *substr, Py_ssize_t start, sub = PyString_AS_STRING(substr); slen = PyString_GET_SIZE(substr); } - else if (PyUnicode_Check(substr)) - return PyUnicode_Tailmatch((PyObject *)self, - substr, start, end, direction); else if (PyObject_AsCharBuffer(substr, &sub, &slen)) return -1; str = PyString_AS_STRING(self); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 30ab1bd57e0..c3511309d07 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1282,17 +1282,17 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size) char* PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize) { - PyObject *str8; + PyObject *bytes; if (!PyUnicode_Check(unicode)) { PyErr_BadArgument(); return NULL; } - str8 = _PyUnicode_AsDefaultEncodedString(unicode, NULL); - if (str8 == NULL) + bytes = _PyUnicode_AsDefaultEncodedString(unicode, NULL); + if (bytes == NULL) return NULL; if (psize != NULL) - *psize = PyString_GET_SIZE(str8); - return PyString_AS_STRING(str8); + *psize = PyString_GET_SIZE(bytes); + return PyString_AS_STRING(bytes); } char* @@ -1686,7 +1686,7 @@ PyObject *PyUnicode_EncodeUTF7(const Py_UNICODE *s, char * start; if (size == 0) - return PyString_FromStringAndSize(NULL, 0); + return PyString_FromStringAndSize(NULL, 0); v = PyBytes_FromStringAndSize(NULL, cbAllocated); if (v == NULL) @@ -2078,7 +2078,7 @@ encodeUCS4: result = PyString_FromStringAndSize(stackbuf, nneeded); } else { - /* Cut back to size actually needed. */ + /* Cut back to size actually needed. */ nneeded = p - PyString_AS_STRING(result); assert(nneeded <= nallocated); _PyString_Resize(&result, nneeded); @@ -4331,7 +4331,7 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping) else { /* wrong return value */ PyErr_Format(PyExc_TypeError, - "character mapping must return integer, None or str8, not %.400s", + "character mapping must return integer, bytes or None, not %.400s", x->ob_type->tp_name); Py_DECREF(x); return NULL; @@ -7160,15 +7160,6 @@ do_argstrip(PyUnicodeObject *self, int striptype, PyObject *args) if (sep != NULL && sep != Py_None) { if (PyUnicode_Check(sep)) return _PyUnicode_XStrip(self, striptype, sep); - else if (PyString_Check(sep)) { - PyObject *res; - sep = PyUnicode_FromObject(sep); - if (sep==NULL) - return NULL; - res = _PyUnicode_XStrip(self, striptype, sep); - Py_DECREF(sep); - return res; - } else { PyErr_Format(PyExc_TypeError, "%s arg must be None, unicode or str", @@ -8389,13 +8380,6 @@ formatchar(Py_UNICODE *buf, goto onError; buf[0] = PyUnicode_AS_UNICODE(v)[0]; } - - else if (PyString_Check(v)) { - if (PyString_GET_SIZE(v) != 1) - goto onError; - buf[0] = (Py_UNICODE)PyString_AS_STRING(v)[0]; - } - else { /* Integer input truncated to a character */ long x; @@ -8473,7 +8457,7 @@ PyObject *PyUnicode_Format(PyObject *format, argidx = -2; } if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) && - !PyString_Check(args) && !PyUnicode_Check(args)) + !PyUnicode_Check(args)) dict = args; while (--fmtcnt >= 0) { @@ -8679,17 +8663,6 @@ PyObject *PyUnicode_Format(PyObject *format, goto onError; if (PyUnicode_Check(temp)) /* nothing to do */; - else if (PyString_Check(temp)) { - /* convert to string to Unicode */ - unicode = PyUnicode_Decode(PyString_AS_STRING(temp), - PyString_GET_SIZE(temp), - NULL, - "strict"); - Py_DECREF(temp); - temp = unicode; - if (temp == NULL) - goto onError; - } else { Py_DECREF(temp); PyErr_SetString(PyExc_TypeError,