MCPcopy Index your code
hub / github.com/pyload/pyload / ask

Method ask

module/setup.py:450–517  ·  view source on GitHub ↗

produce one line to asking for input

(self, qst, default, answers=[], bool=False, password=False)

Source from the content-addressed store, hash-verified

448 return False
449
450 def ask(self, qst, default, answers=[], bool=False, password=False):
451 """produce one line to asking for input"""
452 if answers:
453 info = "("
454
455 for i, answer in enumerate(answers):
456 info += (", " if i != 0 else "") + str((answer == default and "[%s]" % answer) or answer)
457
458 info += ")"
459 elif bool:
460 if default == self.yes:
461 info = "([%s]/%s)" % (self.yes, self.no)
462 else:
463 info = "(%s/[%s])" % (self.yes, self.no)
464 else:
465 info = "[%s]" % default
466
467 if password:
468 p1 = True
469 p2 = False
470 while p1 != p2:
471 # getpass(_("Password: ")) will crash on systems with broken locales (Win, NAS)
472 sys.stdout.write(_("Password: "))
473 p1 = getpass("")
474
475 if len(p1) < 4:
476 print _("Password too short. Use at least 4 symbols.")
477 continue
478
479 sys.stdout.write(_("Password (again): "))
480 p2 = getpass("")
481
482 if p1 == p2:
483 return p1
484 else:
485 print _("Passwords did not match.")
486
487 while True:
488 try:
489 input = raw_input(qst + " %s: " % info)
490 except KeyboardInterrupt:
491 print "\nSetup interrupted"
492 exit(2)
493
494 input = input.decode(self.stdin_encoding)
495
496 if input.strip() == "":
497 input = default
498
499 if bool:
500 # yes, true,t are inputs for booleans with value true
501 if input.lower().strip() in [self.yes, _("yes"), _("true"), _("t"), "yes"]:
502 return True
503 # no, false,f are inputs for booleans with value false
504 elif input.lower().strip() in [self.no, _("no"), _("false"), _("f"), "no"]:
505 return False
506 else:
507 print _("Invalid Input")

Callers 6

startMethod · 0.95
conf_basicMethod · 0.95
conf_webMethod · 0.95
conf_sslMethod · 0.95
set_userMethod · 0.95
conf_pathMethod · 0.95

Calls 3

decodeMethod · 0.80
_Function · 0.50
writeMethod · 0.45

Tested by

no test coverage detected