Esempio n. 1
0
def _get_random_data_from_user(uchars):
    m = 'Enter {} random symbols' if opt.quiet else crmsg['usr_rand_notice']
    msg(m.format(uchars))
    prompt = 'You may begin typing.  {} symbols left: '
    msg_r(prompt.format(uchars))

    import time
    from mmgen.term import get_char_raw, kb_hold_protect
    key_data, time_data = '', []

    for i in range(uchars):
        kb_hold_protect()
        key_data += get_char_raw()
        msg_r('\r' + prompt.format(uchars - i - 1))
        time_data.append(time.time())

    if opt.quiet: msg_r('\r')
    else: msg_r("\rThank you.  That's enough.{}\n\n".format(' ' * 18))

    fmt_time_data = map('{:.22f}'.format, time_data)
    dmsg('\nUser input:\n{!r}\nKeystroke time values:\n{}\n'.format(
        key_data, '\n'.join(fmt_time_data)))
    prompt = 'User random data successfully acquired.  Press ENTER to continue'
    prompt_and_get_char(prompt, '', enter_ok=True)

    return key_data + ''.join(fmt_time_data)
Esempio n. 2
0
def my_raw_input(prompt, echo=True, insert_txt='', use_readline=True):

    try:
        import readline
    except:
        use_readline = False  # Windows

    if use_readline and sys.stdout.isatty():

        def st_hook():
            readline.insert_text(insert_txt)

        readline.set_startup_hook(st_hook)
    else:
        msg_r(prompt)
        prompt = ''

    from mmgen.term import kb_hold_protect
    kb_hold_protect()
    if echo or not sys.stdin.isatty():
        reply = raw_input(prompt.encode('utf8'))
    else:
        from getpass import getpass
        reply = getpass(prompt.encode('utf8'))
    kb_hold_protect()

    try:
        return reply.strip().decode('utf8')
    except:
        die(1, 'User input must be UTF-8 encoded.')
Esempio n. 3
0
def my_raw_input(prompt, echo=True, insert_txt='', use_readline=True):

    try:
        import readline
    except:
        use_readline = False  # Windows

    if use_readline and sys.stdout.isatty():

        def st_hook():
            readline.insert_text(insert_txt)

        readline.set_startup_hook(st_hook)
    else:
        msg_r(prompt)
        prompt = ''

    from mmgen.term import kb_hold_protect
    kb_hold_protect()

    if g.test_suite_popen_spawn:
        msg(prompt)
        sys.stderr.flush()
        reply = os.read(0, 4096).decode()
    elif echo or not sys.stdin.isatty():
        reply = input(prompt)
    else:
        from getpass import getpass
        if g.platform == 'win':
            # MSWin hack - getpass('foo') doesn't flush stderr
            msg_r(prompt.strip())  # getpass('') adds a space
            sys.stderr.flush()
            reply = getpass('')
        else:
            reply = getpass(prompt)

    kb_hold_protect()

    try:
        return reply.strip()
    except:
        die(1, 'User input must be UTF-8 encoded.')
Esempio n. 4
0
def my_raw_input(prompt,echo=True,insert_txt="",use_readline=True):

	try: import readline
	except: use_readline = False # Windows

	if use_readline and sys.stdout.isatty():
		def st_hook(): readline.insert_text(insert_txt)
		readline.set_startup_hook(st_hook)
	else:
		msg_r(prompt)
		prompt = ""

	kb_hold_protect()
	if echo:
		reply = raw_input(prompt)
	else:
		from getpass import getpass
		reply = getpass(prompt)
	kb_hold_protect()

	return reply.strip()
Esempio n. 5
0
File: util.py Progetto: mmgen/mmgen
def my_raw_input(prompt,echo=True,insert_txt='',use_readline=True):

	try: import readline
	except: use_readline = False # Windows

	if use_readline and sys.stdout.isatty():
		def st_hook(): readline.insert_text(insert_txt)
		readline.set_startup_hook(st_hook)
	else:
		msg_r(prompt)
		prompt = ''

	from mmgen.term import kb_hold_protect
	kb_hold_protect()

	if g.test_suite_popen_spawn:
		msg(prompt)
		sys.stderr.flush()
		reply = os.read(0,4096).decode()
	elif echo or not sys.stdin.isatty():
		reply = input(prompt)
	else:
		from getpass import getpass
		if g.platform == 'win':
			# MSWin hack - getpass('foo') doesn't flush stderr
			msg_r(prompt.strip()) # getpass('') adds a space
			sys.stderr.flush()
			reply = getpass('')
		else:
			reply = getpass(prompt)

	kb_hold_protect()

	try:
		return reply.strip()
	except:
		die(1,'User input must be UTF-8 encoded.')