示例#1
0
    def convert(self, objectId, serializedBinaryObjectDefinition):
        import pyfora.Exceptions as PyforaExceptions
        import pyfora.BinaryObjectRegistryDeserializer as BinaryObjectRegistryDeserializer


        result = [None]
        def onConverted(r):
            result[0] = r

        t0 = time.time()

        BinaryObjectRegistryDeserializer.deserializeFromString(
            base64.b64decode(serializedBinaryObjectDefinition), 
            objectRegistry_[0],
            convertJsonToObject
            )

        logging.info("Updated object registry in %s seconds.", time.time() - t0)
        t0 = time.time()

        try:
            converter_[0].convert(objectId, objectRegistry_[0], onConverted)
        except Exception as e:
            logging.error("Converter raised an exception: %s", traceback.format_exc())
            raise Exceptions.InternalError("Unable to convert objectId %s" % objectId)

        logging.info("Converted to fora in %s seconds", time.time() - t0)

        assert result[0] is not None

        if isinstance(result[0], PyforaExceptions.PythonToForaConversionError):
            return {'isException': True, 'message': result[0].message, 'trace': result[0].trace}

        if isinstance(result[0], Exception):
            raise Exceptions.SubscribableWebObjectsException(result[0].message)

        objectIdToIvc_[objectId] = result[0]
        return {'objectId': objectId}
示例#2
0
    def convert(self, objectId, objectIdToObjectDefinition):
        import pyfora.TypeDescription as TypeDescription
        import pyfora.Exceptions as PyforaExceptions

        result = [None]
        def onConverted(r):
            result[0] = r

        t0 = time.time()

        objectRegistry_[0].objectIdToObjectDefinition.update({
            int(k): TypeDescription.deserialize(v)
            for k, v in objectIdToObjectDefinition.iteritems()
            })

        logging.info("Updated object registry in %s seconds.", time.time() - t0)
        t0 = time.time()

        try:
            converter_[0].convert(objectId, objectRegistry_[0], onConverted)
        except Exception as e:
            logging.error("Converter raised an exception: %s", traceback.format_exc())
            raise Exceptions.InternalError("Unable to convert objectId %s" % objectId)

        logging.info("Converted to fora in %s seconds", time.time() - t0)

        assert result[0] is not None

        if isinstance(result[0], PyforaExceptions.PythonToForaConversionError):
            return {'isException': True, 'message': result[0].message, 'trace': result[0].trace}

        if isinstance(result[0], Exception):
            raise Exceptions.SubscribableWebObjectsException(result[0].message)

        objectIdToIvc_[objectId] = result[0]
        return {'objectId': objectId}