[Python-3000-checkins] r57496 - in python/branches/py3k: Lib/binhex.py Modules/cjkcodecs/cjkcodecs.h Modules/cjkcodecs/multibytecodec.c Objects/abstract.c Objects/floatobject.c Objects/object.c Objects/typeobject.c Python/bltinmodule.c
neal.norwitz
python-3000-checkins at python.org
Sun Aug 26 06:19:43 CEST 2007
Author: neal.norwitz
Date: Sun Aug 26 06:19:43 2007
New Revision: 57496
Modified:
python/branches/py3k/Lib/binhex.py
python/branches/py3k/Modules/cjkcodecs/cjkcodecs.h
python/branches/py3k/Modules/cjkcodecs/multibytecodec.c
python/branches/py3k/Objects/abstract.c
python/branches/py3k/Objects/floatobject.c
python/branches/py3k/Objects/object.c
python/branches/py3k/Objects/typeobject.c
python/branches/py3k/Python/bltinmodule.c
Log:
Use unicode and remove support for some uses of str8.
Modified: python/branches/py3k/Lib/binhex.py
==============================================================================
--- python/branches/py3k/Lib/binhex.py (original)
+++ python/branches/py3k/Lib/binhex.py Sun Aug 26 06:19:43 2007
@@ -420,8 +420,8 @@
self.FName = fname
self.FInfo = FInfo()
- self.FInfo.Creator = str8(creator)
- self.FInfo.Type = str8(type)
+ self.FInfo.Creator = creator
+ self.FInfo.Type = type
self.FInfo.Flags = flags
self.state = _DID_HEADER
Modified: python/branches/py3k/Modules/cjkcodecs/cjkcodecs.h
==============================================================================
--- python/branches/py3k/Modules/cjkcodecs/cjkcodecs.h (original)
+++ python/branches/py3k/Modules/cjkcodecs/cjkcodecs.h Sun Aug 26 06:19:43 2007
@@ -261,22 +261,19 @@
const MultibyteCodec *codec;
const char *enc;
- if (PyUnicode_Check(encoding)) {
- encoding = _PyUnicode_AsDefaultEncodedString(encoding, NULL);
- if (encoding == NULL)
- return NULL;
- }
- if (!PyString_Check(encoding)) {
+ if (!PyUnicode_Check(encoding)) {
PyErr_SetString(PyExc_TypeError,
"encoding name must be a string.");
return NULL;
}
+ enc = PyUnicode_AsString(encoding, NULL);
+ if (enc == NULL)
+ return NULL;
cofunc = getmultibytecodec();
if (cofunc == NULL)
return NULL;
- enc = PyString_AS_STRING(encoding);
for (codec = codec_list; codec->encoding[0]; codec++)
if (strcmp(codec->encoding, enc) == 0)
break;
Modified: python/branches/py3k/Modules/cjkcodecs/multibytecodec.c
==============================================================================
--- python/branches/py3k/Modules/cjkcodecs/multibytecodec.c (original)
+++ python/branches/py3k/Modules/cjkcodecs/multibytecodec.c Sun Aug 26 06:19:43 2007
@@ -85,16 +85,20 @@
else if (strcmp(errors, "replace") == 0)
return ERROR_REPLACE;
else
- return PyString_FromString(errors);
+ return PyUnicode_FromString(errors);
}
static PyObject *
call_error_callback(PyObject *errors, PyObject *exc)
{
PyObject *args, *cb, *r;
+ const char *str;
- assert(PyString_Check(errors));
- cb = PyCodec_LookupError(PyString_AS_STRING(errors));
+ assert(PyUnicode_Check(errors));
+ str = PyUnicode_AsString(errors);
+ if (str == NULL)
+ return NULL;
+ cb = PyCodec_LookupError(str);
if (cb == NULL)
return NULL;
@@ -129,7 +133,7 @@
return self->errors;
}
- return PyString_FromString(errors);
+ return PyUnicode_FromString(errors);
}
static int
@@ -137,18 +141,18 @@
void *closure)
{
PyObject *cb;
+ const char *str;
- if (PyUnicode_Check(value)) {
- value = _PyUnicode_AsDefaultEncodedString(value, NULL);
- if (value == NULL)
- return -1;
- }
- if (!PyString_Check(value)) {
+ if (!PyUnicode_Check(value)) {
PyErr_SetString(PyExc_TypeError, "errors must be a string");
return -1;
}
- cb = internal_error_callback(PyString_AS_STRING(value));
+ str = PyUnicode_AsString(value);
+ if (str == NULL)
+ return -1;
+
+ cb = internal_error_callback(str);
if (cb == NULL)
return -1;
Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c (original)
+++ python/branches/py3k/Objects/abstract.c Sun Aug 26 06:19:43 2007
@@ -1281,13 +1281,6 @@
}
if (PyLong_Check(o)) /* A long subclass without nb_long */
return _PyLong_Copy((PyLongObject *)o);
- if (PyString_Check(o))
- /* need to do extra error checking that PyLong_FromString()
- * doesn't do. In particular long('9.5') must raise an
- * exception, not truncate the float.
- */
- return long_from_string(PyString_AS_STRING(o),
- PyString_GET_SIZE(o));
if (PyUnicode_Check(o))
/* The above check is done in PyLong_FromUnicode(). */
return PyLong_FromUnicode(PyUnicode_AS_UNICODE(o),
Modified: python/branches/py3k/Objects/floatobject.c
==============================================================================
--- python/branches/py3k/Objects/floatobject.c (original)
+++ python/branches/py3k/Objects/floatobject.c Sun Aug 26 06:19:43 2007
@@ -74,11 +74,7 @@
Py_ssize_t len;
PyObject *result = NULL;
- if (PyString_Check(v)) {
- s = PyString_AS_STRING(v);
- len = PyString_GET_SIZE(v);
- }
- else if (PyUnicode_Check(v)) {
+ if (PyUnicode_Check(v)) {
s_buffer = (char *)PyMem_MALLOC(PyUnicode_GET_SIZE(v)+1);
if (s_buffer == NULL)
return PyErr_NoMemory();
@@ -843,7 +839,7 @@
return float_subtype_new(type, args, kwds); /* Wimp out */
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x))
return NULL;
- if (PyString_Check(x))
+ if (PyUnicode_Check(x))
return PyFloat_FromString(x);
return PyNumber_Float(x);
}
@@ -894,18 +890,15 @@
char* s;
float_format_type r;
- if (PyUnicode_Check(arg)) {
- arg = _PyUnicode_AsDefaultEncodedString(arg, NULL);
- if (arg == NULL)
- return NULL;
- }
- if (!PyString_Check(arg)) {
+ if (!PyUnicode_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"__getformat__() argument must be string, not %.500s",
Py_Type(arg)->tp_name);
return NULL;
}
- s = PyString_AS_STRING(arg);
+ s = PyUnicode_AsString(arg);
+ if (s == NULL)
+ return NULL;
if (strcmp(s, "double") == 0) {
r = double_format;
}
Modified: python/branches/py3k/Objects/object.c
==============================================================================
--- python/branches/py3k/Objects/object.c (original)
+++ python/branches/py3k/Objects/object.c Sun Aug 26 06:19:43 2007
@@ -357,7 +357,7 @@
PyObject *
PyObject_Repr(PyObject *v)
{
- PyObject *ress, *resu;
+ PyObject *res;
if (PyErr_CheckSignals())
return NULL;
#ifdef USE_STACKCHECK
@@ -371,21 +371,15 @@
else if (Py_Type(v)->tp_repr == NULL)
return PyUnicode_FromFormat("<%s object at %p>", v->ob_type->tp_name, v);
else {
- ress = (*v->ob_type->tp_repr)(v);
- if (!ress)
- return NULL;
- if (PyUnicode_Check(ress))
- return ress;
- if (!PyString_Check(ress)) {
+ res = (*v->ob_type->tp_repr)(v);
+ if (res != NULL && !PyUnicode_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__repr__ returned non-string (type %.200s)",
- ress->ob_type->tp_name);
- Py_DECREF(ress);
+ res->ob_type->tp_name);
+ Py_DECREF(res);
return NULL;
}
- resu = PyUnicode_FromObject(ress);
- Py_DECREF(ress);
- return resu;
+ return res;
}
}
@@ -413,7 +407,7 @@
{
PyObject *res;
if (v == NULL)
- return PyString_FromString("<NULL>");
+ return PyUnicode_FromString("<NULL>");
if (PyString_CheckExact(v)) {
Py_INCREF(v);
return v;
Modified: python/branches/py3k/Objects/typeobject.c
==============================================================================
--- python/branches/py3k/Objects/typeobject.c (original)
+++ python/branches/py3k/Objects/typeobject.c Sun Aug 26 06:19:43 2007
@@ -55,17 +55,15 @@
"can't delete %s.__name__", type->tp_name);
return -1;
}
- if (PyUnicode_Check(value)) {
- value = _PyUnicode_AsDefaultEncodedString(value, NULL);
- if (value == NULL)
- return -1;
- }
- if (!PyString_Check(value)) {
+ if (!PyUnicode_Check(value)) {
PyErr_Format(PyExc_TypeError,
"can only assign string to %s.__name__, not '%s'",
type->tp_name, Py_Type(value)->tp_name);
return -1;
}
+ value = _PyUnicode_AsDefaultEncodedString(value, NULL);
+ if (value == NULL)
+ return -1;
if (strlen(PyString_AS_STRING(value))
!= (size_t)PyString_GET_SIZE(value)) {
PyErr_Format(PyExc_ValueError,
@@ -1918,30 +1916,22 @@
*/
{
PyObject *doc = PyDict_GetItemString(dict, "__doc__");
- if (doc != NULL) {
- char *tp_doc;
- const char *str = NULL;
+ if (doc != NULL && PyUnicode_Check(doc)) {
size_t n;
- if (PyString_Check(doc)) {
- str = PyString_AS_STRING(doc);
- n = (size_t)PyString_GET_SIZE(doc);
- } else if (PyUnicode_Check(doc)) {
- str = PyUnicode_AsString(doc);
- if (str == NULL) {
- Py_DECREF(type);
- return NULL;
- }
- n = strlen(str);
+ char *tp_doc;
+ const char *str = PyUnicode_AsString(doc);
+ if (str == NULL) {
+ Py_DECREF(type);
+ return NULL;
}
- if (str != NULL) {
- tp_doc = (char *)PyObject_MALLOC(n+1);
- if (tp_doc == NULL) {
- Py_DECREF(type);
- return NULL;
- }
- memcpy(tp_doc, str, n+1);
- type->tp_doc = tp_doc;
+ n = strlen(str);
+ tp_doc = (char *)PyObject_MALLOC(n+1);
+ if (tp_doc == NULL) {
+ Py_DECREF(type);
+ return NULL;
}
+ memcpy(tp_doc, str, n+1);
+ type->tp_doc = tp_doc;
}
}
Modified: python/branches/py3k/Python/bltinmodule.c
==============================================================================
--- python/branches/py3k/Python/bltinmodule.c (original)
+++ python/branches/py3k/Python/bltinmodule.c Sun Aug 26 06:19:43 2007
@@ -40,7 +40,7 @@
}
func = PyTuple_GET_ITEM(args, 0); /* Better be callable */
name = PyTuple_GET_ITEM(args, 1);
- if ((!PyString_Check(name) && !PyUnicode_Check(name))) {
+ if (!PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"__build_class__: name is not a string");
return NULL;
@@ -631,8 +631,7 @@
}
else if (locals == Py_None)
locals = globals;
- if (!PyString_Check(prog) &&
- !PyUnicode_Check(prog) &&
+ if (!PyUnicode_Check(prog) &&
!PyCode_Check(prog)) {
PyErr_Format(PyExc_TypeError,
"exec() arg 1 must be a string, file, or code "
@@ -695,23 +694,15 @@
static PyObject *
builtin_getattr(PyObject *self, PyObject *args)
{
- PyObject *v, *result, *dflt = NULL, *release = NULL;
+ PyObject *v, *result, *dflt = NULL;
PyObject *name;
if (!PyArg_UnpackTuple(args, "getattr", 2, 3, &v, &name, &dflt))
return NULL;
- if (PyString_Check(name)) {
- release = PyString_AsDecodedObject(name, NULL, NULL);
- if (!release)
- return NULL;
- name = release;
- }
-
if (!PyUnicode_Check(name)) {
PyErr_SetString(PyExc_TypeError,
"getattr(): attribute name must be string");
- Py_XDECREF(release);
return NULL;
}
result = PyObject_GetAttr(v, name);
@@ -722,7 +713,6 @@
Py_INCREF(dflt);
result = dflt;
}
- Py_XDECREF(release);
return result;
}
@@ -1221,17 +1211,15 @@
if (file == NULL || file == Py_None)
file = PySys_GetObject("stdout");
- if (sep && sep != Py_None && !PyString_Check(sep) &&
- !PyUnicode_Check(sep)) {
+ if (sep && sep != Py_None && !PyUnicode_Check(sep)) {
PyErr_Format(PyExc_TypeError,
- "sep must be None, str or unicode, not %.200s",
+ "sep must be None or a string, not %.200s",
sep->ob_type->tp_name);
return NULL;
}
- if (end && end != Py_None && !PyString_Check(end) &&
- !PyUnicode_Check(end)) {
+ if (end && end != Py_None && !PyUnicode_Check(end)) {
PyErr_Format(PyExc_TypeError,
- "end must be None, str or unicode, not %.200s",
+ "end must be None or a string, not %.200s",
end->ob_type->tp_name);
return NULL;
}
@@ -1383,7 +1371,7 @@
result = NULL;
}
else {
- result = PyString_FromStringAndSize(s, len-1);
+ result = PyUnicode_FromStringAndSize(s, len-1);
}
}
PyMem_FREE(s);
More information about the Python-3000-checkins
mailing list