Exemplo n.º 1
0
    def _call_proxy(self, obj_id, input):
        if obj_id not in self.pool:
            return proto.RETURN_MESSAGE + proto.ERROR +\
                get_command_part('Object ID unknown', self.pool)

        try:
            method = smart_decode(input.readline())[:-1]
            params = self._get_params(input)
            return_value = getattr(self.pool[obj_id], method)(*params)

            if (not isinstance(return_value, JavaObject)) and (
                    not self.python_server.gateway_client.converters is None):
                for converter in self.python_server.gateway_client.converters:
                    if converter.can_convert(return_value):
                        return_value = converter.convert(return_value, self.python_server.gateway_client)
                        break

            return proto.RETURN_MESSAGE + proto.SUCCESS + \
                   get_command_part(return_value, self.pool)
                   
        except Exception as e:
            logger.exception("There was an exception while executing the "
                             "Python Proxy on the Python Side.")

            if self.python_parameters.propagate_java_exceptions and\
               isinstance(e, proto.Py4JJavaError):
                java_exception = e.java_exception
            else:
                java_exception = traceback.format_exc()

            return proto.RETURN_MESSAGE + proto.ERROR +\
                get_command_part(java_exception, self.pool)
Exemplo n.º 2
0
 def __set_item(self, key, value):
     new_key = self.__compute_index(key)
     command = proto.ARRAY_COMMAND_NAME + proto.ARRAY_SET_SUB_COMMAND_NAME + \
         self._get_object_id() + "\n"
     command += get_command_part(new_key)
     command += get_command_part(value)
     command += proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 3
0
 def __set_item(self, key, value):
     new_key = self.__compute_index(key)
     command = proto.ARRAY_COMMAND_NAME +\
         proto.ARRAY_SET_SUB_COMMAND_NAME +\
         self._get_object_id() + "\n"
     command += get_command_part(new_key)
     command += get_command_part(value)
     command += proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 4
0
 def count(self, value):
     command = proto.LIST_COMMAND_NAME +\
         proto.LIST_COUNT_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n" + get_command_part(value) +\
         proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 5
0
 def __imul__(self, other):
     command = proto.LIST_COMMAND_NAME +\
         proto.LIST_IMULT_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n" + get_command_part(other) +\
         proto.END_COMMAND_PART
     self._gateway_client.send_command(command)
     return self
Exemplo n.º 6
0
 def count(self, value):
     command = proto.LIST_COMMAND_NAME +\
         proto.LIST_COUNT_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n" + get_command_part(value) +\
         proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 7
0
 def __imul__(self, other):
     command = proto.LIST_COMMAND_NAME +\
         proto.LIST_IMULT_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n" + get_command_part(other) +\
         proto.END_COMMAND_PART
     self._gateway_client.send_command(command)
     return self
Exemplo n.º 8
0
 def __get_slice(self, indices):
     command = proto.LIST_COMMAND_NAME + proto.LIST_SLICE_SUBCOMMAND_NAME + \
         self._get_object_id() + "\n"
     for index in indices:
         command += get_command_part(index)
     command += proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 9
0
 def __get_slice(self, indices):
     command = proto.LIST_COMMAND_NAME +\
         proto.LIST_SLICE_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n"
     for index in indices:
         command += get_command_part(index)
     command += proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 10
0
 def _call_proxy(self, obj_id, input):
     return_message = proto.ERROR_RETURN_MESSAGE
     if obj_id in self.pool:
         try:
             method = smart_decode(input.readline())[:-1]
             params = self._get_params(input)
             return_value = getattr(self.pool[obj_id], method)(*params)
             return_message = proto.RETURN_MESSAGE + proto.SUCCESS + get_command_part(return_value, self.pool)
         except Exception:
             logger.exception("There was an exception while executing the " "Python Proxy on the Python Side.")
     return return_message
Exemplo n.º 11
0
 def _call_proxy(self, obj_id, input):
     return_message = proto.ERROR_RETURN_MESSAGE
     if obj_id in self.pool:
         try:
             method = smart_decode(input.readline())[:-1]
             params = self._get_params(input)
             return_value = getattr(self.pool[obj_id], method)(*params)
             return_message = proto.RETURN_MESSAGE + proto.SUCCESS +\
                 get_command_part(return_value, self.pool)
         except Exception:
             logger.exception("There was an exception while executing the "
                              "Python Proxy on the Python Side.")
     return return_message
Exemplo n.º 12
0
    def _call_proxy(self, obj_id, input):
        if obj_id not in self.pool:
            return proto.RETURN_MESSAGE + proto.ERROR +\
                get_command_part('Object ID unknown', self.pool)

        try:
            method = smart_decode(input.readline())[:-1]
            params = self._get_params(input)
            return_value = getattr(self.pool[obj_id], method)(*params)
            return proto.RETURN_MESSAGE + proto.SUCCESS +\
                get_command_part(return_value, self.pool)
        except Exception as e:
            logger.exception("There was an exception while executing the "
                             "Python Proxy on the Python Side.")

            if self.python_parameters.propagate_java_exceptions and\
               isinstance(e, proto.Py4JJavaError):
                java_exception = e.java_exception
            else:
                java_exception = traceback.format_exc()

            return proto.RETURN_MESSAGE + proto.ERROR +\
                get_command_part(java_exception, self.pool)
Exemplo n.º 13
0
 def __mul__(self, other):
     command = proto.LIST_COMMAND_NAME + proto.LIST_MULT_SUBCOMMAND_NAME + \
         self._get_object_id() + "\n" + get_command_part(other) + \
         proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)
Exemplo n.º 14
0
 def __mul__(self, other):
     command = proto.LIST_COMMAND_NAME + proto.LIST_MULT_SUBCOMMAND_NAME +\
         self._get_object_id() + "\n" + get_command_part(other) +\
         proto.END_COMMAND_PART
     answer = self._gateway_client.send_command(command)
     return get_return_value(answer, self._gateway_client)