def unpack_args(self, data): self.log.debug('Data received: %r', data) args, kwargs = (), {} if data: parsed = json.loads(data) if len(parsed) > 0: args = parsed[0] if len(parsed) > 1: kwargs = parsed[1] # Convert unicode strings to byte strings. for key in kwargs.keys(): kwargs[str(key)] = kwargs.pop(key) return args, kwargs
def parse_command(line): command = json.loads(line) # The specification for commands is really simple. Essentially they # consist of lists: # ['action_name', ['arg1', 'arg2'], {'key': 'value'}] # The protocol is surprisingly close to Remote Procedure Call (RPC). action, args, kwargs = command[0], (), {} if len(command) > 1: args = command[1] if len(command) > 2: kwargs = command[2] # Convert unicode strings to byte strings. for key in kwargs.keys(): kwargs[str(key)] = kwargs.pop(key) return action, args, kwargs
def handle_response(self, data): try: status, result = json.loads(data) except ValueError, exc: self.log.error('Invalid response returned: %r', data) raise