##// END OF EJS Templates
Change serialization terminology to serialize/deserialize
Jason Grout -
Show More
@@ -197,7 +197,7 b' class Widget(LoggingConfigurable):'
197 keys = self.keys if key is None else [key]
197 keys = self.keys if key is None else [key]
198 state = {}
198 state = {}
199 for k in keys:
199 for k in keys:
200 f = self.trait_metadata(k, 'to_json')
200 f = self.trait_metadata(k, 'serialize')
201 value = getattr(self, k)
201 value = getattr(self, k)
202 if f is not None:
202 if f is not None:
203 state[k] = f(value)
203 state[k] = f(value)
@@ -288,11 +288,11 b' class Widget(LoggingConfigurable):'
288 """Called when a state is received from the front-end."""
288 """Called when a state is received from the front-end."""
289 for name in self.keys:
289 for name in self.keys:
290 if name in sync_data:
290 if name in sync_data:
291 f = self.trait_metadata(name, 'from_json')
291 f = self.trait_metadata(name, 'deserialize')
292 if f is not None:
292 if f is not None:
293 value = f(sync_data[name])
293 value = f(sync_data[name])
294 else:
294 else:
295 value = self._unserialize_trait(sync_data[name])
295 value = self._deserialize_trait(sync_data[name])
296 with self._lock_property(name, value):
296 with self._lock_property(name, value):
297 setattr(self, name, value)
297 setattr(self, name, value)
298
298
@@ -326,15 +326,15 b' class Widget(LoggingConfigurable):'
326 else:
326 else:
327 return x # Value must be JSON-able
327 return x # Value must be JSON-able
328
328
329 def _unserialize_trait(self, x):
329 def _deserialize_trait(self, x):
330 """Convert json values to objects
330 """Convert json values to objects
331
331
332 We explicitly support converting valid string widget UUIDs to Widget references.
332 We explicitly support converting valid string widget UUIDs to Widget references.
333 """
333 """
334 if isinstance(x, dict):
334 if isinstance(x, dict):
335 return {k: self._unserialize_trait(v) for k, v in x.items()}
335 return {k: self._deserialize_trait(v) for k, v in x.items()}
336 elif isinstance(x, (list, tuple)):
336 elif isinstance(x, (list, tuple)):
337 return [self._unserialize_trait(v) for v in x]
337 return [self._deserialize_trait(v) for v in x]
338 elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
338 elif isinstance(x, string_types) and x.startswith('IPY_MODEL_') and x[10:] in Widget.widgets:
339 # we want to support having child widgets at any level in a hierarchy
339 # we want to support having child widgets at any level in a hierarchy
340 # trusting that a widget UUID will not appear out in the wild
340 # trusting that a widget UUID will not appear out in the wild
General Comments 0
You need to be logged in to leave comments. Login now