Exemplo n.º 1
0
 def deser_dict(val):
     r = {}
     try:
         its = val.items()
     except BaseException as e:
         raise SerdeException(val, 'dict_a', t=t, par=e)
     try:
         for k, v in its:
             r[deps[0](k)] = deps[1](v)
     except BaseException as e:
         raise SerdeException(val, 'dict_b', t=t, par=e, k=k, v=v)
     return r
Exemplo n.º 2
0
    def __call__(self, val: Union[list, dict]) -> Any:
        idx, val = val

        dep_idx = self.ordered.get(idx)

        if dep_idx is None:
            raise SerdeException(val, 'u_idx', idx)

        dep = self.deps[dep_idx]

        try:
            return dep(val)
        except Exception as e:
            raise SerdeException(val, 'u_deps', idx=dep_idx, par=e)
Exemplo n.º 3
0
    def __call__(self, val: Union[list, dict]) -> Any:
        self.d, *_ = self.deps

        if len(val) != len(self.deps):
            raise SerdeException(val, 'tpl_len')

        return tuple(d(x) for d, x in zip(self.deps, val))
Exemplo n.º 4
0
        def callable_ret_ser(val):
            dep = deps[0]

            try:
                return dep(val)
            except Exception as e:
                raise SerdeException(val=val, code='ex', par=e)
Exemplo n.º 5
0
    def __call__(self, val):
        desc = None

        desc = self.parent.descriptor_fn(True, val)
        nv = desc, val
        try:
            return desc, super().__call__(nv)
        except Exception as e:
            raise SerdeException(val, 'union_ser', desc=desc, par=e)
Exemplo n.º 6
0
 def __call__(self, val: Union[list, dict]) -> Any:
     fn = self.deps[0]
     try:
         if val is None:
             return None
         else:
             return fn(val)
     except Exception as e:
         raise SerdeException(val, 'opt', fn=fn, par=e)
Exemplo n.º 7
0
    def __call__(self, val: Union[list, dict]) -> Any:
        r = {}

        i, f = None, None

        try:

            for i, f in enumerate(self.fields):
                # either way (even if a field is non-optional), that field must not accept None as it's argument
                r[f] = self.deps[i](val.get(f))
                # r[f] = self.deps[i](val[f])
        except Exception as e:
            raise SerdeException(val, 'u_sf', idx=i, field=f, par=e)

        try:

            return self.t(**r)
        except Exception as e:
            raise SerdeException(val, 'u_inst', fields=r, par=e)
Exemplo n.º 8
0
        def ser_dict(val):
            ks, vs = deps
            r = {}
            k, v = None, None
            try:
                for k, v in val.items():
                    # either way (even if a field is non-optional), that field must not accept None as it's argument
                    ksk = ks(k)
                    vsv = vs(v)
                    r[ksk] = vsv
                    # r[f] = self.deps[i](val[f])
            except (TypeError, Exception) as e:
                raise SerdeException(val, 'u_sf', idx=k, field=v, par=e)

            return r
Exemplo n.º 9
0
 def serialize(self, t, val):
     try:
         return self.serializers[t](val)
     except Exception as e:
         raise SerdeException(val, '$', t=t, par=e)
Exemplo n.º 10
0
 def deserialize(self, t: Any, val) -> T:
     try:
         return self.deserializers[t](val)
     except Exception as e:
         raise SerdeException(val, '$', t=t, par=e)
Exemplo n.º 11
0
    def __call__(self, val: Any) -> Union[list, dict]:
        if not isinstance(val, self.mapper):
            raise SerdeException(val, 'a_sv', t=self.mapper.__name__)

        return val
Exemplo n.º 12
0
 def __call__(self, val: Any) -> Union[list, dict]:
     try:
         return self.mapper(val)
     except Exception as e:
         raise SerdeException(val, 'a_dv', t=self.mapper.__name__, par=e)