Exemplo n.º 1
0
    def _expect_prompt(self,
                       options,
                       countdown,
                       prompt_re=None,
                       earlier_re=None):
        if options['stop_on_silence'] is not False:
            prev = 0
            while 1:
                tmp = min(options['stop_on_silence'], countdown.left())
                silence_countdown = Countdown(tmp)
                try:
                    countdown.start()
                    try:
                        return PexpectMixin._expect_prompt(
                            self, options, silence_countdown, prompt_re,
                            earlier_re)
                    finally:
                        countdown.stop()
                except TimeoutException as ex:
                    # a real timeout
                    if countdown.did_run_out(
                    ) or silence_countdown.did_run_out():
                        raise

                    # inactivity or silence detected
                    if prev >= len(ex.output):
                        raise

                    prev = len(ex.output)

        else:
            return PexpectMixin._expect_prompt(self, options, countdown,
                                               prompt_re, earlier_re)
Exemplo n.º 2
0
    def _expect_prompt(self, options, timeout, prompt_re=None):
        if options['stop_on_silence'] is not False:
            silence_timeout = options['stop_on_silence']
            prev = 0
            while 1:
                try:
                    begin = time.time()
                    return PexpectMixin._expect_prompt(self, options,
                                                       silence_timeout,
                                                       prompt_re)
                except TimeoutException as ex:
                    timeout -= max(time.time() - begin, 0)
                    silence_timeout = min(silence_timeout, timeout)

                    # a real timeout
                    if timeout <= 0 or silence_timeout <= 0:
                        raise

                    # inactivity or silence detected
                    if prev >= len(ex.output):
                        raise

                    prev = len(ex.output)

        else:
            return PexpectMixin._expect_prompt(self, options, timeout,
                                               prompt_re)