Coverage for certbot/display/util.py : 99%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Certbot display."""
# Display exit codes """Display exit code indicating user acceptance."""
"""Display exit code for a user canceling the display."""
"""Display exit code when for when the user requests more help. (UNUSED)"""
"""Display exit code when the user hits Escape (UNUSED)"""
# Display constants """Display boundary (alternates spaces, so when copy-pasted, markdown doesn't interpret it as a heading)"""
"""Format lines nicely to 80 chars.
:param str msg: Original message
:returns: Formatted message respecting newlines in message :rtype: str
"""
line, 80, break_long_words=False, break_on_hyphens=False))
"""Get user input with a timeout.
Behaves the same as six.moves.input, however, an error is raised if a user doesn't answer after timeout seconds. The default timeout value was chosen to place it just under 12 hours for users following our advice and running Certbot twice a day.
:param str prompt: prompt to provide for input :param float timeout: maximum number of seconds to wait for input
:returns: user response :rtype: str
:raises errors.Error if no answer is given before the timeout
""" # use of sys.stdin and sys.stdout to mimic six.moves.input based on # https://github.com/python/cpython/blob/baf7bb30a02aabde260143136bdf5b3738a1d409/Lib/getpass.py#L129
"""File-based display.""" # pylint: disable=too-many-arguments # see https://github.com/certbot/certbot/issues/3915
wrap=True, force_interactive=False): """Displays a notification and waits for user acceptance.
:param str message: Message to display :param bool pause: Whether or not the program should pause for the user's confirmation :param bool wrap: Whether or not the application should wrap text :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
""" "{line}{frame}{line}{msg}{line}{frame}{line}".format( line=os.linesep, frame=SIDE_FRAME, msg=message)) else:
help_label=None, default=None, cli_flag=None, force_interactive=False, **unused_kwargs): # pylint: disable=unused-argument """Display a menu.
.. todo:: This doesn't enable the help label/button (I wasn't sold on any interface I came up with for this). It would be a nice feature
:param str message: title of menu :param choices: Menu lines, len must be > 0 :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated) :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
:returns: tuple of (`code`, `index`) where `code` - str display exit code `index` - int index of the user's selection
:rtype: tuple
"""
cli_flag=None, force_interactive=False, **unused_kwargs): """Accept input from the user.
:param str message: message to display to the user :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
:returns: tuple of (`code`, `input`) where `code` - str display exit code `input` - str of the user's input :rtype: tuple
"""
# Trailing space must be added outside of _wrap_lines to be preserved
else:
cli_flag=None, force_interactive=False, **unused_kwargs): """Query the user with a yes/no question.
Yes and No label must begin with different letters, and must contain at least one letter each.
:param str message: question for the user :param str yes_label: Label of the "Yes" parameter :param str no_label: Label of the "No" parameter :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
:returns: True for "Yes", False for "No" :rtype: bool
"""
os.linesep, frame=SIDE_FRAME + os.linesep, msg=message))
yes=_parens_around_char(yes_label), no=_parens_around_char(no_label)))
# Couldn't get pylint indentation right with elif # elif doesn't matter in this situation ans.startswith(yes_label[0].upper())): ans.startswith(no_label[0].upper())):
cli_flag=None, force_interactive=False, **unused_kwargs): # pylint: disable=unused-argument """Display a checklist.
:param str message: Message to display to user :param list tags: `str` tags to select, len(tags) > 0 :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
:returns: tuple of (`code`, `tags`) where `code` - str display exit code `tags` - list of selected tags :rtype: tuple
"""
"by commas and/or spaces, or leave input " "blank to select all options shown", force_interactive=True)
else: "** Error - Invalid selection **%s" % os.linesep) else:
"""Should we return the default instead of prompting the user?
:param str prompt: prompt for the user :param default: default answer to prompt :param str cli_flag: command line option for setting an answer to this question :param bool force_interactive: if interactivity is forced by the IDisplay call
:returns: True if we should return the default without prompting :rtype: bool
""" # assert_valid_call(prompt, default, cli_flag, force_interactive) "\nYou can provide an answer on the " "command line with the {0} flag.".format(cli_flag)) else: "Falling back to default %s for the prompt:\n%s", default, prompt)
"""Can we safely interact with the user?
:param bool force_interactive: if interactivity is forced by the IDisplay call
:returns: True if the display can interact with the user :rtype: bool
""" sys.stdin.isatty() and self.outfile.isatty()): "Skipped user interaction because Certbot doesn't appear to " "be running in a terminal. You should probably include " "--non-interactive or %s on the command line.", constants.FORCE_INTERACTIVE_FLAG)
force_interactive=False, **unused_kwargs): """Display a directory selection screen.
:param str message: prompt to give the user :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI :param bool force_interactive: True if it's safe to prompt the user because it won't cause any workflow regressions
:returns: tuple of the form (`code`, `string`) where `code` - display exit code `string` - input entered by the user
"""
# pylint: disable=no-self-use """Validate input and transform indices to appropriate tags.
:param list indices: input :param list tags: Original tags of the checklist
:returns: valid tags the user selected :rtype: :class:`list` of :class:`str`
""" # They should all be of type int
# Remove duplicates
# Check all input is within range # Transform indices to appropriate tags
"""Print a menu on the screen.
:param str message: title of menu :param choices: Menu lines :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated)
""" # Can take either tuples or single items in choices list
# Write out the message to the user "{new}{msg}{new}".format(new=os.linesep, msg=message))
# Write out the menu choices
# Keep this outside of the textwrap
"""Get a numerical selection.
:param int max: The maximum entry (len of choices), must be positive
:returns: tuple of the form (`code`, `selection`) where `code` - str display exit code ('ok' or cancel') `selection` - int user's selection :rtype: tuple
""" "[1-{max_}] then [enter] (press 'c' to " "cancel): ".format(max_=max_)) else: "(press 'c' to cancel): ")
"{0}** Invalid input **{0}".format(os.linesep))
"""Verify that provided arguments is a valid IDisplay call.
:param str prompt: prompt for the user :param default: default answer to prompt :param str cli_flag: command line option for setting an answer to this question :param bool force_interactive: if interactivity is forced by the IDisplay call
""" "this prompt with the {0} flag".format(cli_flag))
"""An iDisplay implementation that never asks for interactive user input"""
"Error out in case of an attempt to interact in noninteractive mode" msg += "\n\n(You can set this with the {0} flag)".format(cli_flag)
# pylint: disable=unused-argument """Displays a notification without waiting for user acceptance.
:param str message: Message to display to stdout :param bool pause: The NoninteractiveDisplay waits for no keyboard :param bool wrap: Whether or not the application should wrap text
""" "{line}{frame}{line}{msg}{line}{frame}{line}".format( line=os.linesep, frame=SIDE_FRAME, msg=message))
help_label=None, default=None, cli_flag=None, **unused_kwargs): # pylint: disable=unused-argument,too-many-arguments """Avoid displaying a menu.
:param str message: title of menu :param choices: Menu lines, len must be > 0 :type choices: list of tuples (tag, item) or list of descriptions (tags will be enumerated) :param int default: the default choice :param dict kwargs: absorbs various irrelevant labelling arguments
:returns: tuple of (`code`, `index`) where `code` - str display exit code `index` - int index of the user's selection :rtype: tuple :raises errors.MissingCommandlineFlag: if there was no default
"""
"""Accept input from the user.
:param str message: message to display to the user
:returns: tuple of (`code`, `input`) where `code` - str display exit code `input` - str of the user's input :rtype: tuple :raises errors.MissingCommandlineFlag: if there was no default
""" else:
default=None, cli_flag=None, **unused_kwargs): # pylint: disable=unused-argument """Decide Yes or No, without asking anybody
:param str message: question for the user :param dict kwargs: absorbs yes_label, no_label
:raises errors.MissingCommandlineFlag: if there was no default :returns: True for "Yes", False for "No" :rtype: bool
""" else:
cli_flag=None, **unused_kwargs): """Display a checklist.
:param str message: Message to display to user :param list tags: `str` tags to select, len(tags) > 0 :param dict kwargs: absorbs default_status arg
:returns: tuple of (`code`, `tags`) where `code` - str display exit code `tags` - list of selected tags :rtype: tuple
""" else:
cli_flag=None, **unused_kwargs): """Simulate prompting the user for a directory.
This function returns default if it is not ``None``, otherwise, an exception is raised explaining the problem. If cli_flag is not ``None``, the error message will include the flag that can be used to set this value with the CLI.
:param str message: prompt to give the user :param default: default value to return (if one exists) :param str cli_flag: option used to set this value with the CLI
:returns: tuple of the form (`code`, `string`) where `code` - int display exit code `string` - input entered by the user
"""
"""Separate a comma or space separated list.
:param str input_: input from the user
:returns: strings :rtype: list
""" # Each string is naturally unicode, this causes problems with M2Crypto SANs # TODO: check if above is still true when M2Crypto is gone ^
"""Place parens around first character of label.
:param str label: Must contain at least one character
""" |