original_docstring: Prompt the user for input and return a value based on response.
docstring: Prompt the user for input and return a value based on response.
docstring_tokens: Prompt the user for input and return a value based on response .
code: def prompt(self, text, reps=[],
                 wrap_length=None, kind='bool', default=None,
                 none_string='None of the above.', colorify=True, single=False,
                 options=None, translate=True, message=True, color='',
                 allow_blank=True):
          """Prompt the user for input and return a value based on response."""
          if wrap_length and is_integer(wrap_length):
              wl = wrap_length
          else:
              wl = self._wrap_length
  
          if kind in ['select', 'option', 'bool']:
              if kind == 'bool':
                  options = [('', 'y'), ('', 'n')]
                  if default is None:
                      default = 'n'
                  single = True
                  none_string = None
              if none_string is not None:
                  options.append((none_string, 'n'))
              if default is None and none_string is None:
                  default = (
                      str(options[0][-1]) if isinstance(options[0], tuple)
                      else '1')
  
          while True:
              if kind in ['select', 'option', 'bool']:
                  opt_sels = [
                      (str(x[-1]) if isinstance(x, tuple) else str(xi + 1))
                      for xi, x in enumerate(options)]
                  opt_strs = [
                      (('[' + str(x) + '.]') if x == default else x + '.')
                      for x in opt_sels]
                  opt_nops = [(('[' + str(x) + ']') if x == default else x)
                              for x in opt_sels]
                  opt_labs = [(opt[0] if isinstance(opt, tuple) else opt)
                              for opt in options]
                  opt_labs = [x.decode('utf-8') if not isinstance(x, str)
                              else x for x in opt_labs]
                  new_opts = dict(zip(*(opt_sels, opt_labs)))
  
                  if single:
                      choices = ' (' + '/'.join(opt_nops) + ')'
                  else:
                      msp = max([len(x) for x in opt_strs])
                      carr = [
                          opt_strs[i].rjust(
                              (msp + 1) if opt_sels[i] == default
                              else msp) + (u' ' if opt_sels[i] == default
                                           else u'  ') + opt_labs[i]
                          for i in range(len(options))
                      ]
                      sel_str = ''
                      beg_range = None
                      for oi, opt in enumerate(opt_sels):
                          if is_integer(opt):
                              if beg_range is None:
                                  sel_str += opt_nops[oi]
                                  beg_range = opt
                              else:
                                  if (oi + 1 >= len(opt_sels) or
                                          not is_integer(opt_sels[oi + 1])):
                                      if (oi > 0 and
                                              opt_sels[oi - 1] == beg_range):
                                          sel_str += '/' + opt_nops[oi]
                                      else:
                                          sel_str += '-' + opt_nops[oi]
                          else:
                              if oi != 0:
                                  sel_str += '/'
                              sel_str += opt_nops[oi]
                      carr += ['Enter selection (' + sel_str + '):']
                      choices = '\n' + '\n'.join(carr)
              elif kind == 'string':
                  choices = ''
              else:
                  raise ValueError('Unknown prompt kind.')
  
              if message and text in self._strings:
                  text = self.message(text, reps=reps, prt=False)
              textchoices = text + choices
              if translate:
                  textchoices = self.translate(textchoices)
              prompt_txt = (textchoices).split('\n')
              for txt in prompt_txt[:-1]:
                  ptxt = fill(txt, wl, replace_whitespace=False)
                  self.prt(ptxt, color=color)
  
              inp_text = fill(
                  prompt_txt[-1], wl, replace_whitespace=False) + " "
              if colorify:
                  inp_text = self.colorify(color + inp_text + "!e")
  
              if self._exit_on_prompt:
                  msg = self.message('prompt_encountered', prt=False)
                  raise RuntimeError(msg)
  
              user_input = input(inp_text)
  
              yes = ['y', 'yes', 'yep']
              nos = ['n', 'no', 'nope']
  
              uil = user_input.lower()
              if kind == 'bool':
                  if uil == '':
                      return default in yes
                  if uil in yes:
                      return True
                  if uil in nos:
                      return False
                  continue
              elif kind == 'select':
                  if (none_string is not None and default == 'n' and
                          uil in nos + ['']):
                      return None
                  if uil == '' and default in new_opts:
                      return new_opts[default]
                  if uil in opt_sels:
                      return new_opts[uil]
                  continue
              elif kind == 'option':
                  if (none_string is not None and default == 'n' and
                          uil in nos + ['']):
                      return None
                  if uil == '' and default in new_opts:
                      return int(default) if is_integer(default) else default
                  if is_integer(user_input) and user_input in opt_sels:
                      return int(user_input)
                  if uil in opt_sels:
                      return uil
                  continue
              elif kind == 'string':
                  if not allow_blank and user_input == '':
                      continue
                  return user_input
