diff options
Diffstat (limited to 'ryu/lib/rpc.py')
-rw-r--r-- | ryu/lib/rpc.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/ryu/lib/rpc.py b/ryu/lib/rpc.py index 57ba00c9..ed38f976 100644 --- a/ryu/lib/rpc.py +++ b/ryu/lib/rpc.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python -# # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation. # Copyright (C) 2013 YAMAMOTO Takashi <yamamoto at valinux co jp> # @@ -19,6 +17,9 @@ # msgpack-rpc # http://wiki.msgpack.org/display/MSGPACK/RPC+specification +from collections import deque +import select + import msgpack import six @@ -53,12 +54,12 @@ class MessageEncoder(object): assert isinstance(method, six.binary_type) assert isinstance(params, list) msgid = self._create_msgid() - return (self._packer.pack([MessageType.REQUEST, msgid, method, - params]), msgid) + return (self._packer.pack( + [MessageType.REQUEST, msgid, method, params]), msgid) def create_response(self, msgid, error=None, result=None): assert isinstance(msgid, int) - assert 0 <= msgid and msgid <= 0xffffffff + assert 0 <= msgid <= 0xffffffff assert error is None or result is None return self._packer.pack([MessageType.RESPONSE, msgid, error, result]) @@ -76,21 +77,18 @@ class MessageEncoder(object): for m in self._unpacker: self._dispatch_message(m, disp_table) - def _dispatch_message(self, m, disp_table): + @staticmethod + def _dispatch_message(m, disp_table): # XXX validation - type = m[0] + t = m[0] try: - f = disp_table[type] + f = disp_table[t] except KeyError: # ignore messages with unknown type return f(m[1:]) -from collections import deque -import select - - class EndPoint(object): """An endpoint *sock* is a socket-like. it can be either blocking or non-blocking. @@ -231,7 +229,7 @@ class EndPoint(object): except KeyError: return None error, result = m - return (result, error) + return result, error def get_notification(self): return self._get_message(self._notifications) @@ -241,6 +239,7 @@ class RPCError(Exception): """an error from server """ def __init__(self, error): + super(RPCError, self).__init__() self._error = error def get_value(self): |