Commit e348423c authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Fix PyData.ClassName for py3_pickle3

Test for PyData.ClassName currently fails for py3_pickle3 zkind:

    === RUN   TestPyClassName/py3_pickle3
        pydata_test.go:50: class name for "\x80\x03X\x18\x00\x00\x00ZODB.tests.testSerializeq\x00X\x13\x00\x00\x00ClassWithoutNewargsq\x01\x86q\x02N\x86q\x03.":
            have: "?.?"
            want: "ZODB.tests.testSerialize.ClassWithoutNewargs"
        pydata_test.go:50: class name for "\x80\x03X\x18\x00\x00\x00ZODB.tests.testSerializeq\x00X\x10\x00\x00\x00ClassWithNewargsq\x01\x86q\x02K\x01\x85q\x03\x86q\x04.":
            have: "?.?"
            want: "ZODB.tests.testSerialize.ClassWithNewargs"

This happens because classname decoder was expecting class and module
names to come as py2 bytestrings, while py3 emits them as unicode.

-> Fix it by accepting both py2 bytestring and unicode for class and
module names.
parent 85db9c4f
......@@ -206,12 +206,13 @@ func xpyclass(xklass interface{}) (_ pickle.Class, err error) {
if len(t) != 2 {
return pickle.Class{}, fmt.Errorf("xklass: expect [2](); got [%d]()", len(t))
}
__, ok1 := t[0].(pickle.ByteString)
modname := string(__)
__, ok2 := t[1].(pickle.ByteString)
classname := string(__)
if !(ok1 && ok2) {
return pickle.Class{}, fmt.Errorf("xklass: expect (str, str); got (%T, %T)", t[0], t[1])
modname, err := pickle.AsString(t[0])
if err != nil {
return pickle.Class{}, fmt.Errorf("xklass: module: %s", err)
}
classname, err := pickle.AsString(t[1])
if err != nil {
return pickle.Class{}, fmt.Errorf("xklass: class: %s", err)
}
return pickle.Class{Module: modname, Name: classname}, nil
......
......@@ -38,9 +38,6 @@ var _PyDataClassName_TestDataRegistry = map[/*zkind*/string][]_PyDataClassName_T
func TestPyClassName(t *testing.T) {
for _, zkind := range xmaps.SortedKeys(_PyDataClassName_TestDataRegistry) {
t.Run(zkind, func(t *testing.T) {
if zkind == "py3_pickle3" {
t.Skip("xfail")
}
_TestPyClassName(t, _PyDataClassName_TestDataRegistry[zkind])
})
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment