<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import sys <EOL> import textwrap <EOL> from getpass import getpass as getPass <EOL> from . import ansi , utils <EOL> from . utils import minisix <EOL> from supybot . i18n import PluginInternationalization <EOL> _ = PluginInternationalization ( ) <EOL> useBold = False <EOL> def output ( s , unformatted = True , fd = sys . stdout ) : <EOL> if unformatted : <EOL> s = textwrap . fill ( utils . str . normalizeWhitespace ( s ) , width = <NUM_LIT> ) <EOL> print ( s , file = fd ) <EOL> print ( '<STR_LIT>' , file = fd ) <EOL> def expect ( prompt , possibilities , recursed = False , default = None , <EOL> acceptEmpty = False , fd = sys . stdout ) : <EOL> """<STR_LIT>""" <EOL> prompt = utils . str . normalizeWhitespace ( prompt ) <EOL> originalPrompt = prompt <EOL> if recursed : <EOL> output ( _ ( '<STR_LIT>' ) ) <EOL> if useBold : <EOL> choices = '<STR_LIT>' % ( ansi . RESET , ansi . BOLD ) <EOL> else : <EOL> choices = '<STR_LIT>' <EOL> if possibilities : <EOL> prompt = '<STR_LIT>' % ( originalPrompt , choices % '<STR_LIT:/>' . join ( possibilities ) ) <EOL> if len ( prompt ) > <NUM_LIT> : <EOL> prompt = '<STR_LIT>' % ( originalPrompt , choices % '<STR_LIT>' . join ( possibilities ) ) <EOL> if default is not None : <EOL> if useBold : <EOL> prompt = '<STR_LIT>' % ( prompt , ansi . RESET , default ) <EOL> else : <EOL> prompt = '<STR_LIT>' % ( prompt , default ) <EOL> prompt = textwrap . fill ( prompt ) <EOL> prompt = prompt . replace ( '<STR_LIT>' , '<STR_LIT:/>' ) <EOL> prompt = prompt . strip ( ) + '<STR_LIT:U+0020>' <EOL> if useBold : <EOL> prompt += ansi . RESET <EOL> print ( ansi . BOLD , end = '<STR_LIT:U+0020>' , file = fd ) <EOL> if minisix . PY3 : <EOL> s = input ( prompt ) <EOL> else : <EOL> s = raw_input ( prompt ) <EOL> s = s . strip ( ) <EOL> print ( file = fd ) <EOL> if possibilities : <EOL> if s in possibilities : <EOL> return s <EOL> elif not s and default is not None : <EOL> return default <EOL> elif not s and acceptEmpty : <EOL> return s <EOL> else : <EOL> return expect ( originalPrompt , possibilities , recursed = True , <EOL> default = default ) <EOL> else : <EOL> if not s and default is not None : <EOL> return default <EOL> return s . strip ( ) <EOL> def anything ( prompt ) : <EOL> """<STR_LIT>""" <EOL> return expect ( prompt , [ ] ) <EOL> def something ( prompt , default = None ) : <EOL> """<STR_LIT>""" <EOL> s = expect ( prompt , [ ] , default = default ) <EOL> while not s : <EOL> output ( _ ( '<STR_LIT>' ) ) <EOL> s = expect ( prompt , [ ] , default = default ) <EOL> return s <EOL> def yn ( prompt , default = None ) : <EOL> """<STR_LIT>""" <EOL> if default is not None : <EOL> if default : <EOL> default = '<STR_LIT:y>' <EOL> else : <EOL> default = '<STR_LIT:n>' <EOL> s = expect ( prompt , [ '<STR_LIT:y>' , '<STR_LIT:n>' ] , default = default ) <EOL> if s == '<STR_LIT:y>' : <EOL> return True <EOL> else : <EOL> return False <EOL> def getpass ( prompt = None , secondPrompt = None ) : <EOL> """<STR_LIT>""" <EOL> if prompt is None : <EOL> prompt = _ ( '<STR_LIT>' ) <EOL> if secondPrompt is None : <EOL> secondPrompt = _ ( '<STR_LIT>' ) <EOL> password = '<STR_LIT>' <EOL> secondPassword = '<STR_LIT:U+0020>' <EOL> assert prompt <EOL> if not prompt [ - <NUM_LIT:1> ] . isspace ( ) : <EOL> prompt += '<STR_LIT:U+0020>' <EOL> while True : <EOL> if useBold : <EOL> prompt = ansi . BOLD + prompt + ansi . RESET <EOL> secondPrompt = ansi . BOLD + secondPrompt + ansi . RESET <EOL> password = getPass ( prompt ) <EOL> secondPassword = getPass ( secondPrompt ) <EOL> if password != secondPassword : <EOL> output ( _ ( '<STR_LIT>' ) ) <EOL> else : <EOL> break <EOL> print ( '<STR_LIT>' ) <EOL> return password </s>
