Exemple #1
0
        def onResultCallback(jsonResult):
            try:
                if isinstance(jsonResult, Exception):
                    future.set_exception(jsonResult)
                    return

                if 'foraToPythonConversionError' in jsonResult:
                    future.set_exception(
                        Exceptions.ForaToPythonConversionError(
                            str(jsonResult['foraToPythonConversionError'])))
                    return
                if not jsonResult['isException']:
                    if 'maxBytesExceeded' in jsonResult:
                        future.set_exception(
                            Exceptions.ResultExceededBytecountThreshold())
                    else:
                        result = self.objectRehydrator.convertJsonResultToPythonObject(
                            jsonResult['result'])
                        future.set_result(result)
                else:
                    result = self.objectRehydrator.convertJsonResultToPythonObject(
                        jsonResult['result'])
                    future.set_exception(
                        Exceptions.ComputationError(result,
                                                    jsonResult['trace']))
            except Exception as e:
                # TODO need a better way of wrapping exceptions.
                # Alexandros has some ideas here, but this is
                # better than the experience without the wrapping
                # (which is hanging)
                logging.error(
                    "Rehydration failed: %s\nResult was %s of type %s",
                    traceback.format_exc(), jsonResult, type(jsonResult))

                future.set_exception(Exceptions.ForaToPythonConversionError(e))
Exemple #2
0
    def _translate_download_result(self, jsonResult):
        if 'foraToPythonConversionError' in jsonResult:
            return Exceptions.ForaToPythonConversionError(
                str(jsonResult['foraToPythonConversionError'])
                )

        if not jsonResult['isException']:
            if 'maxBytesExceeded' in jsonResult:
                return Exceptions.ResultExceededBytecountThreshold()
            else:
                return self.objectRehydrator.convertJsonResultToPythonObject(jsonResult['result'])

        result = self.objectRehydrator.convertJsonResultToPythonObject(jsonResult['result'])
        return Exceptions.ComputationError(result, jsonResult['trace'])