Esempio n. 1
0
func pickleInit() {
	C.Py_Initialize()
	var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
	pickleLoads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
	pickleDumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
	highestProtocol = C.PyObject_GetAttrString(cPickle, C.CString("HIGHEST_PROTOCOL"))
	C.Py_DecRef(cPickle)
	initialized = 1
}
Esempio n. 2
0
func _pickle_init() {
	if initialized == 0 {
		C.Py_Initialize()
		var cPickle *C.PyObject = C.PyImport_ImportModule(C.CString("cPickle"))
		pickle_loads = C.PyObject_GetAttrString(cPickle, C.CString("loads"))
		pickle_dumps = C.PyObject_GetAttrString(cPickle, C.CString("dumps"))
		C.Py_DecRef(cPickle)
		initialized = 1
	}
}
Esempio n. 3
0
// Import a Python module.
func Import(t *Thread, name string) (module Object, err error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	t.execute(func() {
		pyModule := C.PyImport_ImportModule(cName)
		if pyModule == nil {
			err = getError()
			return
		}
		defer C.DECREF(pyModule)

		module = newObject(pyModule)
	})
	return
}
Esempio n. 4
0
// PyObject* PyImport_ImportModule(const char *name)
// Return value: New reference.
// This is a simplified interface to PyImport_ImportModuleEx() below, leaving the globals and locals arguments set to NULL and level set to 0. When the name argument contains a dot (when it specifies a submodule of a package), the fromlist argument is set to the list ['*'] so that the return value is the named module rather than the top-level package containing it as would otherwise be the case. (Unfortunately, this has an additional side effect when name in fact specifies a subpackage instead of a submodule: the submodules specified in the package’s __all__ variable are loaded.) Return a new reference to the imported module, or NULL with an exception set on failure. Before Python 2.4, the module may still be created in the failure case — examine sys.modules to find out. Starting with Python 2.4, a failing import of a module no longer leaves the module in sys.modules.
//
// Changed in version 2.4: Failing imports remove incomplete module objects.
//
// Changed in version 2.6: Always uses absolute imports.
func PyImport_ImportModule(name string) *PyObject {
	c_name := C.CString(name)
	defer C.free(unsafe.Pointer(c_name))

	return togo(C.PyImport_ImportModule(c_name))
}