PyTan prompting module.
pytan3.utils.prompts.
ColorWrap
(mode='')[source]¶Bases: object
Wrapper for colorama.
MODE_MAP
= {'BACK': <colorama.ansi.AnsiBack object at 0x7ff2fe424630>, 'FORE': <colorama.ansi.AnsiFore object at 0x7ff2fe4245c0>, 'STYLE': <colorama.ansi.AnsiStyle object at 0x7ff2fe424668>}¶dict
– Map of modes this wrapper can expose.
pytan3.utils.prompts.
Promptness
(input_stream=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>, output_stream=<colorama.ansitowin32.StreamWrapper object>, lvl='info')[source]¶Bases: object
Prompt utility class.
OVERRIDES
= None¶dict
– Default overrides for Promptness.ask_dict()
.
TMPLS
= {'env_value': '\n{{f.green}}OS Environment Variable {env!r} has value {env_value}, {{f.green}}{action} override default {default}{{s.reset}}.', 'option': '\n {{f.BLUE}}{opt}{{s.reset}}', 'options': '\nOptions:{options}\n', 'prompt': '\n{{f.cyan}}{text}{{s.reset}} [default: {default}]: ', 'secure_value': '{{s.reset}}{{f.red}}..HIDDEN..{{s.reset}}', 'value': "{{s.reset}}{{f.green}}'{value}'{{s.reset}}", 'warn_bool_invalid': '\n-- {{f.red}}Value must be one of {yes_values!r} or {no_values!r}{{s.reset}}', 'warn_int_invalid': '\n-- {{f.red}}Value must be a valid number{{s.reset}}', 'warn_nodefault': '\n-- {{f.red}}No default defined, value required!{{s.reset}}', 'warn_notty': '\n\n{{f.red}}No TTY on stream {stream}, using default {default!r} for {text!r}{{s.reset}}\n', 'warn_option_invalid': '\n-- {{f.red}}Value must be one of: {options!r}{{s.reset}}\n', 'warn_text_invalid': '\n-- {{f.red}}Value did not match {validate!r}{{s.reset}}'}¶dict
– String templates used throughout.
__init__
(input_stream=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>, output_stream=<colorama.ansitowin32.StreamWrapper object>, lvl='info')[source]¶Constructor.
Parameters: |
|
---|
log
= None¶logging.Logger
– Log for this object.
spew
(text, **kwargs)[source]¶Print output to stream.
Parameters: |
|
---|
get_prompter
(secure=False)[source]¶Get a prompt function.
Parameters: | secure (bool , optional) – Return getpass.getpass instead of input. Defaults to: False. |
---|---|
Returns: | object |
prompt
(text, default=None, **kwargs)[source]¶Prompt for a value.
Parameters: | |
---|---|
Raises: |
|
Returns: |
ask_choice
(text, choices, default=None, attempts=5, **kwargs)[source]¶Prompt user to select from a list of choices.
Parameters: |
|
---|---|
Raises: |
|
Returns: |
ask_bool
(text, default=None, attempts=5, **kwargs)[source]¶Prompt user to provide yes or no.
Parameters: | |
---|---|
Raises: |
|
Returns: |
ask_int
(text, default=None, attempts=5, **kwargs)[source]¶Prompt user to provide yes or no.
Parameters: | |
---|---|
Raises: |
|
Returns: |
ask_str
(text, default=None, attempts=5, **kwargs)[source]¶Prompt user to provide yes or no.
Parameters: | |
---|---|
Raises: |
|
Returns: |
ask_dict
(asks, overrides=None)[source]¶Prompt for input from a list of dict.
Parameters: |
---|
Notes
Keys for ask dict in asks:
ask_choice()
:ask_str()
:Returns: | dict |
---|
pytan3.utils.prompts.
PromptError
(text, attempts)[source]¶Bases: Exception
Parent exception for any errors when prompting.
Promptness.ask_dict()
msg
= '{text}'¶pytan3.utils.prompts.
InvalidValueError
(text, attempts)[source]¶Bases: pytan3.utils.prompts.PromptError
Thrown when a user provides an invalid value.
msg
= 'Invalid value supplied for prompt {text!r} after {attempts} attempts'¶pytan3.utils.prompts.
EmptyValueError
(text, attempts)[source]¶Bases: pytan3.utils.prompts.PromptError
Thrown when no default defined and user provides no value.
msg
= 'No value supplied for prompt {text!r} after {attempts} attempts'¶pytan3.utils.prompts.
NoTtyError
(stream, text)[source]¶Bases: pytan3.utils.prompts.PromptError
Thrown when a TTY is not attached to a console.
Promptness.prompt()
pytan3.utils.prompts.
stream_name
(stream)[source]¶Get the name of a stream.
Parameters: | stream (io.IOBase ) – Stream to get name of. |
---|---|
Returns: | str |
pytan3.utils.prompts.
isatty
(stream)[source]¶Check if a stream is attached to a console.
Parameters: | stream (io.IOBase ) – Stream to check. |
---|---|
Returns: | bool |
pytan3.utils.prompts.
promptness
= pytan3.utils.prompts.Promptness(input='<stdin>', output='<stderr>')¶Promptness
– Pre-established object for easy usage.