Commit d4d1704c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b387162a
...@@ -182,7 +182,7 @@ func (r rpc) call(ctx context.Context, argv ...interface{}) (interface{}, error) ...@@ -182,7 +182,7 @@ func (r rpc) call(ctx context.Context, argv ...interface{}) (interface{}, error)
// //
// well-known exceptions are mapped to corresponding well-known errors - e.g. // well-known exceptions are mapped to corresponding well-known errors - e.g.
// POSKeyError -> zodb.NoObjectError, and rest are returned wrapper into rpcExcept. // 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 // translate well-known exceptions
switch exc { switch exc {
case "ZODB.POSException.POSKeyError": case "ZODB.POSException.POSKeyError":
...@@ -208,16 +208,14 @@ func (r rpc) excError(exc string, argv []interface{}) error { ...@@ -208,16 +208,14 @@ func (r rpc) excError(exc string, argv []interface{}) error {
// zeo5Error decodes arg of reply with msgExcept flag set and returns // zeo5Error decodes arg of reply with msgExcept flag set and returns
// corresponding error. // corresponding error.
func (r rpc) zeo5Error(arg interface{}) error { func (r rpc) zeo5Error(arg interface{}) error {
// XXX check r.zl.encoding == 'Z' before using pickles?
// ('type', (arg1, arg2, arg3, ...)) // ('type', (arg1, arg2, arg3, ...))
texc, ok := arg.(pickle.Tuple) texc, ok := r.zl.asTuple(arg)
if !ok || len(texc) != 2 { if !ok || len(texc) != 2 {
return r.ereplyf("except5: got %#v; expect 2-tuple", arg) return r.ereplyf("except5: got %#v; expect 2-tuple", arg)
} }
exc, ok1 := texc[0].(string) exc, ok1 := r.zl.asString(texc[0])
argv, ok2 := texc[1].(pickle.Tuple) argv, ok2 := r.zl.asTuple(texc[1])
if !(ok1 && ok2) { if !(ok1 && ok2) {
return r.ereplyf("except5: got (%T, %T); expect (str, tuple)", texc...) return r.ereplyf("except5: got (%T, %T); expect (str, tuple)", texc...)
} }
...@@ -286,7 +284,7 @@ func (r rpc) zeo4Error(arg interface{}) error { ...@@ -286,7 +284,7 @@ func (r rpc) zeo4Error(arg interface{}) error {
argv = args argv = args
} }
return r.excError(exc, argv) return r.excError(exc, tuple(argv)) // XXX don't cast?
} }
// isPyExceptClass returns whether klass represents python exception // isPyExceptClass returns whether klass represents python exception
...@@ -530,3 +528,21 @@ func (zl *zLink) asBytes(xb interface{}) ([]byte, bool) { ...@@ -530,3 +528,21 @@ func (zl *zLink) asBytes(xb interface{}) ([]byte, bool) {
return b, ok return b, ok
} }
} }
// asString tries to decode object as string.
func (zl *zLink) asString(xs interface{}) (string, bool) {
switch zl.encoding{
default:
panic("bug")
case 'Z':
// pickle: str
s, ok := xs.(string)
return s, ok
case 'M':
// msgpack: bin XXX ZEO/py sends strings as bin
b, ok := xs.([]byte)
return string(b), ok
}
}
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