diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:48:01 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:48:04 +0900 |
commit | d80fc1d31f28c6bcf9ea34b253e8765321616c3c (patch) | |
tree | 53afc44a25c72df0a698294b6be95695dfa643ba /gi/_glib/pygiochannel.c | |
parent | 52620756e3ccf2925e140a254d340d3ba29f3ad5 (diff) | |
download | pygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.tar.gz pygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.tar.bz2 pygobject2-d80fc1d31f28c6bcf9ea34b253e8765321616c3c.zip |
Imported Upstream version 3.7.1
Change-Id: I4c5c3aae69e883da127f15b41c102f953e8cc74c
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'gi/_glib/pygiochannel.c')
-rw-r--r-- | gi/_glib/pygiochannel.c | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/gi/_glib/pygiochannel.c b/gi/_glib/pygiochannel.c index 722fd0d..0288145 100644 --- a/gi/_glib/pygiochannel.c +++ b/gi/_glib/pygiochannel.c @@ -191,7 +191,7 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs) return NULL; if (max_count == 0) - return PYGLIB_PyBytes_FromString(""); + return PYGLIB_PyUnicode_FromString(""); while (status == G_IO_STATUS_NORMAL && (max_count == -1 || total_read < max_count)) { @@ -234,6 +234,23 @@ py_io_channel_read_chars(PyGIOChannel* self, PyObject *args, PyObject *kwargs) goto failure; } +#if PY_VERSION_HEX >= 0x03000000 + /* If this is not UTF8 encoded channel return the raw bytes */ + if (g_io_channel_get_encoding(self->channel) != NULL) + return ret_obj; + + /* convert to Unicode string */ + { + PyObject *unicode_obj; + + unicode_obj = PyUnicode_FromString(PyBytes_AS_STRING(ret_obj)); + if (unicode_obj == NULL) + goto failure; + Py_DECREF(ret_obj); + ret_obj = unicode_obj; + } +#endif + return ret_obj; failure: @@ -281,11 +298,9 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs) while (1) { value = PyIter_Next(iter); - if (value == NULL) - break; if (PyErr_ExceptionMatches(PyExc_StopIteration)) { PyErr_Clear(); - break; + goto normal_exit; } if (!PYGLIB_PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "gi._glib.IOChannel.writelines must" @@ -303,7 +318,7 @@ py_io_channel_write_lines(PyGIOChannel* self, PyObject *args, PyObject *kwargs) return NULL; } } - +normal_exit: Py_DECREF(iter); Py_INCREF(Py_None); return Py_None; |