Skip to content

Commit 07568c3

Browse files
committed
Proxyless Gateway: proxy object now accepts and returns proxy objects for Property Set and Method call.
1 parent 7d4a8d9 commit 07568c3

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

isc/py/gw/DynamicObject.cls

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ Property %Type As %String(MAXLEN = 1000);
1111
/// Default serialization for methods
1212
Property %Serialization As %Integer;
1313

14+
/// Automatically escape values on property set
1415
Property %EscapeOnSet As %Boolean [ InitialExpression = {$$$YES} ];
1516

17+
/// Automatically escape values on method call
18+
Property %EscapeOnCall As %Boolean [ InitialExpression = {$$$NO} ];
19+
1620
/// do ##class(isc.py.init.Test).Initialize(,1)
1721
/// set obj = ##class(isc.py.gw.DynamicObject).%New("Person", "p1", , "'Ed'", "25", "'Test'")
1822
/// w obj.name
@@ -46,8 +50,12 @@ Method %DispatchGetProperty(property As %String) [ ServerOnly = 1 ]
4650
$$$TOE(sc, ##class(isc.py.Main).GetVariableInfo(..%Variable _ "." _ property, ..%Serialization, .defined, .type, .length))
4751
throw:'defined ##class(%Exception.General).%New("<PROPERTY>", property)
4852

49-
$$$TOE(sc, ##class(isc.py.Main).SimpleString("zzzproperty=" _ ..%Variable _ "." _ property, "zzzproperty", ..%Serialization, .zzzproperty))
50-
$$$TOE(sc, ##class(isc.py.Main).SimpleString("del zzzproperty"))
53+
if ..%IsPrimitive(type) = $$$YES {
54+
$$$TOE(sc, ##class(isc.py.Main).SimpleString("zzzproperty=" _ ..%Variable _ "." _ property, "zzzproperty", ..%Serialization, .zzzproperty))
55+
$$$TOE(sc, ##class(isc.py.Main).SimpleString("del zzzproperty"))
56+
} else {
57+
set zzzproperty = ..%New(, ..%Variable _ "." _ property)
58+
}
5159

5260
quit zzzproperty
5361
}
@@ -65,27 +73,37 @@ Method %DispatchSetProperty(property As %String, val) [ ServerOnly = 1 ]
6573
} else {
6674
set value = val
6775
}
68-
set arguments = $lb(..%Variable,##class(isc.py.util.Converter).EscapeString(property), value)
76+
set arguments = $lb(..%Variable, ##class(isc.py.util.Converter).EscapeString(property), value)
6977

7078
$$$TOE(sc, ##class(isc.py.Main).ExecuteFunction("setattr", arguments))
7179
}
7280

73-
/// Call python function
81+
/// Call python method
7482
Method %DispatchMethod(method As %String, args...) [ ServerOnly = 1 ]
7583
{
7684
for i=1:1:$g(args) {
7785
set val = args(i)
7886
if ($isObject(val) && val.%Extends("isc.py.gw.DynamicObject")) {
7987
set value = val.%Variable
80-
} elseif (..%EscapeOnSet) {
88+
} elseif (..%EscapeOnCall) {
8189
set value = ##class(isc.py.util.Converter).EscapeString(val)
8290
} else {
8391
set value = val
8492
}
8593

8694
set args(i) = value
8795
}
88-
$$$TOE(sc, ##class(isc.py.Main).ExecuteFunctionArgs(..%Variable _ "." _ method, ,..%Serialization, .result, args...))
96+
97+
set variable = "variable" _ $random(100000000)
98+
99+
$$$TOE(sc, ##class(isc.py.Main).ExecuteFunctionArgs(..%Variable _ "." _ method, variable ,..%Serialization, .result, args...))
100+
101+
$$$TOE(sc, ##class(isc.py.Main).GetVariableInfo(variable, , .defined, .type))
102+
103+
if ..%IsPrimitive(type) = $$$NO {
104+
set result = ..%New(,variable)
105+
}
106+
89107
quit result
90108
}
91109

@@ -126,5 +144,37 @@ Method %Destroy() [ CodeMode = expression ]
126144
##class(isc.py.Main).SimpleString("del " _ ..%Variable)
127145
}
128146

147+
/// Get object as serialized string
148+
Method %GetString(serialization As %Integer = {..%Serialization}) As %String
149+
{
150+
set sc = ..%ToStream(serialization, .stream, $$$YES)
151+
quit:$$$ISERR(sc) ""
152+
if $isObject(stream) {
153+
set stream = stream.Read($$$MaxStringLength)
154+
}
155+
156+
quit stream
157+
}
158+
159+
/// Get object as serialized JSON string
160+
Method %GetJSON() As %String
161+
{
162+
set sc = ..%ToJSON(.stream, $$$YES)
163+
quit:$$$ISERR(sc) ""
164+
if $isObject(stream) {
165+
set stream = stream.Read($$$MaxStringLength)
166+
}
167+
168+
quit stream
169+
}
170+
171+
/// Primitive types are returned serialized.
172+
/// For non-primitive types ProxyObject is returned.
173+
ClassMethod %IsPrimitive(type As %String) As %Boolean
174+
{
175+
quit:$lf($lb("str", "int", "bool", "float"), type)>0 $$$YES
176+
quit $$$NO
177+
}
178+
129179
}
130180

0 commit comments

Comments
 (0)