2
2
Class isc .py .gw .DynamicObject Extends %RegisteredObject
3
3
{
4
4
5
- Property %Name As %String (MAXLEN = 1000 );
5
+ /// Name of python variable holding the object
6
+ Property %Variable As %String (MAXLEN = 1000 );
6
7
8
+ /// Python type
7
9
Property %Type As %String (MAXLEN = 1000 );
8
10
11
+ /// Default serialization for methods
9
12
Property %Serialization As %Integer ;
10
13
11
14
/// do ##class(isc.py.init.Test).Initialize(,1)
@@ -16,21 +19,32 @@ Property %Serialization As %Integer;
16
19
/// w obj.age
17
20
/// w obj.getAge()
18
21
/// w obj.getAgePlus(10)
19
- Method %OnNew (type , variable , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, args ...) As %Status [ Private , ServerOnly = 1 ]
22
+ Method %OnNew (type As %String = " " , variable As %String , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, args ...) As %Status [ Private , ServerOnly = 1 ]
20
23
{
21
- set ..%Name = variable
22
- set ..%Type = type
24
+ set ..%Variable = variable
23
25
set ..%Serialization = serialization
24
- quit ##class (isc.py.Main ).ExecuteFunctionArgs (type , variable ,,, args ...)
26
+
27
+ if type '=" " {
28
+ // Create variable of type
29
+ set ..%Type = type
30
+ set sc = ##class (isc.py.Main ).ExecuteFunctionArgs (type , variable ,,, args ...)
31
+ } else {
32
+ // Populate variable info
33
+ set sc = ##class (isc.py.Main ).GetVariableInfo (variable , ,.defined , .type )
34
+ throw :'defined ##class (%Exception.General ).%New (" <VARIABLE>" , variable )
35
+ set ..%Type = $g (type )
36
+ }
37
+
38
+ quit sc
25
39
}
26
40
27
41
/// Get serialized property value
28
42
Method %DispatchGetProperty (property As %String ) [ ServerOnly = 1 ]
29
43
{
30
- $$$TOE(sc , ##class (isc.py.Main ).GetVariableInfo (..%Name _ " ." _ property , ..%Serialization , .defined , .type , .length ))
44
+ $$$TOE(sc , ##class (isc.py.Main ).GetVariableInfo (..%Variable _ " ." _ property , ..%Serialization , .defined , .type , .length ))
31
45
throw :'defined ##class (%Exception.General ).%New (" <PROPERTY>" , property )
32
46
33
- $$$TOE(sc , ##class (isc.py.Main ).SimpleString (" zzzproperty=" _ ..%Name _ " ." _ property , " zzzproperty" , ..%Serialization , .zzzproperty ))
47
+ $$$TOE(sc , ##class (isc.py.Main ).SimpleString (" zzzproperty=" _ ..%Variable _ " ." _ property , " zzzproperty" , ..%Serialization , .zzzproperty ))
34
48
$$$TOE(sc , ##class (isc.py.Main ).SimpleString (" del zzzproperty" ))
35
49
36
50
quit zzzproperty
@@ -39,20 +53,52 @@ Method %DispatchGetProperty(property As %String) [ ServerOnly = 1 ]
39
53
/// Set python object property
40
54
Method %DispatchSetProperty (property As %String , val ) [ ServerOnly = 1 ]
41
55
{
42
- $$$TOE(sc , ##class (isc.py.Main ).GetVariableInfo (..%Name _ " ." _ property , ..%Serialization , .defined , .type , .length ))
56
+ $$$TOE(sc , ##class (isc.py.Main ).GetVariableInfo (..%Variable _ " ." _ property , ..%Serialization , .defined , .type , .length ))
43
57
throw :'defined ##class (%Exception.General ).%New (" <PROPERTY>" , property )
44
58
45
- set arguments = $lb (..%Name , ##class (isc.py.util.Converter ).EscapeString (property ), ##class (isc.py.util.Converter ).EscapeString (val ))
59
+ set arguments = $lb (..%Variable , ##class (isc.py.util.Converter ).EscapeString (property ), ##class (isc.py.util.Converter ).EscapeString (val ))
46
60
47
61
$$$TOE(sc , ##class (isc.py.Main ).ExecuteFunction (" setattr" , arguments ))
48
62
}
49
63
50
64
/// Call python function
51
65
Method %DispatchMethod (method As %String , args ...) [ ServerOnly = 1 ]
52
66
{
53
- $$$TOE(sc , ##class (isc.py.Main ).ExecuteFunctionArgs (..%Name _ " ." _ method , ,..%Serialization , .result , args ...))
67
+ $$$TOE(sc , ##class (isc.py.Main ).ExecuteFunctionArgs (..%Variable _ " ." _ method , ,..%Serialization , .result , args ...))
54
68
quit result
55
69
}
56
70
71
+ /// Convert Python object to JSON
72
+ Method %ToJSON (ByRef stream As %Stream .Object , useString As %Boolean = {$$$NO}) As %Status [ CodeMode = expression ]
73
+ {
74
+ ##class (isc.py.Main ).GetVariableJson (..%Variable , .stream , useString )
75
+ }
76
+
77
+ /// Convert Python object to InterSystems IRIS Dynamic object
78
+ Method %ToDynObj (Output obj As %DynamicObject ) As %Status
79
+ {
80
+ set sc = ..%ToJSON (.stream )
81
+ quit :$$$ISERR(sc ) sc
82
+ try {
83
+ set obj = {}.%FromJSON (stream )
84
+ } catch ex {
85
+ set sc = ex .AsStatus ()
86
+ }
87
+
88
+ quit sc
89
+ }
90
+
91
+ /// Convert Python object to Pickle or Dill
92
+ Method %ToPickle (ByRef stream As %Stream .Object , useString As %Boolean = {$$$NO}, useDill As %Boolean = {$$$NO}) As %Status [ CodeMode = expression ]
93
+ {
94
+ ##class (isc.py.Main ).GetVariablePickle (..%Variable , .stream , useString , useDill )
95
+ }
96
+
97
+ /// Convert Python object to string
98
+ Method %ToStream (serialization As %Integer = {..%Serialization }, ByRef stream As %Stream .Object , useString As %Boolean = {$$$NO}) As %Status [ CodeMode = expression ]
99
+ {
100
+ ##class (isc.py.Main ).GetVariable (..%Variable , serialization , .stream , useString )
101
+ }
102
+
57
103
}
58
104
0 commit comments