MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / GetSlice

Method GetSlice

pkg/filament/cpython/object.go:81–117  ·  view source on GitHub ↗

GetSlice returns the nth argument as a slice of generic values.

(n uint8)

Source from the content-addressed store, hash-verified

79
80// GetSlice returns the nth argument as a slice of generic values.
81func (args PyArgs) GetSlice(n uint8) ([]interface{}, error) {
82 ob := C.PyArg_ParseList((*C.PyObject)(unsafe.Pointer(args)), C.int(n))
83 if ob == nil {
84 return nil, errTypeNotList
85 }
86 l := int(C.PyList_Size(ob))
87 if l < 0 {
88 return nil, nil
89 }
90 s := make([]interface{}, l)
91 for i := 0; i < l; i++ {
92 item := C.PyList_GetItem(ob, C.longlong(i))
93 if item == nil {
94 continue
95 }
96 switch {
97 case bool(C.Py_IsUnicode(item)):
98 s[i] = fromRawOb(item).String()
99 case bool(C.Py_IsInteger(item)):
100 s[i] = fromRawOb(item).Int()
101 case bool(C.Py_IsDateTime(item)):
102 s[i] = fromRawOb(item).Time()
103 default:
104 if ipv4Class != nil {
105 if !ipv4Class.IsNull() && C.PyObject_IsInstance(item, ipv4Class.rawptr) > 0 {
106 s[i] = net.ParseIP(fromRawOb(item).String())
107 }
108 }
109 if ipv6Class != nil {
110 if !ipv6Class.IsNull() && C.PyObject_IsInstance(item, ipv6Class.rawptr) > 0 {
111 s[i] = net.ParseIP(fromRawOb(item).String())
112 }
113 }
114 }
115 }
116 return s, nil
117}
118
119// PyArgsParseKeywords parses tuple and keywords arguments.
120func PyArgsParseKeywords(args PyArgs, kwargs PyKwargs, kwlist []string) (string, string, string, []string) {

Callers 2

GetMethod · 0.45
addRowFnMethod · 0.45

Calls 5

fromRawObFunction · 0.85
IntMethod · 0.80
TimeMethod · 0.80
IsNullMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected