Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
acc6c2ec
Commit
acc6c2ec
authored
Jul 31, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8da2cb82
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
12 deletions
+68
-12
go/zodb/persistent.go
go/zodb/persistent.go
+1
-1
go/zodb/pydata.go
go/zodb/pydata.go
+63
-8
go/zodb/zodbpy.go
go/zodb/zodbpy.go
+4
-3
No files found.
go/zodb/persistent.go
View file @
acc6c2ec
...
...
@@ -243,7 +243,7 @@ func (obj *Persistent) PActivate(ctx context.Context) (err error) {
err
=
istate
.
SetState
(
state
)
// XXX err ctx
case
PyStateful
:
err
=
pySetState
(
istate
,
obj
.
zclass
.
class
,
state
)
// XXX err ctx
err
=
pySetState
(
istate
,
obj
.
zclass
.
class
,
state
,
obj
.
jar
)
// XXX err ctx
default
:
panic
(
"!stateful instance"
)
...
...
go/zodb/pydata.go
View file @
acc6c2ec
...
...
@@ -22,9 +22,11 @@ package zodb
import
(
"bytes"
"encoding/binary"
"errors"
"fmt"
"lab.nexedi.com/kirr/go123/xerr"
pickle
"github.com/kisielk/og-rek"
)
...
...
@@ -40,26 +42,79 @@ import (
// PyData can be decoded into PyObject.
type
PyData
[]
byte
// xoid verifies and extracts oid from unpickled value.
// XXX place?
func
xoid
(
x
interface
{})
(
Oid
,
error
)
{
s
,
ok
:=
x
.
(
string
)
if
!
ok
{
return
InvalidOid
,
fmt
.
Errorf
(
"xoid: expect str; got %T"
,
x
)
}
if
len
(
s
)
!=
8
{
return
InvalidOid
,
fmt
.
Errorf
(
"xoid: expect [8]str; got [%d]str"
,
len
(
s
))
}
return
Oid
(
binary
.
BigEndian
.
Uint64
([]
byte
(
s
))),
nil
}
// loadref loads persistent references resolving them through jar.
//
// https://github.com/zopefoundation/ZODB/blob/a89485c1/src/ZODB/serialize.py#L80
//
// XXX place?
func
(
jar
*
Connection
)
loadref
(
ref
pickle
.
Ref
)
(
_
interface
{},
err
error
)
{
defer
xerr
.
Context
(
&
err
,
"loadref"
)
// TODO add support for ref formats besides (oid, class)
t
,
ok
:=
ref
.
Pid
.
(
pickle
.
Tuple
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"expect (); got %T"
,
ref
.
Pid
)
}
if
len
(
t
)
!=
2
{
return
nil
,
fmt
.
Errorf
(
"expect (oid, class); got [%d]()"
,
len
(
t
))
}
oid
,
err
:=
xoid
(
t
[
0
])
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
}
pyclass
,
err
:=
normPyClass
(
t
[
1
])
if
err
!=
nil
{
return
nil
,
err
// XXX err ctx
}
class
:=
pyclassPath
(
pyclass
)
return
jar
.
get
(
class
,
oid
)
}
// decode decodes raw ZODB python data into Python class and state.
//
// jar is used to resolve persistent references.
func
(
d
PyData
)
decode
(
jar
*
Connection
)
(
pyclass
pickle
.
Class
,
pystate
interface
{},
err
error
)
{
defer
xerr
.
Context
(
&
err
,
"pydata: decode"
)
p
:=
pickle
.
NewDecoderWithConfig
(
bytes
.
NewReader
([]
byte
(
d
)),
&
pickle
.
DecoderConfig
{
PersistentLoad
:
jar
.
loadref
},
)
// Decode decodes raw ZODB python data into Python class and state.
func
(
d
PyData
)
Decode
()
(
pyclass
pickle
.
Class
,
pystate
interface
{},
_
error
)
{
p
:=
pickle
.
NewDecoder
(
bytes
.
NewReader
([]
byte
(
d
)))
xklass
,
err
:=
p
.
Decode
()
if
err
!=
nil
{
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"
pydata: decode:
class description: %s"
,
err
)
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"class description: %s"
,
err
)
}
klass
,
err
:=
normPyClass
(
xklass
)
if
err
!=
nil
{
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"
pydata: decode:
class description: %s"
,
err
)
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"class description: %s"
,
err
)
}
state
,
err
:=
p
.
Decode
()
if
err
!=
nil
{
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"
pydata: decode:
object state: %s"
,
err
)
return
pickle
.
Class
{},
nil
,
fmt
.
Errorf
(
"object state: %s"
,
err
)
}
//return &PyObject{pyClass: klass, State: state}, nil
return
klass
,
state
,
nil
}
...
...
@@ -81,7 +136,7 @@ func (d PyData) ClassName() string {
return
"?.?"
}
return
klass
.
Module
+
"."
+
klass
.
Name
return
pyclassPath
(
klass
)
}
var
errInvalidPyClass
=
errors
.
New
(
"invalid py class description"
)
...
...
go/zodb/zodbpy.go
View file @
acc6c2ec
...
...
@@ -40,8 +40,9 @@ type PyStateful interface {
// state on PyStateful obj.
//
// It is an error if decoded state has python class not as specified.
func
pySetState
(
obj
PyStateful
,
objClass
string
,
state
*
mem
.
Buf
)
error
{
pyclass
,
pystate
,
err
:=
PyData
(
state
.
Data
)
.
Decode
()
// jar is used to resolve persistent references.
func
pySetState
(
obj
PyStateful
,
objClass
string
,
state
*
mem
.
Buf
,
jar
*
Connection
)
error
{
pyclass
,
pystate
,
err
:=
PyData
(
state
.
Data
)
.
decode
(
jar
)
if
err
!=
nil
{
return
err
// XXX err ctx
}
...
...
@@ -82,7 +83,7 @@ func (conn *Connection) loadpy(ctx context.Context, oid Oid) (class string, pyst
defer
buf
.
Release
()
pyclass
,
pystate
,
err
:=
PyData
(
buf
.
Data
)
.
Decode
(
)
pyclass
,
pystate
,
err
:=
PyData
(
buf
.
Data
)
.
decode
(
conn
)
if
err
!=
nil
{
return
""
,
nil
,
0
,
err
// XXX err ctx
}
...
...
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