A context manager that silences sys.stdout and sys.stderr.
183077
def _silence():
    """"""

    old_stdout = sys.stdout
    old_stderr = sys.stderr
    sys.stdout = _DummyFile()
    sys.stderr = _DummyFile()
    exception_occurred = False
    try:
        yield
    except:
        exception_occurred = True
        # Go ahead and clean up so that exception handling can work normally
        sys.stdout = old_stdout
        sys.stderr = old_stderr
        raise

    if not exception_occurred:
        sys.stdout = old_stdout
        sys.stderr = old_stderr
1133345
def safe_exit(output):
    """"""
    try:
        sys.stdout.write(output)
        sys.stdout.flush()
    except IOError:
        pass
1360936
def ignore_broken_pipe():
    
    for f in sys.stdin, sys.stdout, sys.stderr:
        try:
            f.close()
        except BrokenPipeError:
            pass
427472
def silence(cls, *modules, **kwargs):
        
        level = kwargs.pop("level", logging.WARNING)
        for mod in modules:
            name = mod.__name__ if hasattr(mod, "__name__") else mod
            logging.getLogger(name).setLevel(level)
1232626
def suppress_stdout():
    
    save_stdout = sys.stdout
    sys.stdout = DevNull()
    yield
    sys.stdout = save_stdout
352588
def shut_down():
    """"""
    curses.nocbreak()
    curses.echo()
    curses.endwin()
    gpsd_socket.close()
    print('Keyboard interrupt received\nTerminated by user\nGood Bye.\n')
    sys.exit(1)
168158
def sigint_handler(signum, frame):
    """"""
    global _handled_int
    if not _handled_int:
        _handled_int = True
        if not _env_var_true("_REZ_QUIET_ON_SIG"):
            print >> sys.stderr, "Interrupted by user"
        sigbase_handler(signum, frame)
331970
def stderr_output(cmd):
    """"""

    handle, gpg_stderr = stderr_handle()
    try:
        output = subprocess.check_output(cmd, stderr=gpg_stderr)  # nosec
        if handle:
            handle.close()

        return str(polite_string(output))
    except subprocess.CalledProcessError as exception:
        LOGGER.debug("GPG Command %s", ' '.join(exception.cmd))
        LOGGER.debug("GPG Output %s", exception.output)
        raise CryptoritoError('GPG Execution')
836273
def suppress_keyboard_interrupt_message():
    
    old_excepthook = sys.excepthook

    def new_hook(type, value, traceback):
        if type != KeyboardInterrupt:
            old_excepthook(type, value, traceback)
        else:
            sys.exit(130)

    sys.excepthook = new_hook
813052
def warning(*args):
    """"""
    if sys.stdin.isatty():
        print('WARNING:', *args, file=sys.stderr)
    else:
        notify_warning(*args)
1344995
def stop():
    '''
    
    '''
    ret = {'comment': '', 'success': False}

    cmd = __execute_cmd('riak', 'stop')

    if cmd['retcode'] != 0:
        ret['comment'] = cmd['stderr']
    else:
        ret['comment'] = cmd['stdout']
        ret['success'] = True

    return ret
1196950
def suppressConsoleOut(meth):
    """"""
    @wraps(meth)
    def decorate(*args, **kwargs):
        """Decorate"""
        # Disable ansible console output
        _stdout = sys.stdout
        fptr = open(os.devnull, 'w')
        sys.stdout = fptr
        try:
            return meth(*args, **kwargs)
        except Exception as e:
            raise e
        finally:
            # Enable console output
            sys.stdout = _stdout
    return decorate
658984
def stop_subprocess(pid):
    """"""
    if hasattr(os, "kill"):
        import signal
        os.kill(pid, signal.SIGTERM)
    else:
        import win32api
        pid = win32api.OpenProcess(1, 0, pid)
        win32api.TerminateProcess(pid, 0)
    os.waitpid(pid, 0)
885965
def no_interrupt(syscall, *args, **kwargs):
    
    ret = None

    while True:
        try:
            ret = syscall(*args, **kwargs)
        except OSError as e:
            if e.errno == errno.EINTR:
                continue
            else:
                raise
        else:
            break

    return ret
173685
def cli(context, verbose, quiet, database, sense):
    """"""
    logger = logging.getLogger()
    handler = logging.StreamHandler(sys.stderr)
    handler.setFormatter(LevelFormatter())
    logger.addHandler(handler)
    logger.setLevel(logging.WARNING + (quiet-verbose)*10)
    logging.debug(_('Subcommand: %s'), context.invoked_subcommand)
    context.obj['database'] = Database(database)
    try:
        context.obj['sense'] = SenseWithExport(sense).__enter__()
    except Exception:
        pass
1126712
def block(self):
        """"""
        if self._uses_subprocess:
            # consume stdout and stderr
            if self.blocking:
                try:
                    stdout, stderr = self.subprocess.communicate()
                    self.__out = stdout
                    self.__err = stderr
                except ValueError:
                    pass  # Don't read from finished subprocesses.
            else:
                self.subprocess.stdin.close()
                self.std_out.close()
                self.std_err.close()
                self.subprocess.wait()
        else:
            self.subprocess.sendeof()
            try:
                self.subprocess.wait()
            finally:
                if self.subprocess.proc.stdout:
                    self.subprocess.proc.stdout.close()
348325
def disable():
        """"""
        if os.name != 'nt' or not Windows.is_enabled():
            return False

        getattr(sys.stderr, '_reset_colors', lambda: False)()
        getattr(sys.stdout, '_reset_colors', lambda: False)()

        if isinstance(sys.stderr, _WindowsStream):
            sys.stderr = getattr(sys.stderr, 'original_stream')
        if isinstance(sys.stderr, _WindowsStream):
            sys.stdout = getattr(sys.stdout, 'original_stream')

        return True