From 61d3a2e253b9581ab1764d36a57e042540c38dcb Mon Sep 17 00:00:00 2001 From: Roman Miroshnychenko Date: Mon, 19 Oct 2020 11:36:32 +0300 Subject: Accept Python bytes type into a buffer --- xbmc/interfaces/python/typemaps/python.buffer.intm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xbmc/interfaces/python/typemaps/python.buffer.intm b/xbmc/interfaces/python/typemaps/python.buffer.intm index 57f350d81f..f074b2bad2 100644 --- a/xbmc/interfaces/python/typemaps/python.buffer.intm +++ b/xbmc/interfaces/python/typemaps/python.buffer.intm @@ -16,6 +16,15 @@ ${api}.put(str, size); ${api}.flip(); // prepare the buffer for reading from } + else if (PyBytes_Check(${slarg})) + { + Py_ssize_t pysize = PyBytes_GET_SIZE(${slarg}); + const char* str = PyBytes_AS_STRING(${slarg}); + size_t size = static_cast(pysize); + ${api}.allocate(size); + ${api}.put(str, size); + ${api}.flip(); // prepare the buffer for reading from + } else if (PyByteArray_Check(${slarg})) { size_t size = PyByteArray_Size(${slarg}); @@ -24,4 +33,4 @@ ${api}.flip(); // prepare the buffer for reading from } else - throw XBMCAddon::WrongTypeException("argument \"%s\" for \"%s\" must be a string or a bytearray", "${api}", "${method.@name}"); \ No newline at end of file + throw XBMCAddon::WrongTypeException("argument \"%s\" for \"%s\" must be a string, bytes or a bytearray", "${api}", "${method.@name}"); \ No newline at end of file -- cgit v1.2.3