def _listify_result(self, result): if result is None: return [] if isinstance(result, set): return flatten(list(result)) if not isinstance(result, list): return [result] return flatten(result)
def handle_response(self, result, add_ok=True): """Format the response from a request handler.""" response = [] if result is None: result = [] elif isinstance(result, set): result = list(result) elif not isinstance(result, list): result = [result] for line in flatten(result): if isinstance(line, dict): for (key, value) in line.items(): response.append(u"%s: %s" % (key, value)) elif isinstance(line, tuple): (key, value) = line response.append(u"%s: %s" % (key, value)) else: response.append(line) if add_ok and (not response or not response[-1].startswith(u"ACK")): response.append(u"OK") return response