Beispiel #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
Beispiel #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
Beispiel #3
0
 def encode_value(self, value, typelist=None):
     typelist = [instantiate(t) for t in wrap_list(typelist or [])]
     return self.VALUES_SEP.join(
         self._encode_value(v, t)
         for v, t in zip_longest(wrap_list(value), typelist))