[Python-3000-checkins] r56973 - python/branches/py3k/Modules/_tkinter.c
martin.v.loewis
python-3000-checkins at python.org
Mon Aug 13 08:01:44 CEST 2007
Author: martin.v.loewis
Date: Mon Aug 13 08:01:43 2007
New Revision: 56973
Modified:
python/branches/py3k/Modules/_tkinter.c
Log:
Create Unicode objects.
Modified: python/branches/py3k/Modules/_tkinter.c
==============================================================================
--- python/branches/py3k/Modules/_tkinter.c (original)
+++ python/branches/py3k/Modules/_tkinter.c Mon Aug 13 08:01:43 2007
@@ -460,13 +460,13 @@
* Could be a quoted string containing funnies, e.g. {"}.
* Return the string itself.
*/
- return PyString_FromString(list);
+ return PyUnicode_FromString(list);
}
if (argc == 0)
- v = PyString_FromString("");
+ v = PyUnicode_FromString("");
else if (argc == 1)
- v = PyString_FromString(argv[0]);
+ v = PyUnicode_FromString(argv[0]);
else if ((v = PyTuple_New(argc)) != NULL) {
int i;
PyObject *w;
@@ -756,22 +756,10 @@
PyTclObject_string(PyTclObject *self, void *ignored)
{
char *s;
- int i, len;
+ int len;
if (!self->string) {
s = Tcl_GetStringFromObj(self->value, &len);
- for (i = 0; i < len; i++)
- if (s[i] & 0x80)
- break;
- if (i == len)
- /* It is an ASCII string. */
- self->string = PyString_FromStringAndSize(s, len);
- else {
- self->string = PyUnicode_DecodeUTF8(s, len, "strict");
- if (!self->string) {
- PyErr_Clear();
- self->string = PyString_FromStringAndSize(s, len);
- }
- }
+ self->string = PyUnicode_FromStringAndSize(s, len);
if (!self->string)
return NULL;
}
@@ -816,7 +804,7 @@
static PyObject*
get_typename(PyTclObject* obj, void* ignored)
{
- return PyString_FromString(obj->value->typePtr->name);
+ return PyUnicode_FromString(obj->value->typePtr->name);
}
@@ -951,27 +939,8 @@
TkappObject *app = (TkappObject*)tkapp;
if (value->typePtr == NULL) {
- /* If the result contains any bytes with the top bit set,
- it's UTF-8 and we should decode it to Unicode */
- int i;
- char *s = value->bytes;
- int len = value->length;
- for (i = 0; i < len; i++) {
- if (value->bytes[i] & 0x80)
- break;
- }
-
- if (i == value->length)
- result = PyString_FromStringAndSize(s, len);
- else {
- /* Convert UTF-8 to Unicode string */
- result = PyUnicode_DecodeUTF8(s, len, "strict");
- if (result == NULL) {
- PyErr_Clear();
- result = PyString_FromStringAndSize(s, len);
- }
- }
- return result;
+ return PyUnicode_FromStringAndSize(value->bytes,
+ value->length);
}
if (value->typePtr == app->BooleanType) {
@@ -983,7 +952,7 @@
if (value->typePtr == app->ByteArrayType) {
int size;
char *data = (char*)Tcl_GetByteArrayFromObj(value, &size);
- return PyString_FromStringAndSize(data, size);
+ return PyBytes_FromStringAndSize(data, size);
}
if (value->typePtr == app->DoubleType) {
@@ -1147,25 +1116,7 @@
const char *s = Tcl_GetStringResult(self->interp);
const char *p = s;
- /* If the result contains any bytes with the top bit set,
- it's UTF-8 and we should decode it to Unicode */
- while (*p != '\0') {
- if (*p & 0x80)
- break;
- p++;
- }
-
- if (*p == '\0')
- res = PyString_FromStringAndSize(s, (int)(p-s));
- else {
- /* Convert UTF-8 to Unicode string */
- p = strchr(p, '\0');
- res = PyUnicode_DecodeUTF8(s, (int)(p-s), "strict");
- if (res == NULL) {
- PyErr_Clear();
- res = PyString_FromStringAndSize(s, (int)(p-s));
- }
- }
+ res = PyUnicode_FromStringAndSize(s, (int)(p-s));
}
return res;
}
@@ -1318,7 +1269,7 @@
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyUnicode_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
ckfree(cmd);
}
@@ -1344,7 +1295,7 @@
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyUnicode_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1367,7 +1318,7 @@
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyUnicode_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1391,7 +1342,7 @@
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyUnicode_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1414,7 +1365,7 @@
if (err == TCL_ERROR)
res = Tkinter_Error(self);
else
- res = PyString_FromString(Tkapp_Result(self));
+ res = PyUnicode_FromString(Tkapp_Result(self));
LEAVE_OVERLAP_TCL
return res;
}
@@ -1628,7 +1579,7 @@
res = FromObj(self, tres);
}
else {
- res = PyString_FromString(Tcl_GetString(tres));
+ res = PyUnicode_FromString(Tcl_GetString(tres));
}
}
LEAVE_OVERLAP_TCL
@@ -1872,7 +1823,7 @@
goto finally;
for (i = 0; i < argc; i++) {
- PyObject *s = PyString_FromString(argv[i]);
+ PyObject *s = PyUnicode_FromString(argv[i]);
if (!s || PyTuple_SetItem(v, i, s)) {
Py_DECREF(v);
v = NULL;
@@ -1913,7 +1864,7 @@
PyObject *res = NULL;
if (s) {
- res = PyString_FromString(s);
+ res = PyUnicode_FromString(s);
ckfree(s);
}
@@ -1963,7 +1914,7 @@
return PythonCmd_Error(interp);
for (i = 0; i < (argc - 1); i++) {
- PyObject *s = PyString_FromString(argv[i + 1]);
+ PyObject *s = PyUnicode_FromString(argv[i + 1]);
if (!s || PyTuple_SetItem(arg, i, s)) {
Py_DECREF(arg);
return PythonCmd_Error(interp);
@@ -3039,7 +2990,7 @@
static void
ins_string(PyObject *d, char *name, char *val)
{
- PyObject *v = PyString_FromString(val);
+ PyObject *v = PyUnicode_FromString(val);
if (v) {
PyDict_SetItemString(d, name, v);
Py_DECREF(v);
More information about the Python-3000-checkins
mailing list