Esempio n. 1
0
 def to_portable_primitive(self, val):
     if self.subfield:
         ret = list()
         if val is None:
             return ret
         for item in val:
             ret.append(self.subfield.to_portable_primitive(item))
         #run data through the primitive processor
         return PRIMITIVE_PROCESSOR.to_primitive(ret)
     return PRIMITIVE_PROCESSOR.to_primitive(val)
Esempio n. 2
0
 def to_python(self, val, parent=None):
     if self.subfield:
         ret = DotPathSet()
         if val is None:
             return ret
         #TODO pass in parent
         for item in val:
             if not self.subfield.is_instance(item):
                 item = self.subfield.to_python(item)
             ret.add(item)
         #run data through the primitive processor
         return PRIMITIVE_PROCESSOR.to_python(ret)
     return PRIMITIVE_PROCESSOR.to_python(val)
Esempio n. 3
0
 def __getitem__(self, key):
     assert isinstance(key, basestring)
     if key in self._meta.fields:
         return getattr(self, key)
     if key in self._primitive_data and key not in self._python_data:
         from serializer import PRIMITIVE_PROCESSOR
         r_val = self._primitive_data[key]
         p_val = PRIMITIVE_PROCESSOR.to_python(r_val)
         self._python_data[key] = p_val
     return self._python_data[key]
Esempio n. 4
0
 def to_portable_primitive(self, val):
     ret = dict()
     if val is None:
         return ret
     for key, value in val.iteritems():
         if hasattr(value, 'to_portable_primitive'):
             value = type(value).to_portable_primitive(value)
         if hasattr(key, 'to_portable_primitive'):
             key = type(key).to_portable_primitive(key)
         ret[key] = value
     #TODO run data through the primitive processor
     ret = PRIMITIVE_PROCESSOR.to_primitive(ret)
     return ret
Esempio n. 5
0
 def to_python(self, val, parent=None):
     ret = DotPathDict()
     if val is None:
         return ret
     for key, value in val.iteritems():
         if self.value_subfield:
             if not self.value_subfield.is_instance(value):
                 value = self.value_subfield.to_python(value)
         if self.key_subfield:
             if not self.key_subfield.is_instance(key):
                 key = self.key_subfield.to_python(key)
         ret[key] = value
     #TODO run data through the primitive processor
     ret = PRIMITIVE_PROCESSOR.to_python(ret)
     return ret