コード例 #1
0
ファイル: pickle.go プロジェクト: redbo/goswiftobj
func pyObjToInterface(o *C.PyObject) interface{} {
	if C.myPyString_Check(o) != 0 {
		return C.GoStringN(C.PyString_AsString(o), C.int(C.PyString_Size(o)))
	} else if C.myPyInt_Check(o) != 0 {
		return int64(C.PyInt_AsLong(o))
	} else if C.myPyDict_Check(o) != 0 {
		v := make(map[interface{}]interface{})
		items := C.PyDict_Items(o)
		for i := 0; i < int(C.PyTuple_Size(items)); i++ {
			item := C.PyTuple_GetItem(items, C.Py_ssize_t(i))
			key := C.PyTuple_GetItem(item, 0)
			value := C.PyTuple_GetItem(item, 1)
			v[pyObjToInterface(key)] = pyObjToInterface(value)
		}
		C.Py_DecRef(items)
		return v
	} else if C.myPyTuple_Check(o) != 0 {
		length := int(C.PyTuple_Size(o))
		list := make([]interface{}, length)
		for i := 0; i < length; i++ {
			list[i] = pyObjToInterface(C.PyTuple_GetItem(o, C.Py_ssize_t(i)))
		}
		return list
	}
	return nil
}
コード例 #2
0
ファイル: dict.go プロジェクト: gbbr/textmate
// Items returns a *List containing all the items from the dictionary d, as with
// the Python "d.items()".
//
// Return value: New Reference.
func (d *Dict) Items() (*List, error) {
	ret := C.PyDict_Items(c(d))
	return newList(ret), exception()
}
コード例 #3
0
ファイル: dict.go プロジェクト: remh/go-python
// PyObject* PyDict_Items(PyObject *p)
// Return value: New reference.
// Return a PyListObject containing all the items from the dictionary, as in the dictionary method dict.items().
func PyDict_Items(self *PyObject) *PyObject {
	return togo(C.PyDict_Items(topy(self)))
}