Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Resolve some warnings #57

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
before_install:
- "sudo apt-get install python-dev"
install:
Expand Down
4 changes: 2 additions & 2 deletions examples/sum_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def call():
client = RPCClient('127.0.0.1', 6000)

print client.call('sum', 1, 2)
print( client.call('sum', 1, 2))


def call_using_pool():
Expand All @@ -21,7 +21,7 @@ def _call(n):
return client.call('sum', 1, 2)

glet_pool = gevent.pool.Pool(10)
print [result for result in glet_pool.imap_unordered(_call, xrange(10))]
print([result for result in glet_pool.imap_unordered(_call, xrange(10))])


call()
Expand Down
4,077 changes: 2,200 additions & 1,877 deletions mprpc/client.c

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions mprpc/client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ cdef class RPCClient:
:param int timeout: (optional) Socket timeout.
:param bool lazy: (optional) If set to True, the socket connection is not
established until you specifically call open()
:param str pack_encoding: (optional) Character encoding used to pack data
using Messagepack.
:param str unpack_encoding: (optional) Character encoding used to unpack
data using Messagepack.
:param dict pack_params: (optional) Parameters to pass to Messagepack Packer
:param dict unpack_params: (optional) Parameters to pass to Messagepack
:param tcp_no_delay (optional) If set to True, use TCP_NODELAY.
Expand All @@ -44,15 +40,14 @@ cdef class RPCClient:
cdef _socket
cdef _packer
cdef _pack_params
cdef _unpack_encoding
cdef _unpack_params
cdef _tcp_no_delay
cdef _keep_alive

def __init__(self, host, port, timeout=None, lazy=False,
pack_encoding='utf-8', unpack_encoding='utf-8',
pack_params=None, unpack_params=None,
tcp_no_delay=False, keep_alive=False):

self._host = host
self._port = port
self._timeout = timeout
Expand All @@ -62,14 +57,19 @@ cdef class RPCClient:
self._tcp_no_delay = tcp_no_delay
self._keep_alive = keep_alive
self._pack_params = pack_params or dict(use_bin_type=True)
self._unpack_encoding = unpack_encoding
self._unpack_params = unpack_params or dict(use_list=False)

self._packer = msgpack.Packer(encoding=pack_encoding, **self._pack_params)
self._packer = msgpack.Packer(**self._pack_params)

if not lazy:
self.open()

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()

def getpeername(self):
"""Return the address of the remote endpoint."""
return self._host, self._port
Expand Down Expand Up @@ -132,7 +132,8 @@ cdef class RPCClient:
cdef bytes data
self._socket.sendall(req)

unpacker = msgpack.Unpacker(encoding=self._unpack_encoding,
unpacker = msgpack.Unpacker(raw=False,
strict_map_key=False, # allow keys which is of of type bytes or str
**self._unpack_params)
while True:
data = self._socket.recv(SOCKET_RECV_SIZE)
Expand Down Expand Up @@ -192,10 +193,6 @@ class RPCPoolClient(RPCClient, Connection):
:param int timeout: (optional) Socket timeout.
:param int lifetime: (optional) Connection lifetime in seconds. Only valid
when used with `gsocketpool.pool.Pool <http://gsocketpool.readthedocs.org/en/latest/api.html#gsocketpool.pool.Pool>`_.
:param str pack_encoding: (optional) Character encoding used to pack data
using Messagepack.
:param str unpack_encoding: (optional) Character encoding used to unpack
data using Messagepack.
:param dict pack_params: (optional) Parameters to pass to Messagepack Packer
:param dict unpack_params: (optional) Parameters to pass to Messagepack
:param tcp_no_delay (optional) If set to True, use TCP_NODELAY.
Expand All @@ -204,7 +201,7 @@ class RPCPoolClient(RPCClient, Connection):
"""

def __init__(self, host, port, timeout=None, lifetime=None,
pack_encoding='utf-8', unpack_encoding='utf-8',
pack_encoding='', unpack_encoding='',
pack_params=dict(), unpack_params=dict(use_list=False),
tcp_no_delay=False, keep_alive=False):

Expand All @@ -216,7 +213,6 @@ class RPCPoolClient(RPCClient, Connection):

RPCClient.__init__(
self, host, port, timeout=timeout, lazy=True,
pack_encoding=pack_encoding, unpack_encoding=unpack_encoding,
pack_params=pack_params, unpack_params=unpack_params,
tcp_no_delay=tcp_no_delay, keep_alive=keep_alive)

Expand Down
Loading