bot_choice
— UI Options and Choices#
Options and Choices for pywikibot.input_choice()
.
- class bot_choice.AlwaysChoice(replacer, option='always', shortcut='a')[source]#
Bases:
Choice
Add an option to always apply the default.
- Parameters:
replacer (Optional[pywikibot.bot.InteractiveReplace]) –
option (str) –
shortcut (str) –
- property answer: Any#
Get the actual default answer instructing the replacement.
- class bot_choice.Choice(option, shortcut, replacer)[source]#
Bases:
StandardOption
A simple choice consisting of an option, shortcut and handler.
- Parameters:
option (str) –
shortcut (str) –
replacer (Optional[pywikibot.bot.InteractiveReplace]) –
- property replacer: Optional[InteractiveReplace]#
The replacer.
- exception bot_choice.ChoiceException(option, shortcut, **kwargs)[source]#
Bases:
StandardOption
,Exception
A choice for input_choice which result in this exception.
- Parameters:
option (str) – option string
shortcut (str) – Shortcut of the option
kwargs (Any) –
- Return type:
None
- class bot_choice.ContextOption(option, shortcut, text, context, delta=100, start=0, end=0)[source]#
Bases:
OutputOption
,StandardOption
An option to show more and more context.
- Parameters:
option (str) –
shortcut (str) –
text (str) –
context (int) –
delta (int) –
start (int) –
end (int) –
- property out: str#
Output section of the text.
- class bot_choice.HighlightContextOption(option, shortcut, text, context, delta=100, start=0, end=0)[source]#
Bases:
ContextOption
Show the original region highlighted.
- Parameters:
option (str) –
shortcut (str) –
text (str) –
context (int) –
delta (int) –
start (int) –
end (int) –
- color = 'lightred'#
- property out: str#
Highlighted output section of the text.
- class bot_choice.IntegerOption(minimum=1, maximum=None, prefix='', **kwargs)[source]#
Bases:
Option
An option allowing a range of integers.
- Parameters:
minimum (int) –
maximum (Optional[int]) –
prefix (str) –
kwargs (Any) –
- format(default=None)[source]#
Return a formatted string showing the range.
- Parameters:
default (Optional[str]) –
- Return type:
str
- property maximum: Optional[int]#
Return the upper bound of the range of allowed values.
- property minimum: int#
Return the lower bound of the range of allowed values.
- parse(value)[source]#
Return integer from value with prefix removed.
- Parameters:
value (str) –
- Return type:
int
- class bot_choice.LinkChoice(option, shortcut, replacer, replace_section, replace_label)[source]#
Bases:
Choice
A choice returning a mix of the link new and current link.
- Parameters:
option (str) –
shortcut (str) –
replacer (Optional[pywikibot.bot.InteractiveReplace]) –
replace_section (bool) –
replace_label (bool) –
- class bot_choice.ListOption(sequence, prefix='', **kwargs)[source]#
Bases:
IntegerOption
An option to select something from a list.
- Parameters:
sequence (Sequence[str]) –
prefix (str) –
kwargs (Any) –
- format(default=None)[source]#
Return a string showing the range.
- Parameters:
default (Optional[str]) –
- Return type:
str
- property maximum: int#
Return the maximum value.
- class bot_choice.MultipleChoiceList(sequence, prefix='', **kwargs)[source]#
Bases:
ListOption
An option to select multiple items from a list.
- Parameters:
sequence (Sequence[str]) –
prefix (str) –
kwargs (Any) –
- class bot_choice.NestedOption(option, shortcut, description, options)[source]#
Bases:
OutputOption
,StandardOption
An option containing other options.
It will return True in test if this option applies but False if a sub option applies while handle returns the sub option.
- Parameters:
option (str) –
shortcut (str) –
description (str) –
options (Iterable[Option]) –
- format(default=None)[source]#
Return a formatted string for that option.
- Parameters:
default (Optional[str]) –
- Return type:
str
- handled(value)[source]#
Return itself if it applies or the applying sub option.
- Parameters:
value (str) –
- Return type:
Optional[Option]
- property out: str#
Output of suboptions.
- class bot_choice.Option(stop=True)[source]#
Bases:
ABC
A basic option for input_choice.
The following methods need to be implemented:
format(default=None)
result(value)
test(value)
The methods
test
andhandled
are in such a relationship that whenhandled
returns itself thattest
must return True for that value. So iftest
returns Falsehandled
may not return itself but it may return not None.Also
result
only returns a sensible value whentest
returns True for the same value.- Parameters:
stop (bool) –
- format(default=None)[source]#
Return a formatted string for that option.
- Parameters:
default (Optional[str]) –
- Return type:
str
- static formatted(text, options, default=None)[source]#
Create a text with the options formatted into it.
This static method is used by
pywikibot.input_choice()
. It callsformat
for all options to combine the question forpywikibot.input()
.- Parameters:
text (str) – Text into which options are to be formatted
options (Iterable[Option]) – Option instances to be formatted
default (Optional[str]) – filler for any option’s ‘default’ placeholder
- Returns:
Text with the options formatted into it
- Return type:
str
- handled(value)[source]#
Return the Option object that applies to the given value.
If this Option object doesn’t know which applies it returns None.
- Parameters:
value (str) –
- Return type:
Optional[Option]
- abstract result(value)[source]#
Return the actual value which is associated by the given one.
New in version 6.2: result() is an abstract method and must be defined in subclasses
- Parameters:
value (str) –
- Return type:
Any
- property stop: bool#
Return whether this option stops asking.
- class bot_choice.OutputOption(stop=True)[source]#
Bases:
Option
An option that never stops and can output on each question.
pywikibot.input_choice()
uses before_question attribute to decide whether to output before or after the question.Note
OutputOption must have an
out
property which returns a string foruserinterface output()
method.- Parameters:
stop (bool) –
- before_question: bool = False#
Place output before or after the question
- property out: str#
String to be used when selected before or after the question.
Note
This method is used by
ui.input_choice
instead of deprecatedoutput()
.New in version 6.2.
- output()[source]#
Output string.
Deprecated since version 6.5: This method was replaced by
out
property and is no no longer used by theuserinterfaces
system.- Return type:
None
- property stop: bool#
Never stop asking.
- class bot_choice.OutputProxyOption(option, shortcut, output, **kwargs)[source]#
Bases:
OutputOption
,StandardOption
An option which calls out property of the given output class.
Create a new option for the given sequence.
- Parameters:
option (str) –
shortcut (str) –
output (OutputOption) –
kwargs (Any) –
- property out: str#
Return the contents.
- exception bot_choice.QuitKeyboardInterrupt[source]#
Bases:
ChoiceException
,KeyboardInterrupt
The user has cancelled processing at a prompt.
Constructor using the ‘quit’ (‘q’) in input_choice.
- Return type:
None
- class bot_choice.ShowingListOption(sequence, prefix='', pre=None, post=None, **kwargs)[source]#
Bases:
ListOption
,OutputOption
An option to show a list and select an item.
New in version 3.0.
- Parameters:
pre (Optional[str]) – Additional comment printed before the list.
post (Optional[str]) – Additional comment printed after the list.
sequence (Sequence[str]) –
prefix (str) –
kwargs (Any) –
- before_question: bool = True#
Place output before or after the question
- property out: str#
Output text of the enumerated list.
- property stop: bool#
Return whether this option stops asking.
- class bot_choice.ShowingMultipleChoiceList(sequence, prefix='', pre=None, post=None, **kwargs)[source]#
Bases:
ShowingListOption
,MultipleChoiceList
An option to show a list and select multiple items.
- Parameters:
pre (Optional[str]) – Additional comment printed before the list.
post (Optional[str]) – Additional comment printed after the list.
sequence (Sequence[str]) –
prefix (str) –
kwargs (Any) –
- class bot_choice.StandardOption(option, shortcut, **kwargs)[source]#
Bases:
Option
An option with a description and shortcut and returning the shortcut.
- Parameters:
option (str) – option string
shortcut (str) – Shortcut of the option
kwargs (Any) –