forked from DataDog/go-python3
-
Notifications
You must be signed in to change notification settings - Fork 50
/
import.go
148 lines (111 loc) · 5.26 KB
/
import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
Unless explicitly stated otherwise all files in this repository are licensed
under the MIT License.
This product includes software developed at Datadog (https://www.datadoghq.com/).
Copyright 2018 Datadog, Inc.
*/
package python3
/*
#include "Python.h"
*/
import "C"
import (
"unsafe"
)
//PyImport_ImportModule : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModule
func PyImport_ImportModule(name string) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PyImport_ImportModule(cname))
}
//PyImport_ImportModuleEx : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleEx
func PyImport_ImportModuleEx(name string, globals, locals, fromlist *PyObject) *PyObject {
return PyImport_ImportModuleLevel(name, globals, locals, fromlist, 0)
}
//PyImport_ImportModuleLevelObject : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleLevelObject
func PyImport_ImportModuleLevelObject(name, globals, locals, fromlist *PyObject, level int) *PyObject {
return togo(C.PyImport_ImportModuleLevelObject(toc(name), toc(globals), toc(locals), toc(fromlist), C.int(level)))
}
//PyImport_ImportModuleLevel : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleLevel
func PyImport_ImportModuleLevel(name string, globals, locals, fromlist *PyObject, level int) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PyImport_ImportModuleLevel(cname, toc(globals), toc(locals), toc(fromlist), C.int(level)))
}
//PyImport_Import : https://docs.python.org/3/c-api/import.html#c.PyImport_Import
func PyImport_Import(name *PyObject) *PyObject {
return togo(C.PyImport_Import(toc(name)))
}
//PyImport_ReloadModule : https://docs.python.org/3/c-api/import.html#c.PyImport_ReloadModule
func PyImport_ReloadModule(name *PyObject) *PyObject {
return togo(C.PyImport_ReloadModule(toc(name)))
}
//PyImport_AddModuleObject : https://docs.python.org/3/c-api/import.html#c.PyImport_AddModuleObject
func PyImport_AddModuleObject(name *PyObject) *PyObject {
return togo(C.PyImport_AddModuleObject(toc(name)))
}
//PyImport_AddModule : https://docs.python.org/3/c-api/import.html#c.PyImport_AddModule
func PyImport_AddModule(name string) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PyImport_AddModule(cname))
}
//PyImport_ExecCodeModule : https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModule
func PyImport_ExecCodeModule(name string, co *PyObject) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return togo(C.PyImport_ExecCodeModule(cname, toc(co)))
}
//PyImport_ExecCodeModuleEx : https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleEx
func PyImport_ExecCodeModuleEx(name string, co *PyObject, pathname string) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cpathname := C.CString(pathname)
defer C.free(unsafe.Pointer(cpathname))
return togo(C.PyImport_ExecCodeModuleEx(cname, toc(co), cpathname))
}
//PyImport_ExecCodeModuleObject : https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleObject
func PyImport_ExecCodeModuleObject(name, co, pathname, cpathname *PyObject) *PyObject {
return togo(C.PyImport_ExecCodeModuleObject(toc(name), toc(co), toc(pathname), toc(cpathname)))
}
//PyImport_ExecCodeModuleWithPathnames : https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleWithPathnames
func PyImport_ExecCodeModuleWithPathnames(name string, co *PyObject, pathname string, cpathname string) *PyObject {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
cspathname := C.CString(pathname)
defer C.free(unsafe.Pointer(cspathname))
ccpathname := C.CString(cpathname)
defer C.free(unsafe.Pointer(ccpathname))
return togo(C.PyImport_ExecCodeModuleWithPathnames(cname, toc(co), cspathname, ccpathname))
}
//PyImport_GetMagicNumber : https://docs.python.org/3/c-api/import.html#c.PyImport_GetMagicNumber
func PyImport_GetMagicNumber() int {
return int(C.PyImport_GetMagicNumber())
}
//PyImport_GetMagicTag : https://docs.python.org/3/c-api/import.html#c.PyImport_GetMagicTag
func PyImport_GetMagicTag() string {
cmagicTag := C.PyImport_GetMagicTag()
return C.GoString(cmagicTag)
}
//PyImport_GetModuleDict : https://docs.python.org/3/c-api/import.html#c.PyImport_GetModuleDict
func PyImport_GetModuleDict() *PyObject {
return togo(C.PyImport_GetModuleDict())
}
//PyImport_GetModule : https://docs.python.org/3/c-api/import.html#c.PyImport_GetModule
func PyImport_GetModule(name *PyObject) *PyObject {
return togo(C.PyImport_GetModule(toc(name)))
}
//PyImport_GetImporter : https://docs.python.org/3/c-api/import.html#c.PyImport_GetImporter
func PyImport_GetImporter(path *PyObject) *PyObject {
return togo(C.PyImport_GetImporter(toc(path)))
}
//PyImport_ImportFrozenModuleObject : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportFrozenModuleObject
func PyImport_ImportFrozenModuleObject(name *PyObject) int {
return int(C.PyImport_ImportFrozenModuleObject(toc(name)))
}
//PyImport_ImportFrozenModule : https://docs.python.org/3/c-api/import.html#c.PyImport_ImportFrozenModule
func PyImport_ImportFrozenModule(name string) int {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
return int(C.PyImport_ImportFrozenModule(cname))
}