当前位置: 首页>>代码示例>>Python>>正文


Python pexpect.TIMEOUT属性代码示例

本文整理汇总了Python中pexpect.TIMEOUT属性的典型用法代码示例。如果您正苦于以下问题:Python pexpect.TIMEOUT属性的具体用法?Python pexpect.TIMEOUT怎么用?Python pexpect.TIMEOUT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pexpect的用法示例。


在下文中一共展示了pexpect.TIMEOUT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: after_scenario

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def after_scenario(context, scenario):
    """Cleans up after each scenario completes."""
    if hasattr(context, "cli") and context.cli and not context.exit_sent:
        # Quit nicely.
        if not context.atprompt:
            dbname = context.currentdb
            context.cli.expect_exact("{0}> ".format(dbname), timeout=15)
        context.cli.sendcontrol("c")
        context.cli.sendcontrol("d")
        try:
            context.cli.expect_exact(pexpect.EOF, timeout=15)
        except pexpect.TIMEOUT:
            print("--- after_scenario {}: kill cli".format(scenario.name))
            context.cli.kill(signal.SIGKILL)
    if hasattr(context, "tmpfile_sql_help") and context.tmpfile_sql_help:
        context.tmpfile_sql_help.close()
        context.tmpfile_sql_help = None


# # TODO: uncomment to debug a failure
# def after_step(context, step):
#     if step.status == "failed":
#         import pdb; pdb.set_trace() 
开发者ID:dbcli,项目名称:pgcli,代码行数:25,代码来源:environment.py

示例2: _prepare_smartcard

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def _prepare_smartcard(self, name, filename):
        import pexpect

        remover = pexpect.spawn('ssh-add -e "{}"'.format(filename))
        i = remover.expect(["Card removed:", "Could not remove card", pexpect.TIMEOUT])
        if i == 2:
            raise RuntimeError("Unable to reset card using ssh-agent. Output of ssh-agent was: \n{}\n\n"
                               "Please report this error!".format(remover.before))

        adder = pexpect.spawn('ssh-add -s "{}" -t 14400'.format(filename))
        i = adder.expect(['Enter passphrase for PKCS#11:', pexpect.TIMEOUT])
        if i == 0:
            adder.sendline(getpass.getpass('Please enter your passcode to unlock your "{}" smartcard: '.format(name)))
        else:
            raise RuntimeError("Unable to add card using ssh-agent. Output of ssh-agent was: \n{}\n\n"
                               "Please report this error!".format(remover.before))
        i = adder.expect(['Card added:', pexpect.TIMEOUT])
        if i != 0:
            raise RuntimeError("Unexpected error while adding card. Check your passcode and try again.")

        return True 
开发者ID:airbnb,项目名称:omniduct,代码行数:23,代码来源:base.py

示例3: connect

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def connect(user, host, password):
    ssh_newkey = 'Are you sure you want to continue connecting'
    connStr = 'ssh ' + user + '@' + host
    child = pexpect.spawn(connStr)
    ret = child.expect([pexpect.TIMEOUT, ssh_newkey, '[P|p]assword:'])

    #超时,返回0
    if ret == 0:
        print '[-] Error Connecting'
        return

    if ret == 1:
        child.sendline('yes')
        ret = child.expect([pexpect.TIMEOUT, '[P|p]assword:'])

    if ret == 0:
        print '[-] Error Connecting'
        return

    child.sendline(password)
    child.expect(PROMPT)
    return child 
开发者ID:sunshinelyz,项目名称:python-hacker,代码行数:24,代码来源:ssh_connection.py

示例4: _try_passwordless_openssh

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def _try_passwordless_openssh(server, keyfile):
    """Try passwordless login with shell ssh command."""
    if pexpect is None:
        raise ImportError("pexpect unavailable, use paramiko")
    cmd = 'ssh -f '+ server
    if keyfile:
        cmd += ' -i ' + keyfile
    cmd += ' exit'
    p = pexpect.spawn(cmd)
    while True:
        try:
            p.expect('[Pp]assword:', timeout=.1)
        except pexpect.TIMEOUT:
            continue
        except pexpect.EOF:
            return True
        else:
            return False 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:tunnel.py

示例5: expect_exact

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def expect_exact(self, pattern_list, timeout = -1, searchwindowsize = -1):

        """This is similar to expect(), but uses plain string matching instead
        of compiled regular expressions in 'pattern_list'. The 'pattern_list'
        may be a string; a list or other sequence of strings; or TIMEOUT and
        EOF.

        This call might be faster than expect() for two reasons: string
        searching is faster than RE matching and it is possible to limit the
        search to just the end of the input buffer.

        This method is also useful when you don't want to have to worry about
        escaping regular expression characters that you want to match."""

        if isinstance(pattern_list, (bytes, unicode)) or pattern_list in (TIMEOUT, EOF):
            pattern_list = [pattern_list]
        return self.expect_loop(searcher_string(pattern_list), timeout, searchwindowsize) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:_pexpect.py

示例6: __init__

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def __init__(self, strings):

        """This creates an instance of searcher_string. This argument 'strings'
        may be a list; a sequence of strings; or the EOF or TIMEOUT types. """

        self.eof_index = -1
        self.timeout_index = -1
        self._strings = []
        for n, s in enumerate(strings):
            if s is EOF:
                self.eof_index = n
                continue
            if s is TIMEOUT:
                self.timeout_index = n
                continue
            self._strings.append((n, s)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:18,代码来源:_pexpect.py

示例7: _pexpect_out

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def _pexpect_out(self):
        if self.subprocess.encoding:
            result = ""
        else:
            result = b""

        if self.subprocess.before:
            result += self.subprocess.before

        if self.subprocess.after and self.subprocess.after not in (pexpect.EOF, pexpect.TIMEOUT):
            try:
                result += self.subprocess.after
            except (pexpect.EOF, pexpect.TIMEOUT):
                pass

        result += self.subprocess.read()
        return result 
开发者ID:pypa,项目名称:pipenv,代码行数:19,代码来源:delegator.py

示例8: prompt

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def prompt(self, timeout=-1):
        '''Match the next shell prompt.

        This is little more than a short-cut to the :meth:`~pexpect.spawn.expect`
        method. Note that if you called :meth:`login` with
        ``auto_prompt_reset=False``, then before calling :meth:`prompt` you must
        set the :attr:`PROMPT` attribute to a regex that it will use for
        matching the prompt.

        Calling :meth:`prompt` will erase the contents of the :attr:`before`
        attribute even if no prompt is ever matched. If timeout is not given or
        it is set to -1 then self.timeout is used.

        :return: True if the shell prompt was matched, False if the timeout was
                 reached.
        '''

        if timeout == -1:
            timeout = self.timeout
        i = self.expect([self.PROMPT, TIMEOUT], timeout=timeout)
        if i==1:
            return False
        return True 
开发者ID:pypa,项目名称:pipenv,代码行数:25,代码来源:pxssh.py

示例9: _sendline

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def _sendline(self, line):
        '''Internal method to interact with hpacucli.

Send a command to the hpacucli, wait for the prompt and
returns the output string.
'''
        if self.debug:
            print(line)
        self.process.sendline(line)
        try:
            self.process.expect(PROMPT_REGEXP)
            ret = self.process.before[len(line):]
        except pexpect.TIMEOUT:
            ret = 'Error: timeout'

        parse_error(ret)
        return ret 
开发者ID:redhat-cip,项目名称:hardware,代码行数:19,代码来源:hpacucli.py

示例10: expect_exact

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def expect_exact(self, pattern_list, timeout = -1, searchwindowsize = -1):

        """This is similar to expect(), but uses plain string matching instead
        of compiled regular expressions in 'pattern_list'. The 'pattern_list'
        may be a string; a list or other sequence of strings; or TIMEOUT and
        EOF.

        This call might be faster than expect() for two reasons: string
        searching is faster than RE matching and it is possible to limit the
        search to just the end of the input buffer.

        This method is also useful when you don't want to have to worry about
        escaping regular expression characters that you want to match."""

        if type(pattern_list) in types.StringTypes or pattern_list in (TIMEOUT, EOF):
            pattern_list = [pattern_list]
        return self.expect_loop(searcher_string(pattern_list), timeout, searchwindowsize) 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:19,代码来源:pexpect.py

示例11: __init__

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def __init__(self, strings):

        """This creates an instance of searcher_string. This argument 'strings'
        may be a list; a sequence of strings; or the EOF or TIMEOUT types. """

        self.eof_index = -1
        self.timeout_index = -1
        self._strings = []
        for n, s in zip(range(len(strings)), strings):
            if s is EOF:
                self.eof_index = n
                continue
            if s is TIMEOUT:
                self.timeout_index = n
                continue
            self._strings.append((n, s)) 
开发者ID:theralfbrown,项目名称:smod-1,代码行数:18,代码来源:pexpect.py

示例12: init_scoutfish

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def init_scoutfish(self):
        """ Create/open .scout database index file to help querying
            using scoutfish from https://github.com/mcostalba/scoutfish
        """
        if scoutfish_path is not None and self.path and self.size > 0:
            try:
                if self.progressbar is not None:
                    from gi.repository import GLib
                    GLib.idle_add(self.progressbar.set_text, _("Creating .scout index file..."))
                self.scoutfish = Scoutfish(engine=(scoutfish_path, ))
                self.scoutfish.open(self.path)
                scout_path = os.path.splitext(self.path)[0] + '.scout'
                if getmtime(self.path) > getmtime(scout_path):
                    self.scoutfish.make()
            except OSError as err:
                self.scoutfish = None
                log.warning("Failed to sart scoutfish. OSError %s %s" % (err.errno, err.strerror))
            except pexpect.TIMEOUT:
                self.scoutfish = None
                log.warning("scoutfish failed (pexpect.TIMEOUT)")
            except pexpect.EOF:
                self.scoutfish = None
                log.warning("scoutfish failed (pexpect.EOF)") 
开发者ID:pychess,项目名称:pychess,代码行数:25,代码来源:pgn.py

示例13: __init__

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def __init__(self, strings):

        '''This creates an instance of searcher_string. This argument 'strings'
        may be a list; a sequence of strings; or the EOF or TIMEOUT types. '''

        self.eof_index = -1
        self.timeout_index = -1
        self._strings = []
        for n, s in enumerate(strings):
            if s is EOF:
                self.eof_index = n
                continue
            if s is TIMEOUT:
                self.timeout_index = n
                continue
            self._strings.append((n, s)) 
开发者ID:c-amr,项目名称:camr,代码行数:18,代码来源:__init__.py

示例14: __str__

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def __str__(self):

        '''This returns a human-readable string that represents the state of
        the object.'''

        #ss = [(n, '    %d: re.compile("%s")' %
        #    (n, repr(s.pattern))) for n, s in self._searches]
        ss = list()
        for n, s in self._searches:
            try:
                ss.append((n, '    %d: re.compile("%s")' % (n, s.pattern)))
            except UnicodeEncodeError:
                # for test cases that display __str__ of searches, dont throw
                # another exception just because stdout is ascii-only, using
                # repr()
                ss.append((n, '    %d: re.compile(%r)' % (n, s.pattern)))
        ss.append((-1, 'searcher_re:'))
        if self.eof_index >= 0:
            ss.append((self.eof_index, '    %d: EOF' % self.eof_index))
        if self.timeout_index >= 0:
            ss.append((self.timeout_index, '    %d: TIMEOUT' %
                self.timeout_index))
        ss.sort()
        ss = list(zip(*ss))[1]
        return '\n'.join(ss) 
开发者ID:c-amr,项目名称:camr,代码行数:27,代码来源:__init__.py

示例15: _Cmd

# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import TIMEOUT [as 别名]
def _Cmd(self, command, mode=None):

    def SendAndWait(command):
      """Sends a command and waits for a response."""
      self._connection.child.send(command+'\r')
      self._connection.child.expect('\r\n', timeout=self.timeout_response)
      self._connection.child.expect(self._connection.re_prompt,
                                    timeout=self.timeout_response,
                                    searchwindowsize=128)
      return self._connection.child.before.replace('\r\n', os.linesep)

    _ = mode
    command = command.replace('?', '')
    if next((command
             for prefix in self.verboten_commands
             if command.startswith(prefix)), False):
      raise exceptions.CmdError(
          'Command %s is not permitted on Brocade devices.' % command)
    result = ''
    try:
      result = SendAndWait(command)
    except pexpect.TIMEOUT, e:
      self.connected = False
      raise exceptions.CmdError('%s: %s' % (e.__class__, str(e))) 
开发者ID:google,项目名称:ldpush,代码行数:26,代码来源:brocade.py


注:本文中的pexpect.TIMEOUT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。