Python 3 byte string output: use errors="surrogateescape"

... if available on the version of Python that's in use. This allows
obtaining the original byte string (and potentially trying a fallback
encoding) if the bytes can't be decoded as UTF-8.

Previously, a UnicodeDecodeError would be raised with no way to treat
the data as bytes or try another codec.
This commit is contained in:
Harvey Falcic 2014-04-16 11:13:21 -04:00
commit 9846f3f1ea

View file

@ -89,7 +89,11 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
SWIG_InternalNewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : SWIG_Py_Void();
} else {
%#if PY_VERSION_HEX >= 0x03000000
%#if PY_VERSION_HEX >= 0x03010000
return PyUnicode_DecodeUTF8(carray, %numeric_cast(size,int), "surrogateescape");
%#else
return PyUnicode_FromStringAndSize(carray, %numeric_cast(size,int));
%#endif
%#else
return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
%#endif