func NewEx(cfg *Config, mod *py.Base, clsname string, args ...interface{}) (ret *py.Base, err error) { o, err := mod.GetAttrString(clsname) if err != nil { err = errors.Info(err, "pyutil.New", clsname).Detail(err) return } defer o.Decref() ty, ok := py.AsClass(o) if !ok { err = errors.Info(syscall.EINVAL, "pyutil.New", o.String(), "is not a class") return } return NewInstanceEx(cfg, ty, args...) }
func NewInstanceEx(cfg *Config, typ *py.Class, args ...interface{}) (ret *py.Base, err error) { args1, err := PackEx(cfg, args...) if err != nil { err = errors.Info(syscall.EINVAL, "pyutil.NewInstance").Detail(err) return } defer args1.Decref() return typ.New(args1, nil) }
func CallMethodEx(cfg *Config, self *py.Base, method string, args ...interface{}) (ret *py.Base, err error) { args1, err := PackEx(cfg, args...) if err != nil { err = errors.Info(syscall.EINVAL, "pyutil.Call").Detail(err) return } defer args1.Decref() return self.CallMethodObject(method, args1) }
func CallEx(cfg *Config, fn *py.Base, args ...interface{}) (ret *py.Base, err error) { args1, err := PackEx(cfg, args...) if err != nil { err = errors.Info(syscall.EINVAL, "pyutil.Call").Detail(err) return } defer args1.Decref() return fn.CallObject(args1) }
func PackEx(cfg *Config, args ...interface{}) (ret *py.Tuple, err error) { args1 := py.NewTuple(len(args)) for i, arg := range args { v1, ok1 := NewVarEx(arg, cfg) if !ok1 { args1.Decref() err = errors.Info(syscall.EINVAL, "pyutil.Pack", i+1, arg).Detail(err) return } args1.SetItem(i, v1) } return args1, nil }
func (r *HTTPClient) WriteAndClose(path string, body io.Reader) error { url1 := r.NewURLString(path, "CREATE") // Step 1: // Submit a HTTP PUT request without automatically following // redirects and without sending the file data. req1, err := http.NewRequest(httputil.MethodPut, url1, nil) if err != nil { err = errors.New(qerrors.Info(err).LogMessage()) return err } resp1, err := r.http.Do(req1) if err != nil { err = errors.New(qerrors.Info(err).LogMessage()) return err } if resp1.StatusCode/100 != 3 { err := fmt.Errorf("oops: %v", resp1.StatusCode) err = errors.New(qerrors.Info(err).LogMessage()) return err } // Step 2: // Submit another HTTP PUT request using the URL in // the Location header with the file data to be written. url2 := resp1.Header.Get("Location") log.Debug(url2) req2, err := http.NewRequest(httputil.MethodPut, url2, body) if err != nil { err = errors.New(qerrors.Info(err).LogMessage()) return err } resp2, err2 := r.http.Do(req2) if err2 != nil { err2 = errors.New(qerrors.Info(err).LogMessage()) return err2 } log.Debug(resp2.StatusCode) if resp2.StatusCode != 201 { err := fmt.Errorf("%v", resp2.StatusCode) err = errors.New(qerrors.Info(err).LogMessage()) return err } return nil }