Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c24d55d

Browse filesBrowse files
author
Thomas Belhalfaoui
committed
Replace deprected msgpack-python with msgpack
* Ensure Python 3 compatibility * Remove all encoding options (not needed with msgpack in Python 3)
1 parent 8fcef9b commit c24d55d
Copy full SHA for c24d55d

File tree

Expand file treeCollapse file tree

8 files changed

+31
-36
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+31
-36
lines changed
Open diff view settings
Collapse file

‎example/echoserver.py‎

Copy file name to clipboardExpand all lines: example/echoserver.py
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ def serve(daemon=False):
2929
3030
To stop, use ``server.shutdown()``
3131
"""
32-
for port in xrange(9000, 10000):
32+
for port in range(9000, 10000):
3333
try:
3434
addr = msgpackrpc.Address('localhost', port)
3535
server = msgpackrpc.Server(EchoHandler())
36-
print server
36+
print(server)
3737
server.listen(addr)
3838
thread = serve_background(server, daemon)
39-
return (addr, server, thread)
39+
return addr, server, thread
4040
except Exception as err:
41-
print err
41+
print(err)
4242
pass
4343

4444
if __name__ == '__main__':
45-
port = serve(False)
46-
print "Serving on localhost:%d\n" % port[1]
47-
45+
addr, server, thread = serve(False)
46+
print("Serving on %s:%d\n" % (addr._host, addr._port))
Collapse file

‎example/test_client.py‎

Copy file name to clipboardExpand all lines: example/test_client.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def teardown():
2020

2121
def test_client():
2222
global ADDR
23-
client = msgpackrpc.Client(ADDR, unpack_encoding = 'utf-8')
23+
client = msgpackrpc.Client(ADDR)
2424

2525
f1 = client.call('echo', 'foo')
2626
f2 = client.call('echo', 'bar')
@@ -30,7 +30,7 @@ def test_client():
3030
assert f1 == 'foo'
3131
assert f3 == 'baz'
3232

33-
print "EchoHandler#echo via msgpackrpc"
33+
print("EchoHandler#echo via msgpackrpc")
3434

3535

3636
if __name__ == '__main__':
Collapse file

‎msgpackrpc/client.py‎

Copy file name to clipboardExpand all lines: msgpackrpc/client.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class Client(session.Session):
77
Client is useful for MessagePack RPC API.
88
"""
99

10-
def __init__(self, address, timeout=10, loop=None, builder=tcp, reconnect_limit=5, pack_encoding='utf-8', unpack_encoding=None):
10+
def __init__(self, address, timeout=10, loop=None, builder=tcp, reconnect_limit=5):
1111
loop = loop or Loop()
12-
session.Session.__init__(self, address, timeout, loop, builder, reconnect_limit, pack_encoding, unpack_encoding)
12+
session.Session.__init__(self, address, timeout, loop, builder, reconnect_limit)
1313

1414
if timeout:
1515
loop.attach_periodic_callback(self.step_timeout, 1000) # each 1s
Collapse file

‎msgpackrpc/server.py‎

Copy file name to clipboardExpand all lines: msgpackrpc/server.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ class Server(session.Session):
1212
Server is usaful for MessagePack RPC Server.
1313
"""
1414

15-
def __init__(self, dispatcher, loop=None, builder=tcp, pack_encoding='utf-8', unpack_encoding=None):
15+
def __init__(self, dispatcher, loop=None, builder=tcp):
1616
self._loop = loop or Loop()
1717
self._builder = builder
18-
self._encodings = (pack_encoding, unpack_encoding)
1918
self._listeners = []
2019
self._dispatcher = dispatcher
2120

2221
def listen(self, address):
23-
listener = self._builder.ServerTransport(address, self._encodings)
22+
listener = self._builder.ServerTransport(address)
2423
listener.listen(self)
2524
self._listeners.append(listener)
2625

Collapse file

‎msgpackrpc/session.py‎

Copy file name to clipboardExpand all lines: msgpackrpc/session.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Session(object):
1919
result to the corresponding future.
2020
"""
2121

22-
def __init__(self, address, timeout, loop=None, builder=tcp, reconnect_limit=5, pack_encoding='utf-8', unpack_encoding=None):
22+
def __init__(self, address, timeout, loop=None, builder=tcp, reconnect_limit=5):
2323
"""\
2424
:param address: address of the server.
2525
:param loop: context object.
@@ -29,7 +29,7 @@ def __init__(self, address, timeout, loop=None, builder=tcp, reconnect_limit=5,
2929
self._loop = loop or Loop()
3030
self._address = address
3131
self._timeout = timeout
32-
self._transport = builder.ClientTransport(self, self._address, reconnect_limit, encodings=(pack_encoding, unpack_encoding))
32+
self._transport = builder.ClientTransport(self, self._address, reconnect_limit)
3333
self._generator = _NoSyncIDGenerator()
3434
self._request_table = {}
3535

Collapse file

‎msgpackrpc/transport/tcp.py‎

Copy file name to clipboardExpand all lines: msgpackrpc/transport/tcp.py
+13-16Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88

99
class BaseSocket(object):
10-
def __init__(self, stream, encodings):
10+
def __init__(self, stream):
1111
self._stream = stream
12-
self._packer = msgpack.Packer(encoding=encodings[0], default=lambda x: x.to_msgpack())
13-
self._unpacker = msgpack.Unpacker(encoding=encodings[1])
12+
self._packer = msgpack.Packer(default=lambda x: x.to_msgpack())
13+
self._unpacker = msgpack.Unpacker()
1414

1515
def close(self):
1616
self._stream.close()
@@ -49,8 +49,8 @@ def on_notify(self, method, param):
4949

5050

5151
class ClientSocket(BaseSocket):
52-
def __init__(self, stream, transport, encodings):
53-
BaseSocket.__init__(self, stream, encodings)
52+
def __init__(self, stream, transport):
53+
BaseSocket.__init__(self, stream)
5454
self._transport = transport
5555
self._stream.set_close_callback(self.on_close)
5656

@@ -72,10 +72,9 @@ def on_response(self, msgid, error, result):
7272

7373

7474
class ClientTransport(object):
75-
def __init__(self, session, address, reconnect_limit, encodings=('utf-8', None)):
75+
def __init__(self, session, address, reconnect_limit):
7676
self._session = session
7777
self._address = address
78-
self._encodings = encodings
7978
self._reconnect_limit = reconnect_limit;
8079

8180
self._connecting = 0
@@ -95,7 +94,7 @@ def send_message(self, message, callback=None):
9594

9695
def connect(self):
9796
stream = IOStream(self._address.socket(), io_loop=self._session._loop._ioloop)
98-
socket = ClientSocket(stream, self, self._encodings)
97+
socket = ClientSocket(stream, self)
9998
socket.connect();
10099

101100
def close(self):
@@ -135,8 +134,8 @@ def on_close(self, sock):
135134

136135

137136
class ServerSocket(BaseSocket):
138-
def __init__(self, stream, transport, encodings):
139-
BaseSocket.__init__(self, stream, encodings)
137+
def __init__(self, stream, transport):
138+
BaseSocket.__init__(self, stream)
140139
self._transport = transport
141140
self._stream.read_until_close(self.on_read, self.on_read)
142141

@@ -151,23 +150,21 @@ def on_notify(self, method, param):
151150

152151

153152
class MessagePackServer(tcpserver.TCPServer):
154-
def __init__(self, transport, io_loop=None, encodings=None):
153+
def __init__(self, transport, io_loop=None):
155154
self._transport = transport
156-
self._encodings = encodings
157155
tcpserver.TCPServer.__init__(self, io_loop=io_loop)
158156

159157
def handle_stream(self, stream, address):
160-
ServerSocket(stream, self._transport, self._encodings)
158+
ServerSocket(stream, self._transport)
161159

162160

163161
class ServerTransport(object):
164-
def __init__(self, address, encodings=('utf-8', None)):
162+
def __init__(self, address):
165163
self._address = address;
166-
self._encodings = encodings
167164

168165
def listen(self, server):
169166
self._server = server;
170-
self._mp_server = MessagePackServer(self, io_loop=self._server._loop._ioloop, encodings=self._encodings)
167+
self._mp_server = MessagePackServer(self, io_loop=self._server._loop._ioloop)
171168
self._mp_server.listen(self._address.port)
172169

173170
def close(self):
Collapse file

‎setup.py‎

Copy file name to clipboardExpand all lines: setup.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
This implementation uses Tornado framework as a backend.
2323
""",
2424
packages=['msgpackrpc', 'msgpackrpc/transport'],
25-
install_requires=['msgpack-python', 'tornado >= 3,<5'],
25+
install_requires=['msgpack', 'tornado >= 3,<5'],
2626
license="Apache Software License",
2727
classifiers=[
2828
'Programming Language :: Python :: 2',
Collapse file

‎test/test_msgpackrpc.py‎

Copy file name to clipboardExpand all lines: test/test_msgpackrpc.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _start_server(server):
8787
lock.acquire()
8888
lock.acquire() # wait for the server to start
8989

90-
self._client = msgpackrpc.Client(self._address, unpack_encoding='utf-8')
90+
self._client = msgpackrpc.Client(self._address)
9191
return self._client;
9292

9393
def tearDown(self):
@@ -169,7 +169,7 @@ def test_async_result(self):
169169
def test_connect_failed(self):
170170
client = self.setup_env();
171171
port = helper.unused_port()
172-
client = msgpackrpc.Client(msgpackrpc.Address('localhost', port), unpack_encoding='utf-8')
172+
client = msgpackrpc.Client(msgpackrpc.Address('localhost', port))
173173
self.assertRaises(error.TransportError, lambda: client.call('hello'))
174174

175175
def test_timeout(self):
@@ -178,7 +178,7 @@ def test_timeout(self):
178178
if self.__class__.ENABLE_TIMEOUT_TEST:
179179
self.assertEqual(client.call('long_exec'), 'finish!', "'long_exec' result is incorrect")
180180

181-
client = msgpackrpc.Client(self._address, timeout=1, unpack_encoding='utf-8')
181+
client = msgpackrpc.Client(self._address, timeout=1)
182182
self.assertRaises(error.TimeoutError, lambda: client.call('long_exec'))
183183
else:
184184
print("Skip test_timeout")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.