Commit 6143b5b3 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 06534cb4
...@@ -206,12 +206,13 @@ func xpyclass(xklass interface{}) (_ pickle.Class, err error) { ...@@ -206,12 +206,13 @@ func xpyclass(xklass interface{}) (_ pickle.Class, err error) {
if len(t) != 2 { if len(t) != 2 {
return pickle.Class{}, fmt.Errorf("xklass: expect [2](); got [%d]()", len(t)) return pickle.Class{}, fmt.Errorf("xklass: expect [2](); got [%d]()", len(t))
} }
__, ok1 := t[0].(pickle.ByteString) modname, err := pickle.AsString(t[0])
modname := string(__) if err != nil {
__, ok2 := t[1].(pickle.ByteString) return pickle.Class{}, fmt.Errorf("xklass: module: %s", err)
classname := string(__) }
if !(ok1 && ok2) { classname, err := pickle.AsString(t[1])
return pickle.Class{}, fmt.Errorf("xklass: expect (str, str); got (%T, %T)", t[0], t[1]) if err != nil {
return pickle.Class{}, fmt.Errorf("xklass: class: %s", err)
} }
return pickle.Class{Module: modname, Name: classname}, nil return pickle.Class{Module: modname, Name: classname}, nil
......
...@@ -38,9 +38,6 @@ var _PyDataClassName_TestDataRegistry = map[/*zkind*/string][]_PyDataClassName_T ...@@ -38,9 +38,6 @@ var _PyDataClassName_TestDataRegistry = map[/*zkind*/string][]_PyDataClassName_T
func TestPyClassName(t *testing.T) { func TestPyClassName(t *testing.T) {
for _, zkind := range xmaps.SortedKeys(_PyDataClassName_TestDataRegistry) { for _, zkind := range xmaps.SortedKeys(_PyDataClassName_TestDataRegistry) {
t.Run(zkind, func(t *testing.T) { t.Run(zkind, func(t *testing.T) {
if zkind == "py3_pickle3" {
t.Skip("xfail")
}
_TestPyClassName(t, _PyDataClassName_TestDataRegistry[zkind]) _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