Exemplo n.º 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))
Exemplo n.º 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'])
Exemplo n.º 3
0
 def onExpanded(jsonResult):
     result = jsonResult
     if not isinstance(jsonResult, Exception):
         if jsonResult['isException']:
             result = Exceptions.ComputationError(
                 self.objectRehydrator.convertJsonResultToPythonObject(
                     jsonResult['result']), jsonResult['trace'])
         else:
             assert isinstance(jsonResult['dictOfProxies'], dict)
             result = {
                 k: RemotePythonObject.ComputedRemotePythonObject(
                     v, self, False)
                 for k, v in jsonResult['dictOfProxies'].iteritems()
             }
     self._resolve_future(future, result)
Exemplo n.º 4
0
        def onExpanded(jsonResult):
            result = jsonResult
            if not isinstance(jsonResult, Exception):
                if jsonResult['isException']:
                    result = Exceptions.ComputationError(
                        self.objectRehydrator.convertJsonResultToPythonObject(
                            jsonResult['result']), jsonResult['trace'])
                else:
                    assert isinstance(jsonResult['tupleOfComputedValues'],
                                      tuple)
                    result = tuple(
                        RemotePythonObject.ComputedRemotePythonObject(
                            val, self, False)
                        for val in jsonResult['tupleOfComputedValues'])

            self._resolve_future(future, result)
Exemplo n.º 5
0
        def onExpanded(jsonResult):
            if isinstance(jsonResult, Exception):
                future.set_exception(jsonResult)
                return

            if jsonResult['isException']:
                result = self.objectRehydrator.convertJsonResultToPythonObject(
                    jsonResult['result'])
                future.set_exception(
                    Exceptions.ComputationError(result, jsonResult['trace']))
                return

            assert isinstance(jsonResult['tupleOfComputedValues'], tuple)

            tupleOfProxies = \
                tuple([
                    RemotePythonObject.ComputedRemotePythonObject(val, self) \
                    for val in jsonResult['tupleOfComputedValues']
                    ])

            future.set_result(tupleOfProxies)
Exemplo n.º 6
0
        def onExpanded(jsonResult):
            if isinstance(jsonResult, Exception):
                future.set_exception(jsonResult)
                return

            if jsonResult['isException']:
                result = self.objectRehydrator.convertJsonResultToPythonObject(
                    jsonResult['result'])
                future.set_exception(
                    Exceptions.ComputationError(result, jsonResult['trace']))
                return

            assert isinstance(jsonResult['dictOfProxies'], dict)

            dictOfProxies = {}
            for k, v in jsonResult['dictOfProxies'].iteritems():
                dictOfProxies[
                    k] = RemotePythonObject.ComputedRemotePythonObject(
                        v, self)

            future.set_result(dictOfProxies)