Browse Source

Fix uninitialized variable

master
Neil Booth 8 years ago
parent
commit
56130e4a66
  1. 17
      lib/jsonrpc.py

17
lib/jsonrpc.py

@ -339,12 +339,13 @@ class JSONSessionBase(util.LoggedClass):
self.log_info('resuming processing') self.log_info('resuming processing')
self.pause = False self.pause = False
def is_oversized(self, length): def is_oversized(self, length, id_):
'''Return True if the given outgoing message size is too large.''' '''Return an error payload if the given outgoing message size is too
large, or False if not.
'''
if self.max_send and length > max(1000, self.max_send): if self.max_send and length > max(1000, self.max_send):
msg = 'response too large (at least {:d} bytes)'.format(length) msg = 'response too large (at least {:d} bytes)'.format(length)
return self.error_bytes(msg, JSONRPC.INVALID_REQUEST, return self.error_bytes(msg, JSONRPC.INVALID_REQUEST, id_)
payload.get('id'))
return False return False
def send_binary(self, binary): def send_binary(self, binary):
@ -418,15 +419,15 @@ class JSONSessionBase(util.LoggedClass):
'''Encode a Python object as binary bytes.''' '''Encode a Python object as binary bytes.'''
assert isinstance(payload, dict) assert isinstance(payload, dict)
id_ = payload.get('id')
try: try:
binary = json.dumps(payload).encode() binary = json.dumps(payload).encode()
except TypeError: except TypeError:
msg = 'JSON encoding failure: {}'.format(payload) msg = 'JSON encoding failure: {}'.format(payload)
self.log_error(msg) self.log_error(msg)
binary = self.error_bytes(msg, JSONRPC.INTERNAL_ERROR, binary = self.error_bytes(msg, JSONRPC.INTERNAL_ERROR, id_)
payload.get('id'))
error_bytes = self.is_oversized(len(binary)) error_bytes = self.is_oversized(len(binary), id_)
return error_bytes or binary return error_bytes or binary
def decode_message(self, payload): def decode_message(self, payload):
@ -483,7 +484,7 @@ class JSONSessionBase(util.LoggedClass):
if not batch: if not batch:
return self.version.batch_bytes(results) return self.version.batch_bytes(results)
error_bytes = self.is_oversized(self.batch_size(results)) error_bytes = self.is_oversized(self.batch_size(results), None)
if error_bytes: if error_bytes:
return error_bytes return error_bytes

Loading…
Cancel
Save