+#if PY_VERSION_HEX < 0x03050000
+static char*
+Py_EncodeLocale(const wchar_t *arg, size_t *size)
+{
+ return _Py_wchar2char(arg, size);
+}
+static wchar_t*
+Py_DecodeLocale(const char *arg, size_t *size)
+{
+ return _Py_char2wchar(arg, size);
+}
+#endif
+
+/*
+ The following functions are used to hook the Python
+ interpreter output.
+*/
+
+static void ContainerPyStdOut_dealloc(ContainerPyStdOut *self)
+{
+ PyObject_Del(self);
+}
+
+static PyObject*
+ContainerPyStdOut_write(ContainerPyStdOut *self, PyObject *args)
+{
+ char *c;
+ if (!PyArg_ParseTuple(args, "s",&c))
+ return NULL;
+ if(self->_cb==NULL) {
+ if ( self->_iscerr )
+ std::cerr << c ;
+ else
+ std::cout << c ;
+ }
+ else {
+ self->_cb(self->_data,c);
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject*
+ContainerPyStdOut_flush(ContainerPyStdOut */*self*/, PyObject */*args*/)
+{
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyMethodDef ContainerPyStdOut_methods[] = {
+ {"write", (PyCFunction)ContainerPyStdOut_write, METH_VARARGS, PyDoc_STR("write(string) -> None")},
+ {"flush", (PyCFunction)ContainerPyStdOut_flush, METH_NOARGS, PyDoc_STR("flush() -> None")},
+ {0, 0, 0, 0} /* sentinel */
+};
+
+static PyMemberDef ContainerPyStdOut_memberlist[] = {
+ {(char*)"softspace", T_INT, offsetof(ContainerPyStdOut, softspace), 0, (char*)"flag indicating that a space needs to be printed; used by print"},
+ {0, 0, 0, 0, 0} /* sentinel */
+};