Skip to content

Commit e76296e

Browse files
committed
examples: fix get_selection encoding handling
1 parent 9d50f46 commit e76296e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

examples/get_selection.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# Suite 330,
2323
# Boston, MA 02111-1307 USA
2424

25+
import binascii
2526
import sys
2627
import os
2728

@@ -155,7 +156,13 @@ def output_data(d, r, target_name):
155156
len(r.value))
156157

157158
if r.format == 8:
158-
sys.stdout.write(r.value)
159+
if r.property_type == Xatom.STRING:
160+
value = r.value.decode('ISO-8859-1')
161+
elif r.property_type == d.get_atom('UTF8_STRING'):
162+
value = r.value.decode('UTF-8')
163+
else:
164+
value = binascii.hexlify(r.value).decode('ascii')
165+
sys.stdout.write(value)
159166

160167
elif r.format == 32 and r.property_type == Xatom.ATOM:
161168
for v in r.value:

0 commit comments

Comments
 (0)