X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f74ff5efa5604fcde3cc5ba9009cb015a6f388cf..a2615ebc22a402b1badb46475f94ab6aa3a64018:/wxPython/src/msw/streams.cpp diff --git a/wxPython/src/msw/streams.cpp b/wxPython/src/msw/streams.cpp index e06a968f1f..c5a839d41d 100644 --- a/wxPython/src/msw/streams.cpp +++ b/wxPython/src/msw/streams.cpp @@ -56,6 +56,7 @@ extern PyObject *SWIG_newvarlink(void); #define SWIG_name "streamsc" #include "helpers.h" +#include "pyistream.h" #include #include @@ -85,12 +86,6 @@ static PyObject* t_output_helper(PyObject* target, PyObject* o) { } return target; } - -#if PYTHON_API_VERSION >= 1009 - static char* wxStringErrorMsg = "String or Unicode type required"; -#else - static char* wxStringErrorMsg = "String type required"; -#endif #ifdef __cplusplus extern "C" { #endif @@ -118,7 +113,7 @@ static PyObject *_wrap_new_wxInputStream(PyObject *self, PyObject *args, PyObjec } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (wxPyInputStream *)new_wxPyInputStream(_arg0); + _result = (wxPyInputStream *)new_wxPyInputStream(_arg0); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -151,7 +146,7 @@ static PyObject *_wrap_wxInputStream_close(PyObject *self, PyObject *args, PyObj } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - wxInputStream_close(_arg0); + wxInputStream_close(_arg0); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -179,7 +174,7 @@ static PyObject *_wrap_wxInputStream_flush(PyObject *self, PyObject *args, PyObj } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - wxInputStream_flush(_arg0); + wxInputStream_flush(_arg0); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -208,7 +203,7 @@ static PyObject *_wrap_wxInputStream_eof(PyObject *self, PyObject *args, PyObjec } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (bool )wxInputStream_eof(_arg0); + _result = (bool )wxInputStream_eof(_arg0); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -219,7 +214,7 @@ static PyObject *_wrap_wxInputStream_eof(PyObject *self, PyObject *args, PyObjec #define wxInputStream_read(_swigobj,_swigarg0) (_swigobj->read(_swigarg0)) static PyObject *_wrap_wxInputStream_read(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + PyObject * _result; wxPyInputStream * _arg0; int _arg1 = (int ) -1; PyObject * _argo0 = 0; @@ -237,12 +232,12 @@ static PyObject *_wrap_wxInputStream_read(PyObject *self, PyObject *args, PyObje } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (wxString *)wxInputStream_read(_arg0,_arg1); + _result = (PyObject *)wxInputStream_read(_arg0,_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; }{ - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); + _resultobj = _result; } return _resultobj; } @@ -250,7 +245,7 @@ static PyObject *_wrap_wxInputStream_read(PyObject *self, PyObject *args, PyObje #define wxInputStream_readline(_swigobj,_swigarg0) (_swigobj->readline(_swigarg0)) static PyObject *_wrap_wxInputStream_readline(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + PyObject * _result; wxPyInputStream * _arg0; int _arg1 = (int ) -1; PyObject * _argo0 = 0; @@ -268,12 +263,12 @@ static PyObject *_wrap_wxInputStream_readline(PyObject *self, PyObject *args, Py } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (wxString *)wxInputStream_readline(_arg0,_arg1); + _result = (PyObject *)wxInputStream_readline(_arg0,_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; }{ - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); + _resultobj = _result; } return _resultobj; } @@ -281,7 +276,7 @@ static PyObject *_wrap_wxInputStream_readline(PyObject *self, PyObject *args, Py #define wxInputStream_readlines(_swigobj,_swigarg0) (_swigobj->readlines(_swigarg0)) static PyObject *_wrap_wxInputStream_readlines(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxStringPtrList * _result; + PyObject * _result; wxPyInputStream * _arg0; int _arg1 = (int ) -1; PyObject * _argo0 = 0; @@ -299,24 +294,12 @@ static PyObject *_wrap_wxInputStream_readlines(PyObject *self, PyObject *args, P } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (wxStringPtrList *)wxInputStream_readlines(_arg0,_arg1); + _result = (PyObject *)wxInputStream_readlines(_arg0,_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; }{ - if (_result) { - _resultobj = PyList_New(_result->GetCount()); - wxStringPtrList::Node *node = _result->GetFirst(); - for (int i=0; node; i++) { - wxString *s = node->GetData(); - PyList_SetItem(_resultobj, i, PyString_FromStringAndSize(s->c_str(), s->Len())); - node = node->GetNext(); - delete s; - } - delete _result; - } - else - _resultobj=0; + _resultobj = _result; } return _resultobj; } @@ -342,7 +325,7 @@ static PyObject *_wrap_wxInputStream_seek(PyObject *self, PyObject *args, PyObje } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - wxInputStream_seek(_arg0,_arg1,_arg2); + wxInputStream_seek(_arg0,_arg1,_arg2); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -371,7 +354,7 @@ static PyObject *_wrap_wxInputStream_tell(PyObject *self, PyObject *args, PyObje } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = (int )wxInputStream_tell(_arg0); + _result = (int )wxInputStream_tell(_arg0); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; @@ -379,16 +362,24 @@ static PyObject *_wrap_wxInputStream_tell(PyObject *self, PyObject *args, PyObje return _resultobj; } -static void wxOutputStream_write(wxOutputStream *self,const wxString & str) { - self->Write(str.c_str(), str.Length()); +static void wxOutputStream_write(wxOutputStream *self,PyObject * obj) { + // We use only strings for the streams, not unicode + PyObject* str = PyObject_Str(obj); + if (! str) { + PyErr_SetString(PyExc_TypeError, "Unable to convert to string"); + return; + } + self->Write(PyString_AS_STRING(str), + PyString_GET_SIZE(str)); + Py_DECREF(str); } static PyObject *_wrap_wxOutputStream_write(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; wxOutputStream * _arg0; - wxString * _arg1; + PyObject * _arg1; PyObject * _argo0 = 0; PyObject * _obj1 = 0; - char *_kwnames[] = { "self","str", NULL }; + char *_kwnames[] = { "self","obj", NULL }; self = self; if(!PyArg_ParseTupleAndKeywords(args,kwargs,"OO:wxOutputStream_write",_kwnames,&_argo0,&_obj1)) @@ -401,35 +392,16 @@ static PyObject *_wrap_wxOutputStream_write(PyObject *self, PyObject *args, PyOb } } { -#if PYTHON_API_VERSION >= 1009 - char* tmpPtr; int tmpSize; - if (!PyString_Check(_obj1) && !PyUnicode_Check(_obj1)) { - PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); - return NULL; - } - if (PyString_AsStringAndSize(_obj1, &tmpPtr, &tmpSize) == -1) - return NULL; - _arg1 = new wxString(tmpPtr, tmpSize); -#else - if (!PyString_Check(_obj1)) { - PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); - return NULL; - } - _arg1 = new wxString(PyString_AS_STRING(_obj1), PyString_GET_SIZE(_obj1)); -#endif + _arg1 = _obj1; } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - wxOutputStream_write(_arg0,*_arg1); + wxOutputStream_write(_arg0,_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; } Py_INCREF(Py_None); _resultobj = Py_None; -{ - if (_obj1) - delete _arg1; -} return _resultobj; }