Esempio n. 1
0
    async def _get(
        self, paths: List[str], is_json: bool = False, no_exception: bool = False
    ) -> Any:
        err = None
        ret = None
        try:
            key = self._storage.make_key(*paths)
            unmarshaled = await self._storage.get(key, is_json=is_json)
            if is_json:
                ret = unmarshaled
            else:
                ret = cloudpickle.loads(unmarshaled)
        except KeyNotFoundError as e:
            err = e
        except Exception as e:
            err = DataLoadError()
            err.__cause__ = e

        if no_exception:
            return (ret, err)
        else:
            if err is None:
                return ret
            else:
                raise err
Esempio n. 2
0
    def _get(self,
             key: str,
             is_json: bool = False,
             no_exception: bool = False) -> Any:
        err = None
        ret = None
        try:
            unmarshaled = self._storage.get(key)
            if unmarshaled is None:
                raise KeyNotFoundError
            if is_json:
                ret = json.loads(unmarshaled.decode())
            else:
                ret = cloudpickle.loads(unmarshaled)
        except KeyNotFoundError as e:
            err = e
        except Exception as e:
            err = DataLoadError()
            err.__cause__ = e

        if no_exception:
            return (ret, err)
        elif err is None:
            return ret
        else:
            raise err