本文整理汇总了Python中pexpect.EOF属性的典型用法代码示例。如果您正苦于以下问题:Python pexpect.EOF属性的具体用法?Python pexpect.EOF怎么用?Python pexpect.EOF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pexpect
的用法示例。
在下文中一共展示了pexpect.EOF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: after_scenario
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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()
示例2: _execute
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def _execute(self, cmd, skip_cwd=False, **kwargs):
"""
Additional Args:
skip_cwd (bool): Whether to skip changing to the current working
directory associated with this client before executing the
command. This is mainly useful to methods internal to this
class.
"""
template = 'ssh {login} -T -o ControlPath={socket} << EOF\n{cwd}{cmd}\nEOF'
config = dict(self._subprocess_config)
config.update(kwargs)
cwd = 'cd "{path}"\n'.format(path=escape_path(self.path_cwd)) if not skip_cwd else ''
return run_in_subprocess(template.format(login=self._login_info,
socket=self._socket_path,
cwd=cwd,
cmd=cmd),
check_output=True,
**config)
示例3: _stop_ssh_connection
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def _stop_ssh_connection(self, conn):
if not conn or PEXPECT_VERSION == NO_MODULE:
return
if PEXPECT_VERSION == NEW_MODULE:
conn.logout()
if conn:
conn.close()
elif PEXPECT_VERSION == OLD_MODULE:
conn.sendline('exit')
i = conn.expect([pexpect.EOF, "(?i)there are stopped jobs"])
if i == 1:
conn.sendline("exit")
conn.expect(pexpect.EOF)
if conn:
conn.close()
self.remote_system_command_prompt = '[#$] '
示例4: _try_passwordless_openssh
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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
示例5: readline
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def readline(self, size = -1):
"""This reads and returns one entire line. A trailing newline is kept
in the string, but may be absent when a file ends with an incomplete
line. Note: This readline() looks for a \\r\\n pair even on UNIX
because this is what the pseudo tty device returns. So contrary to what
you may expect you will receive the newline as \\r\\n. An empty string
is returned when EOF is hit immediately. Currently, the size argument is
mostly ignored, so this behavior is not standard for a file-like
object. If size is 0 then an empty string is returned. """
if size == 0:
return self._empty_buffer
index = self.expect ([self._pty_newline, self.delimiter]) # delimiter default is EOF
if index == 0:
return self.before + self._pty_newline
return self.before
示例6: expect_exact
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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)
示例7: __init__
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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))
示例8: change_password2
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def change_password2(old_passwd, new_passwd):
child = pexpect.spawn('passwd')
i = child.expect(['[Oo]ld [Pp]assword', '.current.*password', '[Nn]ew [Pp]assword'])
# Root does not require old password, so it gets to bypass the next step.
if i == 0 or i == 1:
child.sendline(old_passwd)
child.expect('[Nn]ew [Pp]assword')
child.sendline(new_passwd)
i = child.expect(['[Nn]ew [Pp]assword', '[Rr]etype', '[Rr]e-enter'])
if i == 0:
print('Host did not like new password. Here is what it said...')
print(child.before)
child.send(chr(3)) # Ctrl-C
child.sendline('') # This should tell remote passwd command to quit.
return
child.sendline(new_passwd)
child.expect(pexpect.EOF)
示例9: do_test_rebuilder
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def do_test_rebuilder(tree, path):
directory = mktree(FORGE_YAML + tree, MANGLE=MANGLE)
forge = launch(directory, "forge build containers")
forge.expect(pexpect.EOF)
assert forge.wait() == 0
assert run_image(directory).strip() == "hello"
with open(os.path.join(directory, path), "write") as f:
f.write('print("goodbye")\n')
forge = launch(directory, "forge build containers")
forge.expect(pexpect.EOF)
assert forge.wait() == 0
assert run_image(directory).strip() == "goodbye"
forge = launch(directory, "forge clean")
forge.expect("docker kill ")
forge.expect(pexpect.EOF)
assert forge.wait() == 0
示例10: recv_ClientInit
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def recv_ClientInit(self, block):
# start reward proxy.
self._log_info('Starting reward proxy server')
self.reward_proxy = pexpect.spawnu(self.factory.reward_proxy_bin,
logfile=sys.stdout,
timeout=None)
# wait on reward proxy to be up.
self._log_info('Waiting for reward proxy server')
self.reward_proxy.expect('\[RewardProxyServer\]')
self.reward_proxy_thread = threading.Thread(target=lambda: self.reward_proxy.expect(pexpect.EOF))
self.reward_proxy_thread.start()
self._log_info('Reward proxy server is up %s', self.reward_proxy.before)
super(DualProxyServer, self).recv_ClientInit(block)
self.logfile_dir = self.log_manager.logfile_dir
示例11: _pexpect_out
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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
示例12: readline
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [as 别名]
def readline (self, size = -1): # File-like object.
"""This reads and returns one entire line. A trailing newline is kept
in the string, but may be absent when a file ends with an incomplete
line. Note: This readline() looks for a \\r\\n pair even on UNIX
because this is what the pseudo tty device returns. So contrary to what
you may expect you will receive the newline as \\r\\n. An empty string
is returned when EOF is hit immediately. Currently, the size argument is
mostly ignored, so this behavior is not standard for a file-like
object. If size is 0 then an empty string is returned. """
if size == 0:
return ''
index = self.expect (['\r\n', self.delimiter]) # delimiter default is EOF
if index == 0:
return self.before + '\r\n'
else:
return self.before
示例13: expect_exact
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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)
示例14: __init__
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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))
示例15: init_scoutfish
# 需要导入模块: import pexpect [as 别名]
# 或者: from pexpect import EOF [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)")