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
fe24c62f
Commit
fe24c62f
authored
Jul 14, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/zodb/zeo: Factor-out tuple handling into encoding
Handle pickled lists as valid input when decoding tuples.
parent
dc419056
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
10 deletions
+43
-10
go/zodb/storage/zeo/proto.go
go/zodb/storage/zeo/proto.go
+36
-1
go/zodb/storage/zeo/zeo.go
go/zodb/storage/zeo/zeo.go
+6
-6
go/zodb/storage/zeo/zrpc.go
go/zodb/storage/zeo/zrpc.go
+1
-3
No files found.
go/zodb/storage/zeo/proto.go
View file @
fe24c62f
...
...
@@ -98,7 +98,7 @@ func pktDecodeZ(pkb *pktBuf) (msg, error) {
return
m
,
err
}
tpkt
,
ok
:=
xpkt
.
(
pickle
.
Tuple
)
// XXX also list?
tpkt
,
ok
:=
encoding
(
'Z'
)
.
asTuple
(
xpkt
)
if
!
ok
{
return
m
,
derrf
(
"got %T; expected tuple"
,
xpkt
)
}
...
...
@@ -134,6 +134,41 @@ func derrf(format string, argv ...interface{}) error {
// ---- retrieve/put objects from/into msg.arg ----
// tuple represents py tuple.
type
tuple
[]
interface
{}
// Tuple converts t into corresponding object appropriate for encoding e.
func
(
e
encoding
)
Tuple
(
t
tuple
)
pickle
.
Tuple
{
switch
e
{
default
:
panic
(
"bug"
)
case
'Z'
:
// pickle: -> pickle.Tuple
return
pickle
.
Tuple
(
t
)
}
}
// asTuple tries to retrieve tuple from corresponding object decoded via encoding e.
func
(
e
encoding
)
asTuple
(
xt
interface
{})
(
tuple
,
bool
)
{
switch
e
{
default
:
panic
(
"bug"
)
case
'Z'
:
// pickle: tuples are represented by pickle.Tuple; lists as []interface{}
switch
t
:=
xt
.
(
type
)
{
case
pickle
.
Tuple
:
return
tuple
(
t
),
true
case
[]
interface
{}
:
return
tuple
(
t
),
true
default
:
return
tuple
(
nil
),
false
}
}
}
// xuint64Unpack tries to decode packed 8-byte string as bigendian uint64
func
(
e
encoding
)
xuint64Unpack
(
xv
interface
{})
(
uint64
,
bool
)
{
switch
e
{
...
...
go/zodb/storage/zeo/zeo.go
View file @
fe24c62f
...
...
@@ -86,7 +86,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
}
// (data, serial, next_serial | None)
res
,
ok
:=
xres
.
(
pickle
.
Tuple
)
res
,
ok
:=
enc
.
asTuple
(
xres
)
if
!
ok
||
len
(
res
)
!=
3
{
return
nil
,
0
,
rpc
.
ereplyf
(
"got %#v; expect 3-tuple"
,
res
)
}
...
...
@@ -140,7 +140,7 @@ type rpc struct {
// rpcExcept represents generic exception
type
rpcExcept
struct
{
exc
string
argv
[]
interface
{}
argv
tuple
}
func
(
r
*
rpcExcept
)
Error
()
string
{
...
...
@@ -175,7 +175,7 @@ func (r rpc) call(ctx context.Context, argv ...interface{}) (interface{}, error)
//
// well-known exceptions are mapped to corresponding well-known errors - e.g.
// POSKeyError -> zodb.NoObjectError, and rest are returned wrapper into rpcExcept.
func
(
r
rpc
)
excError
(
exc
string
,
argv
[]
interface
{}
)
error
{
func
(
r
rpc
)
excError
(
exc
string
,
argv
tuple
)
error
{
// translate well-known exceptions
switch
exc
{
case
"ZODB.POSException.POSKeyError"
:
...
...
@@ -204,13 +204,13 @@ func (r rpc) excError(exc string, argv []interface{}) error {
func
(
r
rpc
)
zeo5Error
(
arg
interface
{})
error
{
enc
:=
r
.
zlink
.
enc
// ('type', (arg1, arg2, arg3, ...))
texc
,
ok
:=
arg
.
(
pickle
.
Tuple
)
texc
,
ok
:=
enc
.
asTuple
(
arg
)
if
!
ok
||
len
(
texc
)
!=
2
{
return
r
.
ereplyf
(
"except5: got %#v; expect 2-tuple"
,
arg
)
}
exc
,
ok1
:=
enc
.
asString
(
texc
[
0
])
argv
,
ok2
:=
texc
[
1
]
.
(
pickle
.
Tuple
)
argv
,
ok2
:=
enc
.
asTuple
(
texc
[
1
]
)
if
!
(
ok1
&&
ok2
)
{
return
r
.
ereplyf
(
"except5: got (%T, %T); expect (str, tuple)"
,
texc
...
)
}
...
...
@@ -277,7 +277,7 @@ func (r rpc) zeo4Error(arg interface{}) error {
argv
=
args
}
return
r
.
excError
(
exc
,
argv
)
return
r
.
excError
(
exc
,
tuple
(
argv
)
)
}
// isPyExceptClass returns whether klass represents python exception
...
...
go/zodb/storage/zeo/zrpc.go
View file @
fe24c62f
...
...
@@ -30,8 +30,6 @@ import (
"net"
"sync"
pickle
"github.com/kisielk/og-rek"
"github.com/someonegg/gocontainer/rbuf"
"lab.nexedi.com/kirr/go123/xbytes"
"lab.nexedi.com/kirr/go123/xerr"
...
...
@@ -188,7 +186,7 @@ func (zl *zLink) Call(ctx context.Context, method string, argv ...interface{}) (
msgid
:
callID
,
flags
:
0
,
method
:
method
,
arg
:
pickle
.
Tuple
(
argv
),
arg
:
zl
.
enc
.
Tuple
(
argv
),
})
// ok, pkt is ready to go
...
...
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