Skip to content

Commit

Permalink
convert function to the use_json way
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-mangin committed Oct 17, 2024
1 parent c479e53 commit f30ab92
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/exabgp/reactor/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,17 @@ def process(self, reactor, service, command):
# 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.json(reactor, service, command)
return self.response(reactor, service, command, True)
if 'text' in command.split(' '):
return self.text(reactor, service, command)
return self.text(reactor, service, command)
return self.response(reactor, service, command, False)
return self.response(reactor, service, command, False)

def text(self, reactor, service, command):
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['text'][registered](self, reactor, service, command, False)
reactor.processes.answer_text_error(service)
log.warning('command from process not understood : %s' % command, 'api')
return False

def json(self, reactor, service, command):
for registered in self.functions:
if registered == command or command.endswith(' ' + registered) or registered + ' ' in command:
return self.callback['json'][registered](self, reactor, service, command, True)
reactor.processes.answer_json_error(service)
return self.callback[api][registered](self, reactor, service, command, use_json)
reactor.processes.answer_error(service, use_json)
log.warning('command from process not understood : %s' % command, 'api')
return False

Expand Down

0 comments on commit f30ab92

Please sign in to comment.