Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
0af12a50
Commit
0af12a50
authored
Aug 08, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3f3478c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
31 deletions
+33
-31
go/zodb/pydata.go
go/zodb/pydata.go
+33
-31
No files found.
go/zodb/pydata.go
View file @
0af12a50
...
...
@@ -23,7 +23,6 @@ package zodb
import
(
"bytes"
"encoding/binary"
"errors"
"fmt"
"lab.nexedi.com/kirr/go123/xerr"
...
...
@@ -52,7 +51,7 @@ func (d PyData) ClassName() string {
return
"?.?"
}
klass
,
err
:=
normPyC
lass
(
xklass
)
klass
,
err
:=
xpyc
lass
(
xklass
)
if
err
!=
nil
{
return
"?.?"
}
...
...
@@ -78,7 +77,7 @@ func (d PyData) decode(jar *Connection) (pyclass pickle.Class, pystate interface
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"class description: %s"
,
err
)
}
klass
,
err
:=
normPyC
lass
(
xklass
)
klass
,
err
:=
xpyc
lass
(
xklass
)
if
err
!=
nil
{
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"class description: %s"
,
err
)
}
...
...
@@ -110,12 +109,12 @@ func (jar *Connection) loadref(ref pickle.Ref) (_ interface{}, err error) {
oid
,
err
:=
xoid
(
t
[
0
])
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
return
nil
,
err
}
pyclass
,
err
:=
normPyC
lass
(
t
[
1
])
pyclass
,
err
:=
xpyc
lass
(
t
[
1
])
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
return
nil
,
err
}
class
:=
pyclassPath
(
pyclass
)
...
...
@@ -125,32 +124,34 @@ func (jar *Connection) loadref(ref pickle.Ref) (_ interface{}, err error) {
var
errInvalidPyClass
=
errors
.
New
(
"invalid py class description"
)
// normPyClass normalizes py class that has just been decoded from a serialized
// ZODB object or reference.
func
normPyClass
(
xklass
interface
{})
(
pickle
.
Class
,
error
)
{
// class description:
//
// - type(obj), or
// - (xklass, newargs|None) ; xklass = type(obj) | (modname, classname)
// xpyclass verifies and extracts py class from unpickled value.
//
// it normalizes py class that has just been decoded from a serialized ZODB
// object or reference.
//
// class description:
//
// - type(obj), or
// - (xklass, newargs|None) ; xklass = type(obj) | (modname, classname)
func
xpyclass
(
xklass
interface
{})
(
_
pickle
.
Class
,
err
error
)
{
defer
xerr
.
Context
(
&
err
,
"class"
)
if
t
,
ok
:=
xklass
.
(
pickle
.
Tuple
);
ok
{
// t = (xklass, newargs|None)
if
len
(
t
)
!=
2
{
return
pickle
.
Class
{},
errInvalidPyClass
return
pickle
.
Class
{},
fmt
.
Errorf
(
"top: expect [2](); got [%d]()"
,
len
(
t
))
}
// XXX newargs is ignored (zodb/py uses it only for persistent classes)
xklass
=
t
[
0
]
if
t
,
ok
:=
xklass
.
(
pickle
.
Tuple
);
ok
{
// t = (modname, classname)
if
len
(
t
)
!=
2
{
return
pickle
.
Class
{},
errInvalidPyClass
return
pickle
.
Class
{},
fmt
.
Errorf
(
"xklass: expect [2](); got [%d]()"
,
len
(
t
))
}
modname
,
ok1
:=
t
[
0
]
.
(
string
)
classname
,
ok2
:=
t
[
1
]
.
(
string
)
if
!
(
ok1
&&
ok2
)
{
return
pickle
.
Class
{},
errInvalidPyClass
return
pickle
.
Class
{},
fmt
.
Errorf
(
"xklass: expect (str, str); got (%T, %T)"
,
t
[
0
],
t
[
1
])
}
return
pickle
.
Class
{
Module
:
modname
,
Name
:
classname
},
nil
...
...
@@ -162,28 +163,29 @@ func normPyClass(xklass interface{}) (pickle.Class, error) {
return
klass
,
nil
}
return
pickle
.
Class
{},
errInvalidPyClass
}
// pyclassPath returns full path for a python class.
//
// for example class "ABC" in module "wendelin.lib" has its full path as "wendelin.lib.ABC".
func
pyclassPath
(
pyclass
pickle
.
Class
)
string
{
return
pyclass
.
Module
+
"."
+
pyclass
.
Name
return
pickle
.
Class
{},
fmt
.
Errorf
(
"expect type; got %T"
,
xklass
)
}
// xoid verifies and extracts oid from unpickled value.
//
// XXX +zobdpickle.binary support
// XXX -> shared place
func
xoid
(
x
interface
{})
(
Oid
,
error
)
{
// TODO +zobdpickle.binary support
func
xoid
(
x
interface
{})
(
_
Oid
,
err
error
)
{
defer
xerr
.
Context
(
&
err
,
"oid"
)
s
,
ok
:=
x
.
(
string
)
if
!
ok
{
return
InvalidOid
,
fmt
.
Errorf
(
"
xoid:
expect str; got %T"
,
x
)
return
InvalidOid
,
fmt
.
Errorf
(
"expect str; got %T"
,
x
)
}
if
len
(
s
)
!=
8
{
return
InvalidOid
,
fmt
.
Errorf
(
"
xoid:
expect [8]str; got [%d]str"
,
len
(
s
))
return
InvalidOid
,
fmt
.
Errorf
(
"expect [8]str; got [%d]str"
,
len
(
s
))
}
return
Oid
(
binary
.
BigEndian
.
Uint64
([]
byte
(
s
))),
nil
}
// pyclassPath returns full path for a python class.
//
// for example class "ABC" in module "wendelin.lib" has its full path as "wendelin.lib.ABC".
func
pyclassPath
(
pyclass
pickle
.
Class
)
string
{
return
pyclass
.
Module
+
"."
+
pyclass
.
Name
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment