本文整理汇总了Python中prompt_toolkit.prompt方法的典型用法代码示例。如果您正苦于以下问题:Python prompt_toolkit.prompt方法的具体用法?Python prompt_toolkit.prompt怎么用?Python prompt_toolkit.prompt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prompt_toolkit
的用法示例。
在下文中一共展示了prompt_toolkit.prompt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prompt_for_install
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def prompt_for_install(self):
"""
Prompt user to install untrusted repo signing key
"""
print(self.key_info)
repo_key_url = "{0}/{1}".format(self.url, self.repo_signing_key)
print(("warning: Repository key untrusted \n"
"Importing GPG key 0x{0}:\n"
" Userid: \"{1}\"\n"
" From : {2}".format(self.key_info['fingerprint'],
self.key_info['uids'][0],
repo_key_url)))
response = prompt(u'Is this ok: [y/N] ')
if response == 'y':
self.install_key(self.raw_key)
return True
else:
return False
示例2: input
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def input(self, more=False):
"""Prompt for code input."""
sys.stdout.flush()
if more:
msg = more_prompt
else:
msg = main_prompt
if self.style is not None:
internal_assert(prompt_toolkit is not None, "without prompt_toolkit cannot highlight style", self.style)
try:
return self.prompt(msg)
except EOFError:
raise # issubclass(EOFError, Exception), so we have to do this
except (Exception, AssertionError):
logger.display_exc()
logger.show_sig("Syntax highlighting failed; switching to --style none.")
self.style = None
return input(msg)
示例3: prompt
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def prompt(self, msg):
"""Get input using prompt_toolkit."""
try:
# prompt_toolkit v2
prompt = prompt_toolkit.PromptSession(history=self.history).prompt
except AttributeError:
# prompt_toolkit v1
prompt = partial(prompt_toolkit.prompt, history=self.history)
return prompt(
msg,
multiline=self.multiline,
vi_mode=self.vi_mode,
wrap_lines=self.wrap_lines,
enable_history_search=self.history_search,
lexer=PygmentsLexer(CoconutLexer),
style=style_from_pygments_cls(
pygments.styles.get_style_by_name(self.style),
),
)
示例4: set_config
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def set_config(self):
ip_listening = prompt('Set IP to listening: ')
port_listening = prompt('Set PORT to listening: ')
payload_choice = prompt('Choose into insert payload:\n1 - pre-commit\n2 - pre-push\n:> ')
payload_hook = lambda choice: "pre-commit" if choice == "1" else "pre-push"
payload = payload_hook(payload_choice)
payload_content = pl.generate(ip_listening, port_listening, payload)
filename = self.write_payload(payload_content)
save_config = prompt('Save configuration? [y] [n]\n:> ')
if 'y' == save_config.lower():
output_config = open('conf/conf_payload.conf', 'w')
output_config.write('{}|{}|{}'.format(ip_listening, port_listening, payload))
output_config.close()
elif 'n' == save_config.lower():
pass
print('\n[+] File in output/{}'.format(filename))
listen_response = prompt('Listening backdoor? [y] [n]\n:> ')
if 'y' == listen_response.lower():
self.listening(ip_listening, port_listening)
#pass
else:
self.start()
示例5: gen_backdoor
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def gen_backdoor(self):
os.system('clear')
print(self.gen_menu)
while 1:
user_input = prompt(':> ')
if '1' == user_input:
self.set_config()
elif '2' == user_input:
self.get_config()
elif 'back' == user_input:
self.start()
else:
os.system('clear')
print('Chose one option')
print(self.gen_menu)
示例6: remove_db_job_by_id
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def remove_db_job_by_id(preset=None):
"""
removes rms job from db by id
"""
if preset:
job_id = preset
else:
print(" please enter job_id to run")
job_id = prompt("> run_job_by_db_id> ", **sub_prompt_options)
job_id = int(job_id)
job = rms_db.get(doc_id=job_id)
if job:
list_jobs(by_id=job_id)
cmd_str = serdes(job=job)
print(colorful.cyan(" got removed from db"))
job = rms_db.remove(doc_ids=[job_id])
else:
print(" no job with this id found")
示例7: run_db_job
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def run_db_job():
"""
runs a job from database
"""
print(" please enter: '<project_code>'")
project_code = prompt("> run_job> ", **sub_prompt_options)
print(" please enter: '<command>'")
command = prompt("> run_job> ", **sub_prompt_options)
print(f"to be run: 'python process_model.py {project_code} {command}'")
job_id = rms_db.get((Query()["<project_code>"] == project_code) & (Query()["<command>"] == command)).doc_id
job = rms_db.get(doc_id=job_id)
if job_id:
cmd_tokens = serdes(job=job[0])
cmd_str = " ".join(cmd_tokens)
if check_model_path(job_id):
print(cmd_str)
subprocess.Popen(cmd_str)
else:
print(" no job with this id found")
示例8: run_db_job_by_id
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def run_db_job_by_id(preset=None):
"""
runs a job from database by id
"""
if preset:
job_id = preset
else:
print(" please enter job_id to run")
job_id = prompt("> run_job_by_db_id> ", **sub_prompt_options)
if job_id:
job_id = int(job_id)
job = rms_db.get(doc_id=job_id)
if job:
# print(job)
cmd_tokens = serdes(job=job)
# print(cmd_tokens)
cmd_str = " ".join(cmd_tokens)
if check_model_path(job_id):
print("cmd_str:", cmd_str)
subprocess.Popen(cmd_str)
else:
print(" no job with this id found")
示例9: show_db_job_by_id
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def show_db_job_by_id(preset=None):
"""
show config details of rms job from db by id
"""
if not preset:
print(" please enter job_id to show details")
job_id = prompt("> show_job_by_db_id> ", **sub_prompt_options)
job_id = int(job_id)
else:
job_id = int(preset)
job = rms_db.get(doc_id=job_id)
if job:
list_jobs(by_id=job_id)
cmd_str = serdes(job=job)
print(colorful.cyan("\n command:"))
print(cmd_str)
return
else:
print(" no job with this id found")
示例10: login
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def login(self):
global s
print("\n[!] checking cookies")
time.sleep(1)
s = self.req
s.cookies = kuki('toket/kue.txt')
try:
fil=open('toket/kue.txt')
fil.close()
except FileNotFoundError:
print("[!] cookies not found\n\n[!] please login in your facebook once again")
email=input('[?] email/username: ')
pw=prompt('[?] password: ', is_password=True)
data = {'email':email,'pass':pw}
res = s.post('https://mbasic.facebook.com/login',data=data).text
if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
s.cookies.save()
else:
exit('[!] fail login into your account')
if 'True' in cek():
pass
else:
exit()
示例11: login
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def login():
print("\n[!] checking cookies")
time.sleep(1)
s = ses()
s.cookies = kuki('toket/kue.txt')
try:
fil=open('toket/kue.txt')
fil.close()
except FileNotFoundError:
print("[!] cookies not found\n\n[!] please login in your facebook once again")
email=input('[?] email/username: ')
pw=prompt('[?] password: ',is_password=True)
data = {'email':email,'pass':pw}
url='https://mbasic.facebook.com/login'
res = s.post(url,data=data).text
if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
s.cookies.save()
else:
exit('[!] fail login into your account')
示例12: cmdloop
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def cmdloop(self, intro=None):
"""A Cmd.cmdloop implementation"""
style = style_from_pygments(BasicStyle, style_dict)
self.preloop()
stop = None
while not stop:
line = prompt(get_prompt_tokens=get_prompt_tokens, lexer=lexer,
get_bottom_toolbar_tokens=get_bottom_toolbar_tokens,
history=history, style=style, true_color=True,
on_exit='return-none', on_abort='return-none',
completer=QCompleter())
if line is None or line.strip() == r'\\':
raise SystemExit
else:
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()
示例13: _prompt_sub_id_selection
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def _prompt_sub_id_selection(c):
# Importing here to avoid overhead to the rest of the application
from tabulate import tabulate
from toolz import pipe
import json
from prompt_toolkit import prompt
results = c.run(f"az account list", pty=True, hide="out")
parsestr = "["+results.stdout[1:-7]+"]" #TODO: Figure why this is necessary
sub_dict = json.loads(parsestr)
sub_list = [
{"Index": i, "Name": sub["name"], "id": sub["id"]}
for i, sub in enumerate(sub_dict)
]
pipe(sub_list, tabulate, print)
prompt_result = prompt("Please type in index of subscription you want to use: ")
sub_id = sub_list[int(prompt_result)]["id"]
print(f"You selected index {prompt_result} sub id {sub_id}")
return sub_id
示例14: config_settings
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def config_settings(event):
""" opens the configuration """
global PROMPTING
telemetry.track_key('F1')
PROMPTING = True
config = azclishell.configuration.CONFIGURATION
answer = ""
questions = {
"Do you want command descriptions" : "command_description",
"Do you want parameter descriptions" : "param_description",
"Do you want examples" : "examples"
}
for question in questions:
while answer.lower() != 'y' and answer.lower() != 'n':
answer = prompt(u'\n%s (y/n): ' % question)
config.set_val('Layout', questions[question], format_response(answer))
answer = ""
PROMPTING = False
print("\nPlease restart shell for changes to take effect.\n\n")
event.cli.set_return_value(event.cli.current_buffer)
示例15: prompt_continuation
# 需要导入模块: import prompt_toolkit [as 别名]
# 或者: from prompt_toolkit import prompt [as 别名]
def prompt_continuation(width, line_number, wrap_count):
"""
The continuation: display line numbers and '->' before soft wraps.
Notice that we can return any kind of formatted text from here.
The prompt continuation doesn't have to be the same width as the prompt
which is displayed before the first line, but in this example we choose to
align them. The `width` input that we receive here represents the width of
the prompt.
"""
if wrap_count > 0:
return " " * (width - 3) + "-> "
else:
text = ("- %i - " % (line_number + 1)).rjust(width)
return HTML("<strong>%s</strong>") % text