code_tokens: def prompt ( self , text , reps = [ ] , wrap_length = None , kind = 'bool' , default = None , none_string = 'None of the above.' , colorify = True , single = False , options = None , translate = True , message = True , color = '' , allow_blank = True ) : if wrap_length and is_integer ( wrap_length ) : wl = wrap_length else : wl = self . _wrap_length if kind in [ 'select' , 'option' , 'bool' ] : if kind == 'bool' : options = [ ( '' , 'y' ) , ( '' , 'n' ) ] if default is None : default = 'n' single = True none_string = None if none_string is not None : options . append ( ( none_string , 'n' ) ) if default is None and none_string is None : default = ( str ( options [ 0 ] [ - 1 ] ) if isinstance ( options [ 0 ] , tuple ) else '1' ) while True : if kind in [ 'select' , 'option' , 'bool' ] : opt_sels = [ ( str ( x [ - 1 ] ) if isinstance ( x , tuple ) else str ( xi + 1 ) ) for xi , x in enumerate ( options ) ] opt_strs = [ ( ( '[' + str ( x ) + '.]' ) if x == default else x + '.' ) for x in opt_sels ] opt_nops = [ ( ( '[' + str ( x ) + ']' ) if x == default else x ) for x in opt_sels ] opt_labs = [ ( opt [ 0 ] if isinstance ( opt , tuple ) else opt ) for opt in options ] opt_labs = [ x . decode ( 'utf-8' ) if not isinstance ( x , str ) else x for x in opt_labs ] new_opts = dict ( zip ( * ( opt_sels , opt_labs ) ) ) if single : choices = ' (' + '/' . join ( opt_nops ) + ')' else : msp = max ( [ len ( x ) for x in opt_strs ] ) carr = [ opt_strs [ i ] . rjust ( ( msp + 1 ) if opt_sels [ i ] == default else msp ) + ( u' ' if opt_sels [ i ] == default else u'  ' ) + opt_labs [ i ] for i in range ( len ( options ) ) ] sel_str = '' beg_range = None for oi , opt in enumerate ( opt_sels ) : if is_integer ( opt ) : if beg_range is None : sel_str += opt_nops [ oi ] beg_range = opt else : if ( oi + 1 >= len ( opt_sels ) or not is_integer ( opt_sels [ oi + 1 ] ) ) : if ( oi > 0 and opt_sels [ oi - 1 ] == beg_range ) : sel_str += '/' + opt_nops [ oi ] else : sel_str += '-' + opt_nops [ oi ] else : if oi != 0 : sel_str += '/' sel_str += opt_nops [ oi ] carr += [ 'Enter selection (' + sel_str + '):' ] choices = '\n' + '\n' . join ( carr ) elif kind == 'string' : choices = '' else : raise ValueError ( 'Unknown prompt kind.' ) if message and text in self . _strings : text = self . message ( text , reps = reps , prt = False ) textchoices = text + choices if translate : textchoices = self . translate ( textchoices ) prompt_txt = ( textchoices ) . split ( '\n' ) for txt in prompt_txt [ : - 1 ] : ptxt = fill ( txt , wl , replace_whitespace = False ) self . prt ( ptxt , color = color ) inp_text = fill ( prompt_txt [ - 1 ] , wl , replace_whitespace = False ) + " " if colorify : inp_text = self . colorify ( color + inp_text + "!e" ) if self . _exit_on_prompt : msg = self . message ( 'prompt_encountered' , prt = False ) raise RuntimeError ( msg ) user_input = input ( inp_text ) yes = [ 'y' , 'yes' , 'yep' ] nos = [ 'n' , 'no' , 'nope' ] uil = user_input . lower ( ) if kind == 'bool' : if uil == '' : return default in yes if uil in yes : return True if uil in nos : return False continue elif kind == 'select' : if ( none_string is not None and default == 'n' and uil in nos + [ '' ] ) : return None if uil == '' and default in new_opts : return new_opts [ default ] if uil in opt_sels : return new_opts [ uil ] continue elif kind == 'option' : if ( none_string is not None and default == 'n' and uil in nos + [ '' ] ) : return None if uil == '' and default in new_opts : return int ( default ) if is_integer ( default ) else default if is_integer ( user_input ) and user_input in opt_sels : return int ( user_input ) if uil in opt_sels : return uil continue elif kind == 'string' : if not allow_blank and user_input == '' : continue return user_input
short_docstring: Prompt the user for input and return a value based on response.
short_docstring_tokens: Prompt the user for input and return a value based on response .
comment: """Prompt the user for input and return a value based on response."""