[bindings] Make sample Python 2/3 compatible
diff --git a/src/sample.py b/src/sample.py
index e2daba8..5a76f91 100755
--- a/src/sample.py
+++ b/src/sample.py
@@ -5,6 +5,19 @@
 import sys
 from gi.repository import HarfBuzz as hb
 
+# Python 2/3 compatibility
+try:
+	unicode
+except NameError:
+	unicode = str
+
+def tounicode(s, encoding='utf-8'):
+	if not isinstance(s, unicode):
+		return s.decode(encoding)
+	else:
+		return s
+
+
 def nothing(data):
 	print(data)
 
@@ -12,7 +25,7 @@
 
 blob = hb.blob_create (fontdata, hb.memory_mode_t.DUPLICATE, 1234, None)
 buf = hb.buffer_create ()
-hb.buffer_add_utf8 (buf, "Hello بهداد", 0, -1)
+hb.buffer_add_utf8 (buf, tounicode("Hello بهداد").encode('utf-8'), 0, -1)
 hb.buffer_guess_segment_properties (buf)
 
 face = hb.face_create (blob, 0)