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:
parent
d9cac66462
commit
9846f3f1ea
1 changed files with 4 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue