diff --git a/src/exabgp/reactor/api/__init__.py b/src/exabgp/reactor/api/__init__.py index f8f474e45..38afc9ae6 100644 --- a/src/exabgp/reactor/api/__init__.py +++ b/src/exabgp/reactor/api/__init__.py @@ -38,21 +38,20 @@ def log_failure(self, message, level='ERR'): log.error(report, 'processes', level) def process(self, reactor, service, command): + use_json = False # it to allow a global "set encoding json" # it to allow a global "set encoding text" # to not have to set the encoding on each command if 'json' in command.split(' '): - return self.response(reactor, service, command, True) - if 'text' in command.split(' '): - return self.response(reactor, service, command, False) - return self.response(reactor, service, command, False) + use_json = True + return self.response(reactor, service, command, use_json) def response(self, reactor, service, command, use_json): api = 'json' if use_json else 'text' for registered in self.functions: if registered == command or command.endswith(' ' + registered) or registered + ' ' in command: return self.callback[api][registered](self, reactor, service, command, use_json) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) log.warning('command from process not understood : %s' % command, 'api') return False diff --git a/src/exabgp/reactor/api/command/announce.py b/src/exabgp/reactor/api/command/announce.py index 56580d78e..696798eee 100644 --- a/src/exabgp/reactor/api/command/announce.py +++ b/src/exabgp/reactor/api/command/announce.py @@ -32,14 +32,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_route(command) if not changes: self.log_failure('command could not parse route in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -56,14 +56,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -78,14 +78,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_route(command) if not changes: self.log_failure('command could not parse route in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -112,14 +112,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -134,14 +134,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_vpls(command) if not changes: self.log_failure('command could not parse vpls in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -153,14 +153,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the vpls') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the vpls') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -175,7 +175,7 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -183,7 +183,7 @@ def callback(): if not changes: self.log_failure('command could not parse vpls in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -200,14 +200,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the vpls') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the vpls') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -223,14 +223,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_attributes(command, peers) if not changes: self.log_failure('command could not parse route in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -242,14 +242,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -265,14 +265,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_attributes(command, peers) if not changes: self.log_failure('command could not parse route in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -289,14 +289,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the route') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -311,14 +311,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_flow(command) if not changes: self.log_failure('command could not parse flow in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -330,14 +330,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the flow') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the flow') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -352,7 +352,7 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -360,7 +360,7 @@ def callback(): if not changes: self.log_failure('command could not parse flow in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -376,14 +376,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the flow') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the flow') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -396,7 +396,7 @@ def callback(self, command, peers): family = self.api_eor(command) if not family: self.log_failure("Command could not parse eor : %s" % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -407,24 +407,24 @@ def callback(self, command, peers): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: descriptions, command = extract_neighbors(line) peers = match_neighbors(reactor.established_peers(), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False reactor.asynchronous.schedule(service, command, callback(self, command, peers)) return True except ValueError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False @@ -434,7 +434,7 @@ def callback(self, command, peers): refreshes = self.api_refresh(command) if not refreshes: self.log_failure("Command could not parse route-refresh command : %s" % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -446,24 +446,24 @@ def callback(self, command, peers): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: descriptions, command = extract_neighbors(line) peers = match_neighbors(reactor.established_peers(), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False reactor.asynchronous.schedule(service, command, callback(self, command, peers)) return True except ValueError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False @@ -473,7 +473,7 @@ def callback(self, command, peers): operational = self.api_operational(command) if not operational: self.log_failure("Command could not parse operational command : %s" % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -483,7 +483,7 @@ def callback(self, command, peers): % (', '.join(peers if peers else []) if peers is not None else 'all peers', operational.extensive()) ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) if (line.split() + ['be', 'safe'])[2].lower() not in ( 'asm', @@ -495,7 +495,7 @@ def callback(self, command, peers): 'lpcq', 'lpcp', ): - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) return False try: @@ -503,17 +503,17 @@ def callback(self, command, peers): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False reactor.asynchronous.schedule(service, command, callback(self, command, peers)) return True except ValueError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False @@ -525,14 +525,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_announce_v4(command) if not changes: self.log_failure('command could not parse ipv4 in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -544,14 +544,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the ipv4') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the ipv4') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -566,7 +566,7 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -574,7 +574,7 @@ def callback(): if not changes: self.log_failure('command could not parse ipv4 in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -590,14 +590,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the ipv4') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the ipv4') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -612,14 +612,14 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return changes = self.api_announce_v6(command) if not changes: self.log_failure('command could not parse ipv6 in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -631,14 +631,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the ipv6') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the ipv6') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) @@ -653,7 +653,7 @@ def callback(): peers = match_neighbors(reactor.peers(service), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -661,7 +661,7 @@ def callback(): if not changes: self.log_failure('command could not parse ipv6 in : %s' % command) - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True return @@ -677,14 +677,14 @@ def callback(): ) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) except ValueError: self.log_failure('issue parsing the ipv6') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True except IndexError: self.log_failure('issue parsing the ipv6') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) yield True reactor.asynchronous.schedule(service, line, callback()) diff --git a/src/exabgp/reactor/api/command/neighbor.py b/src/exabgp/reactor/api/command/neighbor.py index 444a0a46b..d1d65ee33 100644 --- a/src/exabgp/reactor/api/command/neighbor.py +++ b/src/exabgp/reactor/api/command/neighbor.py @@ -26,24 +26,24 @@ def teardown(self, reactor, service, line, use_json): try: descriptions, line = extract_neighbors(line) if ' ' not in line: - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False _, code = line.split(' ', 1) if not code.isdigit(): - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False for key in reactor.established_peers(): for description in descriptions: if match_neighbor(description, key): reactor.teardown_peer(key, int(code)) self.log_message('teardown scheduled for %s' % ' '.join(description)) - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) return True except ValueError: - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False @@ -80,7 +80,7 @@ def callback_configuration(): for line in str(neighbor).split('\n'): reactor.processes.write(service, line) yield True - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) def callback_json(): p = [] @@ -89,7 +89,7 @@ def callback_json(): for line in json.dumps(p).split('\n'): reactor.processes.write(service, line) yield True - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) def callback_extensive(): for peer_name in reactor.peers(): @@ -98,7 +98,7 @@ def callback_extensive(): for line in NeighborTemplate.extensive(reactor.neighbor_cli_data(peer_name)).split('\n'): reactor.processes.write(service, line) yield True - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) def callback_summary(): reactor.processes.write(service, NeighborTemplate.summary_header) @@ -108,7 +108,7 @@ def callback_summary(): for line in NeighborTemplate.summary(reactor.neighbor_cli_data(peer_name)).split('\n'): reactor.processes.write(service, line) yield True - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) if use_json: reactor.asynchronous.schedule(service, line, callback_json()) @@ -128,4 +128,4 @@ def callback_summary(): reactor.processes.write(service, 'please specify summary, extensive or configuration') reactor.processes.write(service, 'you can filter by peer ip address adding it after the word neighbor') - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) diff --git a/src/exabgp/reactor/api/command/reactor.py b/src/exabgp/reactor/api/command/reactor.py index 8ad7f14a1..b1f980dd6 100644 --- a/src/exabgp/reactor/api/command/reactor.py +++ b/src/exabgp/reactor/api/command/reactor.py @@ -42,7 +42,7 @@ def manual(self, reactor, service, line, use_json): for line in sorted(lines): reactor.processes.write(service, line, True) reactor.processes.write(service, '', True) - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True @@ -50,7 +50,7 @@ def manual(self, reactor, service, line, use_json): def shutdown(self, reactor, service, line, use_json): reactor.signal.received = reactor.signal.SHUTDOWN reactor.processes.write(service, 'shutdown in progress') - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True @@ -58,7 +58,7 @@ def shutdown(self, reactor, service, line, use_json): def reload(self, reactor, service, line, use_json): reactor.signal.received = reactor.signal.RELOAD reactor.processes.write(service, 'reload in progress') - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True @@ -66,21 +66,21 @@ def reload(self, reactor, service, line, use_json): def restart(self, reactor, service, line, use_json): reactor.signal.received = reactor.signal.RESTART reactor.processes.write(service, 'restart in progress') - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True @Command.register('version', False) def version(self, reactor, service, line, use_json): reactor.processes.write(service, 'exabgp %s' % _version) - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True @Command.register('#', False) def comment(self, reactor, service, line, use_json): log.debug(line.lstrip().lstrip('#').strip(), 'process') - reactor.processes.answer_text_done(service) + reactor.processes.answer_done(service) return True diff --git a/src/exabgp/reactor/api/command/rib.py b/src/exabgp/reactor/api/command/rib.py index d22f0668a..7f8428bf7 100644 --- a/src/exabgp/reactor/api/command/rib.py +++ b/src/exabgp/reactor/api/command/rib.py @@ -80,7 +80,7 @@ def callback(): else: to_text(key, changes) yield True - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) return callback @@ -93,7 +93,7 @@ def show_adj_rib(self, reactor, service, line, use_json): try: rib = words[2] if not rib in ('in', 'out'): - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: if words[1] == 'adj-rib-in': @@ -101,11 +101,11 @@ def show_adj_rib(self, reactor, service, line, use_json): elif words[1] == 'adj-rib-out': rib = 'out' else: - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False if rib not in ('in', 'out'): - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False klass = NLRI @@ -140,24 +140,24 @@ def callback(self, peers): reactor.neighbor_rib_resend(peer_name) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: descriptions, command = extract_neighbors(line) peers = match_neighbors(reactor.established_peers(), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command, 'warning') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False reactor.asynchronous.schedule(service, command, callback(self, peers)) return True except ValueError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False @@ -175,14 +175,14 @@ def callback(self, peers, direction): reactor.neighbor_rib_in_clear(peer_name) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: descriptions, command = extract_neighbors(line) peers = match_neighbors(reactor.peers(), descriptions) if not peers: self.log_failure('no neighbor matching the command : %s' % command, 'warning') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False words = command.split() direction = 'in' if 'adj-rib-in' in words or 'in' in words else 'out' @@ -190,9 +190,9 @@ def callback(self, peers, direction): return True except ValueError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False except IndexError: self.log_failure('issue parsing the command') - reactor.processes.answer_error(service, use_json) + reactor.processes.answer_error(service) return False diff --git a/src/exabgp/reactor/api/command/watchdog.py b/src/exabgp/reactor/api/command/watchdog.py index 1810353f8..268e549f4 100644 --- a/src/exabgp/reactor/api/command/watchdog.py +++ b/src/exabgp/reactor/api/command/watchdog.py @@ -25,7 +25,7 @@ def callback(name): neighbor.rib.outgoing.announce_watchdog(name) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: name = line.split(' ')[2] @@ -46,7 +46,7 @@ def callback(name): neighbor.rib.outgoing.withdraw_watchdog(name) yield False - reactor.processes.answer_done(service, use_json) + reactor.processes.answer_done(service) try: name = line.split(' ')[2] diff --git a/src/exabgp/reactor/api/processes.py b/src/exabgp/reactor/api/processes.py index e1dc93227..0e8132781 100644 --- a/src/exabgp/reactor/api/processes.py +++ b/src/exabgp/reactor/api/processes.py @@ -70,6 +70,7 @@ def clean(self): self.fds = [] self._process = {} self._encoder = {} + self._ackjson = {} self._broken = [] self._respawning = {} @@ -146,8 +147,10 @@ def _start(self, process): run = configuration.get('run', '') if run: - api = configuration.get('encoder', '') - self._encoder[process] = Response.Text(text_version) if api == 'text' else Response.JSON(json_version) + use_json = configuration.get('encoder', 'text') == 'json' + self._encoder[process] = Response.JSON(json_version) if use_json else Response.Text(text_version) + # XXX: add an option to ack in JSON (do not break backward compatibility) + self._ackjson[process] = False self._process[process] = subprocess.Popen( run, @@ -321,29 +324,17 @@ def _answer(self, service, string, force=False): log.debug('responding to %s : %s' % (service, string.replace('\n', '\\n')), 'process') self.write(service, string) - def answer_done(self, service, use_json): - if use_json: - self.answer_json_done(service) + def answer_done(self, service): + if self._ackjson[service]: + self._answer(service, Answer.json_done) else: - self.answer_text_done(service) + self._answer(service, Answer.text_done) - def answer_text_done(self, service): - self._answer(service, Answer.text_done) - - def answer_json_done(self, service): - self._answer(service, Answer.json_done) - - def answer_error(self, service, use_json): - if use_json: - self.answer_json_error(service) + def answer_error(self, service): + if self._ackjson[service]: + self._answer(service, Answer.json_error) else: - self.answer_text_error(service) - - def answer_text_error(self, service): - self._answer(service, Answer.text_error) - - def answer_json_error(self, service): - self._answer(service, Answer.json_error) + self._answer(service, Answer.text_error) def _notify(self, neighbor, event): for process in neighbor.api[event]: