This fixes Github issue #2 reported by "kupiakos".
<
https://github.com/libguestfs/hivex/issues/2>
---
generator/generator.ml | 2 +-
python/t/210-setvalue.py | 26 +++++++++++++++++---------
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/generator/generator.ml b/generator/generator.ml
index 908c5f3..02aaf12 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -2981,7 +2981,7 @@ put_val_type (char *val, size_t len, hive_type t)
{
PyObject *r = PyTuple_New (2);
PyTuple_SetItem (r, 0, PyLong_FromLong ((long) t));
- PyTuple_SetItem (r, 1, PyUnicode_DecodeUTF8 (val, len, NULL));
+ PyTuple_SetItem (r, 1, PyBytes_FromStringAndSize (val, len));
return r;
}
diff --git a/python/t/210-setvalue.py b/python/t/210-setvalue.py
index 2ee7ac5..8e7ed5c 100644
--- a/python/t/210-setvalue.py
+++ b/python/t/210-setvalue.py
@@ -19,6 +19,14 @@ import sys
import os
import hivex
+if sys.version >= '3':
+ import codecs
+ def b(x):
+ return codecs.encode(x)
+else:
+ def b(x):
+ return x
+
srcdir = os.environ["srcdir"]
if not srcdir:
srcdir = "."
@@ -32,27 +40,27 @@ assert root
h.node_add_child (root, "B")
-b = h.node_get_child (root, "B")
-assert b
+B = h.node_get_child (root, "B")
+assert B
values = [
{ "key": "Key1", "t": 3, "value":
"ABC" },
{ "key": "Key2", "t": 3, "value":
"DEF" }
]
-h.node_set_values (b, values)
+h.node_set_values (B, values)
value1 = { "key": "Key3", "t": 3, "value":
"GHI" }
-h.node_set_value (b, value1)
+h.node_set_value (B, value1)
value1 = { "key": "Key1", "t": 3, "value":
"JKL" }
-h.node_set_value (b, value1)
+h.node_set_value (B, value1)
-val = h.node_get_value (b, "Key1")
+val = h.node_get_value (B, "Key1")
t_data = h.value_value (val)
assert t_data[0] == 3
-assert t_data[1] == "JKL"
+assert t_data[1] == b("JKL")
-val = h.node_get_value (b, "Key3")
+val = h.node_get_value (B, "Key3")
t_data = h.value_value (val)
assert t_data[0] == 3
-assert t_data[1] == "GHI"
+assert t_data[1] == b("GHI")
--
1.9.rc1