@@ -21,6 +21,12 @@ Parameter SimpleStringFull As Integer = 5;
21
21
22
22
Parameter SimpleString As Integer = 6 ;
23
23
24
+ Parameter StreamInit As Integer = 7 ;
25
+
26
+ Parameter StreamWrite As Integer = 8 ;
27
+
28
+ Parameter StreamExecute As Integer = 9 ;
29
+
24
30
/// Get path to the shared library file.
25
31
/// Library file is assumed to be in a bin folder, unless specified otherwise in ^isc.py.Callout global.
26
32
/// write ##class(isc.py.Callout).GetLib()
@@ -95,6 +101,63 @@ ClassMethod SimpleString(code As %String = "", variable As %String = "", seriali
95
101
quit result
96
102
}
97
103
104
+ /// Init incoming Stream
105
+ /// write ##class(isc.py.Callout).StreamInit()
106
+ ClassMethod StreamInit (length As %Integer ) As %Status
107
+ {
108
+ #dim sc As %Status = $$$OK
109
+ try {
110
+ do $ZF (-6 , ..#PyLibId, ..#StreamInit, length )
111
+ } catch ex {
112
+ #dim ex As %Exception.General
113
+ if (ex .Name = " <FUNCTION>" ) {
114
+ set sc = $$$ERROR($$$GeneralError, " Unable to allocate memory" )
115
+ } else {
116
+ set sc = ex .AsStatus ()
117
+ }
118
+ }
119
+
120
+ quit sc
121
+ }
122
+
123
+ /// Write piece into incoming Stream
124
+ /// write ##class(isc.py.Callout).StreamWrite()
125
+ ClassMethod StreamWrite (code As %String = " " ) As %Status
126
+ {
127
+ #dim sc As %Status = $$$OK
128
+ try {
129
+ do $ZF (-6 , ..#PyLibId, ..#StreamWrite, code )
130
+ } catch ex {
131
+ #dim ex As %Exception.General
132
+ if (ex .Name = " <FUNCTION>" ) {
133
+ set sc = $$$ERROR($$$GeneralError, " Call StreamInit before calling StreamWrite. Or attempted to write into stream more than allocated data." )
134
+ } else {
135
+ set sc = ex .AsStatus ()
136
+ }
137
+ }
138
+
139
+ quit sc
140
+ }
141
+
142
+ /// Send incoming stream to Python for execution and free it.
143
+ /// write ##class(isc.py.Callout).StreamExecute()
144
+ ClassMethod StreamExecute () As %Status
145
+ {
146
+ #dim sc As %Status = $$$OK
147
+ try {
148
+ do $ZF (-6 , ..#PyLibId, ..#StreamExecute)
149
+ } catch ex {
150
+ #dim ex As %Exception.General
151
+ if (ex .Name = " <FUNCTION>" ) {
152
+ set sc = $$$ERROR($$$GeneralError, " Call StreamInit and StreamWrite before calling StreamExecute" )
153
+ } else {
154
+ set sc = ex .AsStatus ()
155
+ }
156
+ }
157
+
158
+ quit sc
159
+ }
160
+
98
161
/// Finalize Python. Idempotent.
99
162
/// do ##class(isc.py.Callout).Finalize()
100
163
ClassMethod Finalize () As %Integer
@@ -110,21 +173,5 @@ ClassMethod Unload() As %Integer
110
173
quit result
111
174
}
112
175
113
- /// Returns last occured exception in Python and clears it
114
- /// write ##class(isc.py.Callout).GetStatus()
115
- ClassMethod GetStatus () As %Status
116
- {
117
- do ##class (isc.py.Callout ).SimpleString (" import sys, traceback" )
118
- set haxExc = ##class (isc.py.Callout ).SimpleString (" zzzerr = hasattr(sys, 'last_type')" , " zzzerr" )
119
-
120
- quit :haxExc =" False" $$$OK
121
-
122
- set excText = ##class (isc.py.Callout ).SimpleString (" zzzerr = traceback.format_exception(sys.last_type, sys.last_value, sys.last_traceback)" , " zzzerr" )
123
- set excText = $zcvt ($zcvt (excText , " I" , " UTF8" ), " I" , " JSON" )
124
- do ##class (isc.py.Callout ).SimpleString (" del zzzerr, sys.last_type, sys.last_value, sys.last_traceback" )
125
-
126
- quit $$$ERROR($$$GeneralError, excText )
127
- }
128
-
129
176
}
130
177
0 commit comments