예제 #1
0
func (t *Type) String() string {
	pyS := C.PyObject_Str(c(t))
	if pyS == nil {
		return "<unknown type>"
	}
	return C.GoString(C.PyString_AsString(pyS))
}
예제 #2
0
파일: type.go 프로젝트: hexid/gopy
func (t *Type) String() string {
	pyS := C.PyObject_Str(c(t))
	if pyS == nil {
		return "<unknown type>"
	}
	return stringify(t)
}
예제 #3
0
파일: object.go 프로젝트: gbbr/textmate
func stringify(obj Object) string {
	tpyS := C.PyObject_Str(c(obj))
	defer C.decref(tpyS)
	u := C.PyUnicode_AsUTF8String(tpyS)
	defer C.decref(u)
	return C.GoString(C.PyBytes_AsString(u))
}
예제 #4
0
파일: object.go 프로젝트: MogeiWang/py
func (obj *Base) String() string {
	if v, ok := AsString(obj); ok {
		return v.String()
	}
	ret := C.PyObject_Str(obj.c())
	if ret == nil {
		return "<nil>"
	}
	defer C.decref(ret)
	return ((*String)(unsafe.Pointer(ret))).String()
}
예제 #5
0
파일: err.go 프로젝트: xushiwei/gopy
// Error() returns a string representation of the Python exception represented
// by the Error e.  This is the same as the final line of the Python output from
// an uncaught exception.
func (e *Error) Error() string {
	ts := ""
	en := C.excName(c(e.Kind))
	if en.c == nil {
		tpyS := C.PyObject_Str(c(e.Kind))
		defer C.decref(tpyS)
		ts = C.GoString(C.PyString_AsString(tpyS))
	} else {
		if en.m != nil {
			ts = C.GoString(en.m) + "."
		}
		ts += C.GoString(en.c)
	}

	pyS := C.PyObject_Str(c(e.Value))
	defer C.decref(pyS)
	s := C.GoString(C.PyString_AsString(pyS))

	return fmt.Sprintf("%s: %s", ts, s)
}
예제 #6
0
파일: python.go 프로젝트: tsavola/go-python
func stringify(pyObject *C.PyObject) (s string) {
	if pyResult := C.PyObject_Str(pyObject); pyResult != nil {
		defer C.DECREF(pyResult)

		if cString := C.PyString_AsString(pyResult); cString != nil {
			s = C.GoString(cString)
		}
	}

	C.PyErr_Clear()
	return
}
예제 #7
0
파일: object.go 프로젝트: gward/go-python
// PyObject* PyObject_Str(PyObject *o)
// Return value: New reference.
// Compute a string representation of object o. Returns the string representation on success, NULL on failure. This is the equivalent of the Python expression str(o). Called by the str() built-in function and by the print statement.
func (self *PyObject) Str() *PyObject {
	return togo(C.PyObject_Str(self.ptr))
}
예제 #8
0
파일: object.go 프로젝트: MogeiWang/py
// Str returns a String representation of "obj".  This is equivalent to the
// Python "str(obj)".
//
// Return value: New Reference.
func (obj *Base) Str() (*Base, error) {
	ret := C.PyObject_Str(obj.c())
	return obj2ObjErr(ret)
}
예제 #9
0
파일: base.go 프로젝트: xushiwei/gopy
// Str returns a String representation of "obj".  This is equivalent to the
// Python "str(obj)".
//
// Return value: New Reference.
func (obj *BaseObject) Str() (Object, error) {
	ret := C.PyObject_Str(c(obj))
	return obj2ObjErr(ret)
}