2
2
Class isc .py .data .Variable Extends %Persistent
3
3
{
4
4
5
+ Parameter DisplayLimit = 100 ;
6
+
5
7
/// Variable Name
6
8
Property Name As %String ;
7
9
8
10
/// Variable Class
9
11
Property Type As %String ;
10
12
11
13
/// Variable repr serialization
12
- Property Value As %VarString ;
14
+ Property Value As %Stream . GlobalCharacter ;
13
15
14
16
/// Variable pickle serialization
15
- Property Pickle As %VarString ;
17
+ Property Pickle As %Stream . GlobalCharacter ;
16
18
17
19
/// Variable JSON serialization
18
- Property JSON As %VarString ;
20
+ Property JSON As %Stream . GlobalCharacter ;
19
21
20
22
/// Save variable on disk.
21
23
/// zw ##class(isc.py.data.Variable).SaveVariable()
22
- ClassMethod SaveVariable (name As %String = " " , Output variable As isc .py .data .Variable ) As %Status
24
+ ClassMethod SaveVariable (variable As %String = " " , Output obj As isc .py .data .Variable ) As %Status
23
25
{
24
- kill variable
25
- quit :name =" " $$$ERROR($$$GeneralError, " Variable name can't be empty" )
26
-
27
- set repr = ##class (isc.py.Callout ).SimpleString (,name , 1 )
28
- quit :repr =" " $$$ERROR($$$GeneralError, $$$FormatText(" Variable %1 is empty or initialized" , name ))
26
+ #include Ensemble
27
+ kill obj
28
+ quit :variable =" " $$$ERROR($$$GeneralError, " Variable name can't be empty" )
29
29
30
- set type = ##class (isc.py.Callout ).SimpleString (" zzztype=type(" _name _" ).__name__" , " zzztype" )
31
- do ##class (isc.py.Callout ).SimpleString (" import json, pickle;" )
30
+ //$$$TRACE(variable)
32
31
33
- if type = " DataFrame" {
34
- set json = ##class (isc.py.Callout ).SimpleString (" zzzjson=" _name _ " .to_json()" , " zzzjson" )
35
- } elseif type =" DatetimeIndex" {
36
- /// TODO
37
- } else {
38
- set json = ##class (isc.py.Callout ).SimpleString (" zzzjson=json.dumps(" _name _ " )" , " zzzjson" )
39
- }
32
+ set sc = ##class (isc.py.Main ).GetVariableInfo (variable , ##class (isc.py.Callout ).#SerializationRepr, .defined , .type , .length )
33
+ quit :$$$ISERR(sc ) sc
34
+ quit :'defined $$$ERROR($$$GeneralError, " Variable '" _ variable _ " ' is not defined" )
40
35
41
- set pickle = ##class (isc.py.Callout ).SimpleString (" zzzjson=pickle.dumps(" _name _ " )" , " zzzjson" )
36
+ #dim repr , pickle, json As %Stream.GlobalCharacter
37
+
38
+ set sc = ##class (isc.py.Main ).GetVariable (variable , ##class (isc.py.Callout ).#SerializationRepr, .repr )
39
+ quit :$$$ISERR(sc ) sc
42
40
41
+ set sc = ##class (isc.py.Main ).GetVariableJson (variable , .json )
42
+ quit :$$$ISERR(sc ) sc
43
43
44
- do ##class (isc.py.Callout ).SimpleString (" del zzztype, zzzjson" )
44
+ set sc = ##class (isc.py.Main ).GetVariablePickle (variable , .pickle )
45
+ quit :$$$ISERR(sc ) sc
45
46
46
- set variable = ..%New ()
47
- set variable .Name = name
48
- set variable .Value = repr
49
- set variable .Type = type
50
- set variable .Pickle = pickle
51
- set variable .JSON = $g ( json )
52
- set sc = variable .%Save ()
47
+ set obj = ..%New ()
48
+ set obj .Name = variable
49
+ set obj .Value = repr
50
+ set obj .Type = type
51
+ set obj .Pickle = pickle
52
+ set obj .JSON = json
53
+ set sc = obj .%Save ()
53
54
54
55
quit sc
55
56
}
@@ -58,21 +59,24 @@ ClassMethod SaveVariable(name As %String = "", Output variable As isc.py.data.Va
58
59
Method Display (indent As %String = " " )
59
60
{
60
61
write indent , " Name: " , ..Name , !
61
- write indent , " Type: " , ..Type , !
62
- set limit = 100
63
- If $l (..Value )<=limit {
64
- Write indent , " Value: " , ..Value , !
65
- } Else {
66
- Write indent , " Value (truncated): " , $replace ($e (..Value ,1 ,limit ),$c (10 ), $c (13 ,10 )), !
67
- }
68
- write !
62
+ write indent , " Type: " , ..Type , !
63
+ write indent , " Value" , $case (..Value .Size <=..#DisplayLimit, $$$YES:" " , $$$NO:" (truncated)" ), " : " , ..Value .Read (..#DisplayLimit), !, !
69
64
}
70
65
71
66
/// Restore variable from disk.
72
67
/// context - variable owner Python context object.
73
- Method Restore (context As isc .py .data .Context )
68
+ Method Restore (context As isc .py .data .Context ) As %Status
74
69
{
75
- do ##class (isc.py.Callout ).SimpleString (..Name _ " =" _ context .%PickleAlias _ " .loads(" _ ..Pickle _ " )" )
70
+ #dim sc As %Status = $$$OK
71
+ if ..Pickle .Size > 0 {
72
+ set stream = ##class (%Stream.TmpCharacter ).%New ()
73
+ do stream .Write (context .%PickleAlias _ " .loads(" )
74
+ do stream .CopyFrom (..Pickle )
75
+ do stream .Write (" )" )
76
+ set sc = ##class (isc.py.Main ).ExcuteCode (stream , ..Name )
77
+ }
78
+
79
+ quit sc
76
80
}
77
81
78
82
Storage Default
0 commit comments