summaryrefslogtreecommitdiff
path: root/Lib/python
diff options
context:
space:
mode:
authorHarvey Falcic <harvey.falcic@gmail.com>2014-04-16 11:13:21 -0400
committerHarvey Falcic <harvey.falcic@gmail.com>2014-05-23 15:40:01 -0400
commit9846f3f1eac0835e9d1870f41ea0c03f3006a687 (patch)
tree2a73c79a5fd3abb297cd65fa87950d1cc174f037 /Lib/python
parentd9cac664620d282aa423d3f0ef55ab9a677156a4 (diff)
downloadswig-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.swg4
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