Exemple #1
0
    def decode_value(self, value, typelist=None):
        typelist = [instantiate(t) for t in wrap_list(typelist or [])]
        raw_values = force_unicode(value).split(self.VALUES_SEP)

        decoded_values = []
        for v, type in zip_longest(raw_values, typelist):
            if type is None:
                to_python = force_unicode
            else:
                to_python_factory = self.PROCESSOR_FACTORIES.get(
                    type.__class__)
                if to_python_factory:
                    to_python = to_python_factory(type)
                else:
                    to_python = type.to_python_single
            if v is None:
                continue

            if v == self.NULL_VAL:
                decoded_values.append(None)
            else:
                try:
                    decoded_values.append(to_python(v))
                except ValueError:
                    break

        return decoded_values
Exemple #2
0
    def decode_value(self, value, typelist=None):
        typelist = [instantiate(t) for t in wrap_list(typelist or [])]
        raw_values = force_unicode(value).split(self.VALUES_SEP)

        decoded_values = []
        for v, type in zip_longest(raw_values, typelist):
            if type is None:
                to_python = force_unicode
            else:
                to_python_factory = self.PROCESSOR_FACTORIES.get(type.__class__)
                if to_python_factory:
                    to_python = to_python_factory(type)
                else:
                    to_python = type.to_python_single
            if v is None:
                continue

            if v == self.NULL_VAL:
                decoded_values.append(None)
            else:
                try:
                    decoded_values.append(to_python(v))
                except ValueError:
                    break

        return decoded_values
Exemple #3
0
 def _encode_value(self, value):
     if value is None:
         return self.NULL_VAL
     if value is True:
         return self.TRUE_VAL
     if value is False:
         return self.FALSE_VAL
     return force_unicode(value)
Exemple #4
0
 def _encode_value(self, value):
     if value is None:
         return self.NULL_VAL
     if value is True:
         return self.TRUE_VAL
     if value is False:
         return self.FALSE_VAL
     return force_unicode(value)
Exemple #5
0
 def _encode_value(self, value, type=None):
     if value is None:
         return self.NULL_VAL
     if value is True:
         return self.TRUE_VAL
     if value is False:
         return self.FALSE_VAL
     if type:
         value = type.from_python(value, validate=True)
     return force_unicode(value)