From 742a075426fa64589080df7efdf32c8689cd0ec0 Mon Sep 17 00:00:00 2001 From: Patrick Pellissier Date: Wed, 20 Nov 2019 21:57:13 +0100 Subject: [PATCH 1/2] Improvement of string concatenation by use of buffer --- pyFG/fortios.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyFG/fortios.py b/pyFG/fortios.py index 23feef6..01daefa 100644 --- a/pyFG/fortios.py +++ b/pyFG/fortios.py @@ -150,8 +150,20 @@ def execute_command(self, command): output = '' for e in error_chan.read(): error = error + self._read_wrapper(e) + + _buf = "" + _bufcnt = 0 + _bufmaxlength = 2048 + for o in output_chan.read(): - output = output + self._read_wrapper(o) + _buf = _buf + self._read_wrapper(o) + _bufcnt += 1 + if _bufcnt > _bufmaxlength: + output = output + _buf + _buf = "" + _bufcnt = 0 + if _bufcnt > 0: + output = output + _buf if len(error) > 0: msg = '%s %s:\n%s\n%s' % (err_msg, self.ssh.get_host_keys().keys()[0], command, error) From ffd3e6af16d0e8f8d56fbae414f11e6f3c4d233a Mon Sep 17 00:00:00 2001 From: Patrick Pellissier Date: Wed, 20 Nov 2019 22:18:01 +0100 Subject: [PATCH 2/2] Correction of empty error stream --- pyFG/fortios.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyFG/fortios.py b/pyFG/fortios.py index 01daefa..590becb 100644 --- a/pyFG/fortios.py +++ b/pyFG/fortios.py @@ -148,9 +148,12 @@ def execute_command(self, command): error = '' output = '' - for e in error_chan.read(): - error = error + self._read_wrapper(e) - + try: + for e in error_chan.read(): + error = error + self._read_wrapper(e) + except: + pass + _buf = "" _bufcnt = 0 _bufmaxlength = 2048