Removed blocks from several functions in unicodeobject and stringobject where a PyString function was still checking for PyUnicode or the other way around.
PyUnicode and PyString shouldn't magically convert the other type.
This commit is contained in:
parent
830a4bcfd4
commit
f386311fdb
|
@ -517,11 +517,6 @@ string_getbuffer(register PyObject *op)
|
||||||
Py_ssize_t
|
Py_ssize_t
|
||||||
PyString_Size(register PyObject *op)
|
PyString_Size(register PyObject *op)
|
||||||
{
|
{
|
||||||
if (PyUnicode_Check(op)) {
|
|
||||||
op = _PyUnicode_AsDefaultEncodedString(op, NULL);
|
|
||||||
if (!op)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(op))
|
if (!PyString_Check(op))
|
||||||
return string_getsize(op);
|
return string_getsize(op);
|
||||||
return Py_Size(op);
|
return Py_Size(op);
|
||||||
|
@ -530,11 +525,6 @@ PyString_Size(register PyObject *op)
|
||||||
/*const*/ char *
|
/*const*/ char *
|
||||||
PyString_AsString(register PyObject *op)
|
PyString_AsString(register PyObject *op)
|
||||||
{
|
{
|
||||||
if (PyUnicode_Check(op)) {
|
|
||||||
op = _PyUnicode_AsDefaultEncodedString(op, NULL);
|
|
||||||
if (!op)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!PyString_Check(op))
|
if (!PyString_Check(op))
|
||||||
return string_getbuffer(op);
|
return string_getbuffer(op);
|
||||||
return ((PyStringObject *)op) -> ob_sval;
|
return ((PyStringObject *)op) -> ob_sval;
|
||||||
|
@ -551,19 +541,10 @@ PyString_AsStringAndSize(register PyObject *obj,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyString_Check(obj)) {
|
if (!PyString_Check(obj)) {
|
||||||
if (PyUnicode_Check(obj)) {
|
|
||||||
obj = _PyUnicode_AsDefaultEncodedString(obj, NULL);
|
|
||||||
if (obj == NULL)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"expected string, "
|
"expected string, %.200s found", Py_Type(obj)->tp_name);
|
||||||
"%.200s found", Py_Type(obj)->tp_name);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
*s = PyString_AS_STRING(obj);
|
*s = PyString_AS_STRING(obj);
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
|
@ -1250,8 +1231,6 @@ string_partition(PyStringObject *self, PyObject *sep_obj)
|
||||||
sep = PyString_AS_STRING(sep_obj);
|
sep = PyString_AS_STRING(sep_obj);
|
||||||
sep_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1280,8 +1259,6 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj)
|
||||||
sep = PyString_AS_STRING(sep_obj);
|
sep = PyString_AS_STRING(sep_obj);
|
||||||
sep_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1585,9 +1562,6 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
|
||||||
sub = PyString_AS_STRING(subobj);
|
sub = PyString_AS_STRING(subobj);
|
||||||
sub_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
|
||||||
/* XXX - the "expected a character buffer object" is pretty
|
/* XXX - the "expected a character buffer object" is pretty
|
||||||
confusing for a non-expert. remap to something else ? */
|
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 = PyString_AS_STRING(sub_obj);
|
||||||
sub_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(sub_obj, &sub, &sub_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -1888,17 +1854,6 @@ string_translate(PyStringObject *self, PyObject *args)
|
||||||
table = NULL;
|
table = NULL;
|
||||||
tablen = 256;
|
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))
|
else if (PyObject_AsCharBuffer(tableobj, &table, &tablen))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -2594,9 +2549,6 @@ string_replace(PyStringObject *self, PyObject *args)
|
||||||
from_s = PyString_AS_STRING(from);
|
from_s = PyString_AS_STRING(from);
|
||||||
from_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(from, &from_s, &from_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -2604,9 +2556,6 @@ string_replace(PyStringObject *self, PyObject *args)
|
||||||
to_s = PyString_AS_STRING(to);
|
to_s = PyString_AS_STRING(to);
|
||||||
to_len = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(to, &to_s, &to_len))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -2634,9 +2583,6 @@ _string_tailmatch(PyStringObject *self, PyObject *substr, Py_ssize_t start,
|
||||||
sub = PyString_AS_STRING(substr);
|
sub = PyString_AS_STRING(substr);
|
||||||
slen = PyString_GET_SIZE(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))
|
else if (PyObject_AsCharBuffer(substr, &sub, &slen))
|
||||||
return -1;
|
return -1;
|
||||||
str = PyString_AS_STRING(self);
|
str = PyString_AS_STRING(self);
|
||||||
|
|
|
@ -1282,17 +1282,17 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
|
||||||
char*
|
char*
|
||||||
PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize)
|
PyUnicode_AsStringAndSize(PyObject *unicode, Py_ssize_t *psize)
|
||||||
{
|
{
|
||||||
PyObject *str8;
|
PyObject *bytes;
|
||||||
if (!PyUnicode_Check(unicode)) {
|
if (!PyUnicode_Check(unicode)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
str8 = _PyUnicode_AsDefaultEncodedString(unicode, NULL);
|
bytes = _PyUnicode_AsDefaultEncodedString(unicode, NULL);
|
||||||
if (str8 == NULL)
|
if (bytes == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (psize != NULL)
|
if (psize != NULL)
|
||||||
*psize = PyString_GET_SIZE(str8);
|
*psize = PyString_GET_SIZE(bytes);
|
||||||
return PyString_AS_STRING(str8);
|
return PyString_AS_STRING(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
|
@ -4331,7 +4331,7 @@ static PyObject *charmapencode_lookup(Py_UNICODE c, PyObject *mapping)
|
||||||
else {
|
else {
|
||||||
/* wrong return value */
|
/* wrong return value */
|
||||||
PyErr_Format(PyExc_TypeError,
|
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);
|
x->ob_type->tp_name);
|
||||||
Py_DECREF(x);
|
Py_DECREF(x);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -7160,15 +7160,6 @@ do_argstrip(PyUnicodeObject *self, int striptype, PyObject *args)
|
||||||
if (sep != NULL && sep != Py_None) {
|
if (sep != NULL && sep != Py_None) {
|
||||||
if (PyUnicode_Check(sep))
|
if (PyUnicode_Check(sep))
|
||||||
return _PyUnicode_XStrip(self, striptype, 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 {
|
else {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"%s arg must be None, unicode or str",
|
"%s arg must be None, unicode or str",
|
||||||
|
@ -8389,13 +8380,6 @@ formatchar(Py_UNICODE *buf,
|
||||||
goto onError;
|
goto onError;
|
||||||
buf[0] = PyUnicode_AS_UNICODE(v)[0];
|
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 {
|
else {
|
||||||
/* Integer input truncated to a character */
|
/* Integer input truncated to a character */
|
||||||
long x;
|
long x;
|
||||||
|
@ -8473,7 +8457,7 @@ PyObject *PyUnicode_Format(PyObject *format,
|
||||||
argidx = -2;
|
argidx = -2;
|
||||||
}
|
}
|
||||||
if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
|
if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
|
||||||
!PyString_Check(args) && !PyUnicode_Check(args))
|
!PyUnicode_Check(args))
|
||||||
dict = args;
|
dict = args;
|
||||||
|
|
||||||
while (--fmtcnt >= 0) {
|
while (--fmtcnt >= 0) {
|
||||||
|
@ -8679,17 +8663,6 @@ PyObject *PyUnicode_Format(PyObject *format,
|
||||||
goto onError;
|
goto onError;
|
||||||
if (PyUnicode_Check(temp))
|
if (PyUnicode_Check(temp))
|
||||||
/* nothing to do */;
|
/* 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 {
|
else {
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
|
Loading…
Reference in New Issue