]> git.saurik.com Git - wxWidgets.git/commitdiff
Tweak unicode --> string conversion helper so UnicodeDecodeError is
authorRobin Dunn <robin@alldunn.com>
Fri, 15 Oct 2004 19:28:34 +0000 (19:28 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 15 Oct 2004 19:28:34 +0000 (19:28 +0000)
raised when appropriate instead ofg just catching everything and
raising TypeError

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/src/helpers.cpp

index 0c46c50b7dd28f42d01ea49f9f5eee9e9af714b2..aa4ebd29864702e08df15e85f579d13b4ae5f9f9 100644 (file)
@@ -1911,12 +1911,18 @@ wxString* wxString_in_helper(PyObject* source) {
     if (PyString_Check(source))
         Py_DECREF(uni);
 #else
-    char* tmpPtr; int tmpSize;
-    if (PyString_AsStringAndSize(source, &tmpPtr, &tmpSize) == -1) {
-        PyErr_SetString(PyExc_TypeError, "Unable to convert string");
-        return NULL;
+    // Convert to a string object if it isn't already, then to wxString
+    PyObject* str = source;
+    if (!PyString_Check(source)) {
+        str = PyObject_Str(source);
+        if (PyErr_Occurred()) return NULL;
     }
+    char* tmpPtr; int tmpSize;
+    PyString_AsStringAndSize(str, &tmpPtr, &tmpSize);
     target = new wxString(tmpPtr, tmpSize);
+    
+    if (!PyString_Check(source))
+        Py_DECREF(str);
 #endif // wxUSE_UNICODE
     
     return target;