THRIFT-1857 Python 3 Support
Client: Python
Patch: Thomas Bartelmess, Eevee (Alex Munroe), helgridly, Christian Verkerk, Jeroen Vlek, Nobuaki Sukegawa
This closes #213 and closes #680
diff --git a/lib/py/src/compat.py b/lib/py/src/compat.py
new file mode 100644
index 0000000..b2f47dc
--- /dev/null
+++ b/lib/py/src/compat.py
@@ -0,0 +1,27 @@
+import sys
+
+if sys.version_info[0] == 2:
+
+ from cStringIO import StringIO as BufferIO
+
+ def binary_to_str(bin_val):
+ return bin_val
+
+ def str_to_binary(str_val):
+ return str_val
+
+else:
+
+ from io import BytesIO as BufferIO
+
+ def binary_to_str(bin_val):
+ try:
+ return bin_val.decode('utf8')
+ except:
+ return bin_val
+
+ def str_to_binary(str_val):
+ try:
+ return bytearray(str_val, 'utf8')
+ except:
+ return str_val