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.

handle()[source]#

Handle the custom shortcut.

Return type:

Any

Directly return answer whether it’s applying it always.

Return type:

bool

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]) –

abstract handle()[source]#

Handle this choice. Must be implemented.

Return type:

Any

The current link will be handled by this choice.

Return type:

bool

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

result(value)[source]#

Return itself to raise the exception.

Parameters:

value (Any) –

Return type:

Any

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.

output_range(start, end)[source]#

DEPRECATED. Output a section from the text.

Parameters:
  • start (int) –

  • end (int) –

Return type:

None

result(value)[source]#

Add the delta to the context.

Parameters:

value (str) –

Return type:

Any

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.

output_range(start, end)[source]#

Show normal context with a highlighted center region.

Deprecated since version 6.2: use out instead.

Parameters:
  • start (int) –

  • end (int) –

Return type:

None

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

result(value)[source]#

Return a tuple with the prefix and value converted into an int.

Parameters:

value (str) –

Return type:

Any

test(value)[source]#

Return whether the value is an int and in the specified range.

Parameters:

value (str) –

Return type:

bool

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) –

handle()[source]#

Handle by either applying the new section or label.

Return type:

Any

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.

result(value)[source]#

Return a tuple with the prefix and selected value.

Parameters:

value (str) –

Return type:

Any

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) –

result(value)[source]#

Return a tuple with the prefix and selected values as a list.

Parameters:

value (str) –

Return type:

Any

test(value)[source]#

Return whether the values are int and in the specified range.

Parameters:

value (str) –

Return type:

bool

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 and handled are in such a relationship that when handled returns itself that test must return True for that value. So if test returns False handled may not return itself but it may return not None.

Also result only returns a sensible value when test 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 calls format for all options to combine the question for pywikibot.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.

test(value)[source]#

Return True whether this option applies.

Parameters:

value (str) –

Return type:

bool

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 for userinterface 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 deprecated output().

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 the userinterfaces system.

Return type:

None

result(value)[source]#

Just return None.

Parameters:

value (str) –

Return type:

Any

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) –

format(default=None)[source]#

Return a formatted string for that option.

Parameters:

default (Optional[str]) –

Return type:

str

result(value)[source]#

Return the lowercased shortcut.

Parameters:

value (str) –

Return type:

Any

test(value)[source]#

Return True whether this option applies.

Parameters:

value (str) –

Return type:

bool

class bot_choice.StaticChoice(option, shortcut, result)[source]#

Bases: Choice

A static choice which just returns the given value.

Create instance with replacer set to None.

Parameters:
  • option (str) –

  • shortcut (str) –

  • result (Any) –

handle()[source]#

Return the predefined value.

Return type:

Any

exception bot_choice.UnhandledAnswer[source]#

Bases: Exception

The given answer didn’t suffice.