diff options
author | Harvey Falcic <harvey.falcic@gmail.com> | 2014-04-16 11:13:21 -0400 |
---|---|---|
committer | Harvey Falcic <harvey.falcic@gmail.com> | 2014-05-23 15:40:01 -0400 |
commit | 9846f3f1eac0835e9d1870f41ea0c03f3006a687 (patch) | |
tree | 2a73c79a5fd3abb297cd65fa87950d1cc174f037 /Lib/python | |
parent | d9cac664620d282aa423d3f0ef55ab9a677156a4 (diff) | |
download | swig-9846f3f1eac0835e9d1870f41ea0c03f3006a687.tar.gz |
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.
Diffstat (limited to 'Lib/python')
-rw-r--r-- | Lib/python/pystrings.swg | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/python/pystrings.swg b/Lib/python/pystrings.swg index f6a4eba8a..2b14547ad 100644 --- a/Lib/python/pystrings.swg +++ b/Lib/python/pystrings.swg @@ -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 |