blob: b2f47dc9f1f51af36f8d405947064896d20ffefd [file] [log] [blame]
Nobuaki Sukegawa760511f2015-11-06 21:24:16 +09001import sys
2
3if sys.version_info[0] == 2:
4
5 from cStringIO import StringIO as BufferIO
6
7 def binary_to_str(bin_val):
8 return bin_val
9
10 def str_to_binary(str_val):
11 return str_val
12
13else:
14
15 from io import BytesIO as BufferIO
16
17 def binary_to_str(bin_val):
18 try:
19 return bin_val.decode('utf8')
20 except:
21 return bin_val
22
23 def str_to_binary(str_val):
24 try:
25 return bytearray(str_val, 'utf8')
26 except:
27 return str_val