Beispiel #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))
}
Beispiel #2
0
func (t *Type) String() string {
	pyS := C.PyObject_Str(c(t))
	if pyS == nil {
		return "<unknown type>"
	}
	return stringify(t)
}
Beispiel #3
0
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))
}
Beispiel #4
0
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()
}
Beispiel #5
0
// 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)
}
Beispiel #6
0
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
}
Beispiel #7
0
// 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))
}
Beispiel #8
0
// 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)
}
Beispiel #9
0
// 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)
}