11
11
from ..transporters .general_data_structure_transporter import GeneralDataStructureTransporter
12
12
13
13
14
- class Mode (Enum ):
15
- """fallback state of the PyMiloClient."""
16
-
17
- LOCAL = 1
18
- DELEGATE = 2
19
-
20
-
21
14
class PymiloClient :
22
15
"""Facilitate working with the PyMilo server."""
23
16
17
+ class Mode (Enum ):
18
+ """fallback state of the PyMiloClient."""
19
+
20
+ LOCAL = 1
21
+ DELEGATE = 2
22
+
24
23
def __init__ (
25
24
self ,
26
25
model = None ,
@@ -41,9 +40,9 @@ def __init__(
41
40
:type server_url: str
42
41
:return: an instance of the Pymilo PymiloClient class
43
42
"""
44
- self ._client_id = "0x_client_id"
45
- self ._model_id = "0x_model_id "
46
- self ._model = model
43
+ self .model = model
44
+ self .client_id = "0x_client_id "
45
+ self .model_id = "0x_model_id"
47
46
self ._mode = mode
48
47
self ._compressor = compressor .value
49
48
self ._encryptor = DummyEncryptor ()
@@ -69,7 +68,7 @@ def toggle_mode(self, mode=Mode.LOCAL):
69
68
70
69
:return: None
71
70
"""
72
- if mode not in Mode .__members__ .values ():
71
+ if mode not in PymiloClient . Mode .__members__ .values ():
73
72
raise Exception (PYMILO_CLIENT_INVALID_MODE )
74
73
if mode != self ._mode :
75
74
self ._mode = mode
@@ -83,15 +82,15 @@ def download(self):
83
82
serialized_model = self ._communicator .download (
84
83
self .encrypt_compress (
85
84
{
86
- "client_id" : self ._client_id ,
87
- "model_id" : self ._model_id ,
85
+ "client_id" : self .client_id ,
86
+ "model_id" : self .model_id ,
88
87
}
89
88
)
90
89
)
91
90
if serialized_model is None :
92
91
print (PYMILO_CLIENT_FAILED_TO_DOWNLOAD_REMOTE_MODEL )
93
92
return
94
- self ._model = Import (file_adr = None , json_dump = serialized_model ).to_model ()
93
+ self .model = Import (file_adr = None , json_dump = serialized_model ).to_model ()
95
94
print (PYMILO_CLIENT_MODEL_SYNCHED )
96
95
97
96
def upload (self ):
@@ -103,9 +102,9 @@ def upload(self):
103
102
succeed = self ._communicator .upload (
104
103
self .encrypt_compress (
105
104
{
106
- "client_id" : self ._client_id ,
107
- "model_id" : self ._model_id ,
108
- "model" : Export (self ._model ).to_json (),
105
+ "client_id" : self .client_id ,
106
+ "model_id" : self .model_id ,
107
+ "model" : Export (self .model ).to_json (),
109
108
}
110
109
)
111
110
)
@@ -123,18 +122,18 @@ def __getattr__(self, attribute):
123
122
124
123
:return: Any
125
124
"""
126
- if self ._mode == Mode .LOCAL :
127
- if attribute in dir (self ._model ):
128
- return getattr (self ._model , attribute )
125
+ if self ._mode == PymiloClient . Mode .LOCAL :
126
+ if attribute in dir (self .model ):
127
+ return getattr (self .model , attribute )
129
128
else :
130
129
raise AttributeError (PYMILO_CLIENT_INVALID_ATTRIBUTE )
131
- elif self ._mode == Mode .DELEGATE :
130
+ elif self ._mode == PymiloClient . Mode .DELEGATE :
132
131
gdst = GeneralDataStructureTransporter ()
133
132
response = self ._communicator .attribute_type (
134
133
self .encrypt_compress (
135
134
{
136
- "client_id" : self ._client_id ,
137
- "model_id" : self ._model_id ,
135
+ "client_id" : self .client_id ,
136
+ "model_id" : self .model_id ,
138
137
"attribute" : attribute ,
139
138
}
140
139
)
@@ -144,8 +143,8 @@ def __getattr__(self, attribute):
144
143
145
144
def relayer (* args , ** kwargs ):
146
145
payload = {
147
- "client_id" : self ._client_id ,
148
- "model_id" : self ._model_id ,
146
+ "client_id" : self .client_id ,
147
+ "model_id" : self .model_id ,
149
148
'attribute' : attribute ,
150
149
'args' : args ,
151
150
'kwargs' : kwargs ,
0 commit comments