Example #1
0
// PyObject* PyString_AsEncodedObject(PyObject *str, const char *encoding, const char *errors)
// Return value: New reference.
// Encode a string object using the codec registered for encoding and return the result as Python object. encoding and errors have the same meaning as the parameters of the same name in the string encode() method. The codec to be used is looked up using the Python codec registry. Return NULL if an exception was raised by the codec.
//
// Note This function is not available in 3.x and does not have a PyBytes alias.
func PyString_AsEncodedObject(self *PyObject, encoding, errors string) *PyObject {
	c_encoding := C.CString(encoding)
	defer C.free(unsafe.Pointer(c_encoding))

	c_errors := C.CString(errors)
	defer C.free(unsafe.Pointer(c_errors))

	return togo(C.PyString_AsEncodedObject(topy(self), c_encoding, c_errors))
}
Example #2
0
func (s *String) Encode(encoding, errors string) (Object, error) {
	var cEncoding, cErrors *C.char
	if encoding == "" {
		cEncoding = C.CString(encoding)
		defer C.free(unsafe.Pointer(cEncoding))
	}
	if errors != "" {
		cErrors = C.CString(errors)
		defer C.free(unsafe.Pointer(cErrors))
	}
	ret := C.PyString_AsEncodedObject(c(s), cEncoding, cErrors)
	return obj2ObjErr(ret)
}