diff --git a/README.md b/README.md index 9c6c93f..f0061e0 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ bundle Use Python 3 and then install the following dependencies. ``` -pip install mprpc +pip install msgpack-rpc-python ``` To verify the installation, execute a sample script. diff --git a/rb_call.py b/rb_call.py index 370865d..27d237a 100644 --- a/rb_call.py +++ b/rb_call.py @@ -1,5 +1,5 @@ -import subprocess,time,sys,os,inspect,atexit,re -import msgpack,mprpc +import subprocess,time,sys,os,inspect,atexit +import msgpack,msgpackrpc class RubyObject(): @@ -58,12 +58,9 @@ def send(self, method, *args, **kwargs): try: obj = self.session.client.call('send_method', self.obj_id, method, args, kwargs ) return self.cast(obj) - except mprpc.exceptions.RPCError as ex: - # data may contain space, single-quote('), double-quote(") - matched = re.match(r'ExtType\(code=40, data=b(.+)\)', ex.args[0]) - if matched: - e = msgpack.ExtType(40, eval('b'+matched.group(1)) ) - arg = RubyObject.cast( e ) + except msgpackrpc.error.RPCError as ex: + arg = RubyObject.cast( ex.args[0] ) + if isinstance( arg, RubyObject ): raise RubyException( arg.message(), arg ) from None else: raise @@ -105,9 +102,8 @@ def cleanup(): atexit.register( cleanup ) port = int( self.proc.stdout.readline() ) self.proc.stdout.close() - def default(obj): - return obj.to_msgpack() - self.client = mprpc.RPCClient('localhost', port, pack_encoding= None, unpack_encoding=None, pack_params = {"default": default}, unpack_params={"raw":False}) + self.address = msgpackrpc.Address("localhost", port) + self.client = msgpackrpc.Client(self.address, unpack_encoding='utf-8') RubyObject.session = self self.kernel = RubyObject.cast( self.client.call('get_kernel') )