Esempio n. 1
0
 def pump_stream(cmdline, name, stream, is_decode, handler):
     try:
         for line in stream:
             if handler:
                 if is_decode:
                     line = line.decode(defenc)
                 handler(line)
     except Exception as ex:
         log.error("Pumping %r of cmd(%s) failed due to: %r", name, cmdline, ex)
         raise CommandError(['<%s-pump>' % name] + cmdline, ex)
     finally:
         stream.close()
Esempio n. 2
0
 def pump_stream(cmdline: str, name: str, stream: Union[BinaryIO, TextIO], is_decode: bool,
                 handler: Union[None, Callable[[Union[bytes, str]], None]]) -> None:
     try:
         for line in stream:
             if handler:
                 if is_decode:
                     assert isinstance(line, bytes)
                     line_str = line.decode(defenc)
                     handler(line_str)
                 else:
                     handler(line)
     except Exception as ex:
         log.error("Pumping %r of cmd(%s) failed due to: %r", name, remove_password_if_present(cmdline), ex)
         raise CommandError(['<%s-pump>' % name] + remove_password_if_present(cmdline), ex) from ex
     finally:
         stream.close()