MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / __error_retry_input

Method __error_retry_input

client/util/smartinput.py:34–54  ·  view source on GitHub ↗

检查输入,如果输入有误,重新提示输入,直到输入正确,或超过最多重试次数 :param input_data: 输入数据 :param check_func: 检查回调函数,返回True(输入正确)|False(输入有误) :param retry_prompt: 重试输入的提示信息 :param retry_times: 重试总次数,默认可以重试2次 :param is_password: 是否是密码输入 :return:

(self, input_data, check_func, retry_prompt, retry_times, is_password=False)

Source from the content-addressed store, hash-verified

32 return input_data
33
34 def __error_retry_input(self, input_data, check_func, retry_prompt, retry_times, is_password=False):
35 """
36 检查输入,如果输入有误,重新提示输入,直到输入正确,或超过最多重试次数
37 :param input_data: 输入数据
38 :param check_func: 检查回调函数,返回True(输入正确)|False(输入有误)
39 :param retry_prompt: 重试输入的提示信息
40 :param retry_times: 重试总次数,默认可以重试2次
41 :param is_password: 是否是密码输入
42 :return:
43 """
44 if check_func(input_data):
45 return input_data
46 else: # 不符合要求,需要重试
47 retry_cnt = 1
48 while retry_cnt <= retry_times:
49 input_data = self.__base_input(retry_prompt, is_password)
50 if check_func(input_data):
51 return input_data
52 retry_cnt += 1
53 logger.error("%s次输入错误,退出!" % (retry_times+1))
54 raise InputRetryError("%s次输入错误,退出!" % (retry_times+1))
55
56 def input(self, prompt, check_func=None, retry_prompt=None, retry_times=2, is_password=False):
57 """

Callers 1

inputMethod · 0.95

Calls 3

__base_inputMethod · 0.95
InputRetryErrorClass · 0.90
errorMethod · 0.80

Tested by

no test coverage detected