You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Gateway.md
+120-6Lines changed: 120 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,22 +6,39 @@ There are three main parts:
6
6
- Proxyless Gateway
7
7
- Proxy Gateway
8
8
9
-
10
9
# Execute function
11
10
12
-
Consists of `ExecuteFunction` method from `isc.py.Main` class. Signature:
13
-
-`function` - name of function to invoke. Can be nested, i.e. `random.randint`
11
+
Executes function by name. This API consists of two methods:
12
+
-`ExecuteFunction`
13
+
-`ExecuteFunctionArgs`
14
+
15
+
The difference between them is caller signature. `ExecuteFunction` accepts %List, %Collection.AbstractArray and JSON object separated into positional and keyword arguments. `ExecuteFunctionArgs` accepts `args...` and parses them into positional and keyword arguments. After that `ExecuteFunctionArgs` calls `ExecuteFunction`.
16
+
17
+
It is caller responsibility to escape argument values. Use `isc.py.util.Converter` class to escape:
18
+
- string
19
+
- boolean
20
+
- date
21
+
- time
22
+
- timestamp
23
+
24
+
## ExecuteFunction
25
+
26
+
`ExecuteFunction` method from `isc.py.Main` class. Signature:
27
+
-`function` - name of function to invoke. Can be nested, i.e. `random.randint`
28
+
-`variable` - name of python variable to write result to.
14
29
-`positionalArguments` - positional argumets for Python function. Can be one of:
15
30
+`$lb(val1, val2, ..., valN)`
16
31
+`%Collection.AbstractIterator` object
17
32
+ JSON array
18
-
- keywordArguments - keyword argumets for Python function. Can be one of:
33
+
-`keywordArguments` - keyword argumets for Python function. Can be one of:
set sc = ##class(isc.py.Main).ExecuteFunction(random _ ".randint", ,kwArguments,,.result)
50
-
51
66
write result,!
52
67
}
53
68
@@ -62,3 +77,102 @@ set kwDynamic = {"name":(##class(isc.py.util.Converter).EscapeString("Alice")),
62
77
set sc = ##class(isc.py.Main).ExecuteFunction("str.format", posList, kwDynamic,,.result)
63
78
write result,!
64
79
```
80
+
81
+
## ExecuteFunctionArgs
82
+
83
+
`ExecuteFunctionArgs` method from `isc.py.Main` class. Signature:
84
+
-`function` - name of function to invoke. Can be nested, i.e. `random.randint`
85
+
-`variable` - name of python variable to write result to.
86
+
-`serialization` - how to serialize result
87
+
-`result` - write result into this variable
88
+
-`args...` - function arguments.
89
+
90
+
`ExecuteFunctionArgs` attempts to determine correct positional and keyword arguments from function signature (if available). It is recommended to call `ExecuteFunction` directly if `ExecuteFunctionArgs` is unable to construct a correct argument spec (and open an issue). Example:
91
+
92
+
```
93
+
set sc = ##class(isc.py.Main).ImportModule("random", ,.random)
94
+
set sc = ##class(isc.py.Main).ExecuteFunctionArgs(random _ ".randint", , ,.result, 1, 100)
95
+
write result,!
96
+
97
+
set string = ##class(isc.py.util.Converter).EscapeString("Positional: {0}, {1}, {2}, {3}")
98
+
set arg1 = ##class(isc.py.util.Converter).EscapeString("Hello")
99
+
set arg2 = ##class(isc.py.util.Converter).EscapeString("World")
100
+
set arg3 = ##class(isc.py.util.Converter).EscapeString("Alice")
101
+
set arg4 = ##class(isc.py.util.Converter).EscapeString("Bob")
102
+
set sc = ##class(isc.py.Main).ExecuteFunctionArgs("str.format",,,.result, string, arg1, arg2, arg3, arg4)
103
+
write result,!
104
+
105
+
set string = ##class(isc.py.util.Converter).EscapeString("Positional: {0} {1}! Keyword: {name}, {name2}")
106
+
set arg1 = ##class(isc.py.util.Converter).EscapeString("Hello")
107
+
set arg2 = ##class(isc.py.util.Converter).EscapeString("World")
108
+
set kwargs = "**" _ {"name":"Alice","name2":"Bob"}.%ToJSON()
109
+
set sc = ##class(isc.py.Main).ExecuteFunctionArgs("str.format",,, .result, string, arg1, arg2, kwargs)
110
+
write result,!
111
+
```
112
+
113
+
# Proxyless Gateway
114
+
115
+
Proxyless gateway allows user to bind Python variables to InterSystems IRIS variables.
In this call we create Python variable `p1` of `Person` class and pass three methods to constructor `'Ed'`, `25` and `'Test'`.
140
+
141
+
3. Now we can interact with the object, let's get and set some properties:
142
+
```
143
+
write obj.name
144
+
set obj.name="Bob"
145
+
write obj.name
146
+
write obj.age
147
+
```
148
+
4. We can set some new properties too (unlike `ExecuteFunction` values are escaped automatically if `%EscapeOnSet` property is 1, which is default. You can also set properties to other dynamic objects. In that case unsecaped python variable name would be used):
149
+
```
150
+
set obj.pet = "Dog"
151
+
write obj.pet
152
+
```
153
+
154
+
5. And we can call object methods:
155
+
156
+
```
157
+
write obj.getAge()
158
+
write obj.getAgePlus(10)
159
+
```
160
+
161
+
6. Finally we can convert object:
162
+
```
163
+
set sc = obj.%ToJSON(.json)
164
+
set sc = obj.%ToDynObj(.dynObj)
165
+
set sc = obj.%ToPickle(.pickle)
166
+
set sc = obj.%ToStream(,.stream)
167
+
```
168
+
169
+
To create proxy object from existing proxy object just skip type argument:
170
+
```
171
+
kill obj
172
+
set p1 = ##class(isc.py.gw.DynamicObject).%New(, "p1")
0 commit comments