pywikibot.userinterfaces package

User interfaces.


pywikibot.userinterfaces.cgi_interface module

CGI user interface.

class pywikibot.userinterfaces.cgi_interface.UI[source]

Bases: object

CGI user interface.

__module__ = 'pywikibot.userinterfaces.cgi_interface'
input(question, colors=None)[source]

Output question to CGI stream.

output(text, colors=None, newline=True, toStdout=False)[source]

Output text to CGI stream if toStdout is True.

pywikibot.userinterfaces.gui module

pywikibot.userinterfaces.terminal_interface module

Platform independent terminal interface module.

It imports the appropriate operating system specific implementation.


alias of pywikibot.userinterfaces.terminal_interface_unix.UnixUI

pywikibot.userinterfaces.terminal_interface_base module

Base for terminal user interfaces.

class pywikibot.userinterfaces.terminal_interface_base.MaxLevelFilter(level=None)[source]

Bases: logging.Filter

Filter that only passes records at or below a specific level.

(setting handler level only passes records at or above a specified level, so this provides the opposite functionality)



__module__ = 'pywikibot.userinterfaces.terminal_interface_base'

Return true if the level is below or equal to the set level.

class pywikibot.userinterfaces.terminal_interface_base.TerminalFormatter(fmt=None, datefmt=None, style='%')[source]

Bases: logging.Formatter

Terminal logging formatter.

__module__ = 'pywikibot.userinterfaces.terminal_interface_base'
class pywikibot.userinterfaces.terminal_interface_base.TerminalHandler(UI, strm=None)[source]

Bases: logging.Handler

A handler class that writes logging records to a terminal.

This class does not close the stream, as sys.stdout or sys.stderr may be (and usually will be) used.

Slightly modified version of the StreamHandler class that ships with logging module, plus code for colorization of output.

__init__(UI, strm=None)[source]

Initialize the handler.

If strm is not specified, sys.stderr is used.

__module__ = 'pywikibot.userinterfaces.terminal_interface_base'

Emit the record formatted to the output and return it.


Flush the stream.

sharedlock = <_thread.RLock owner=0 count=0>
class pywikibot.userinterfaces.terminal_interface_base.UI[source]

Bases: object

Base for terminal user interfaces.


Initialize the UI.

This caches the std-streams locally so any attempts to monkey-patch the streams later will not work.

__module__ = 'pywikibot.userinterfaces.terminal_interface_base'

Return the decoded arguments from argv.

classmethod divide_color(color)[source]

Split color label in a tuple.

Received color is a string like ‘fg_color;bg_color’ or ‘fg_color’. Returned values are (fg_color, bg_color) or (fg_color, None).

editText(text, jumpIndex=None, highlight=None)[source]

Return the text as edited by the user.

Uses a Tkinter edit box because we don’t have a console editor

  • text (str) – the text to be edited
  • jumpIndex (int) – position at which to put the caret
  • highlight (str) – each occurrence of this substring will be highlighted

the modified text, or None if the user didn’t save the text file in his text editor

Return type:

str or None

encounter_color(color, target_stream)[source]

Handle the next color encountered.

init_handlers(root_logger, default_stream='stderr')[source]

Initialize the handlers for user output.

This method initializes handler(s) for output levels VERBOSE (if enabled by config.verbose_output), INFO, STDOUT, WARNING, ERROR, and CRITICAL. STDOUT writes its output to sys.stdout; all the others write theirs to sys.stderr.

input(question, password=False, default='', force=False)[source]

Ask the user a question and return the answer.

Works like raw_input(), but returns a unicode string instead of ASCII.

Unlike raw_input, this function automatically adds a colon and space after the question if they are not already present. Also recognises a trailing question mark.

  • question (basestring) – The question, without trailing whitespace.
  • password (bool) – if True, hides the user’s input (for password entry).
  • default (basestring) – The default answer if none was entered. None to require an answer.
  • force (bool) – Automatically use the default
Return type:


inputChoice(question, options, hotkeys, default=None)[source]

Ask the user a question with a predefined list of acceptable answers.

DEPRECATED: Use input_choice instead!

Directly calls input_choice with the options and hotkeys zipped into a tuple list. It always returns the hotkeys and throws no QuitKeyboardInterrupt if quit was selected.

input_choice(question, options, default=None, return_shortcut=True, automatic_quit=True, force=False)[source]

Ask the user and returns a value from the options.

Depending on the options setting return_shortcut to False may not be sensible when the option supports multiple values as it’ll return an ambiguous index.

  • question (basestring) – The question, without trailing whitespace.
  • options (iterable containing sequences of length 2 or iterable containing Option instances or ChoiceException as well. Singletons of Option and its subclasses are also accepted.) – Iterable of all available options. Each entry contains the full length answer and a shortcut of only one character. Alternatively they may be Option (or subclass) instances or ChoiceException instances which have a full option and shortcut and will be raised if selected.
  • default (basestring) – The default answer if no was entered. None to require an answer.
  • return_shortcut (bool) – Whether the shortcut or the index in the option should be returned.
  • automatic_quit (bool) – Adds the option ‘Quit’ (‘q’) if True and throws a QuitKeyboardInterrupt if selected.
  • force (bool) – Automatically use the default

If return_shortcut the shortcut of options or the value of default (if it’s not None). Otherwise the index of the answer in options. If default is not a shortcut, it’ll return -1.

Return type:

int (if not return_shortcut), lowercased basestring (otherwise)

input_list_choice(question, answers, default=None, force=False)[source]

Ask the user to select one entry from a list of entries.

output(text, toStdout=False, targetStream=None)[source]

Output text to a stream.

If a character can’t be displayed in the encoding used by the user’s terminal, it will be replaced with a question mark or by a transliteration.

split_col_pat = re.compile('(\\w+);?(\\w+)?')

Return whether the target stream does support colors.

pywikibot.userinterfaces.terminal_interface_unix module

User interface for unix terminals.

class pywikibot.userinterfaces.terminal_interface_unix.UnixUI[source]

Bases: pywikibot.userinterfaces.terminal_interface_base.UI

User interface for unix terminals.

__module__ = 'pywikibot.userinterfaces.terminal_interface_unix'
encounter_color(color, target_stream)[source]

Write the unix color directly to the stream.


Obtain background color from foreground color.


Return that the target stream supports colors.

pywikibot.userinterfaces.terminal_interface_win32 module

User interface for Win32 terminals.

class pywikibot.userinterfaces.terminal_interface_win32.Win32UI[source]

Bases: pywikibot.userinterfaces.terminal_interface_base.UI

User interface for Win32 terminals using ctypes.



__module__ = 'pywikibot.userinterfaces.terminal_interface_win32'
encounter_color(color, target_stream)[source]

Set the new color.


Return whether the target stream supports actually color.

pywikibot.userinterfaces.transliteration module

Module to transliterate text.

class pywikibot.userinterfaces.transliteration.transliterator(encoding)[source]

Bases: object

Class to transliterating text.


Initialize the transliteration mapping.

Parameters:encoding (str) – the encoding available. Any transliterated character which can’t be mapped, will be removed from the mapping.
__module__ = 'pywikibot.userinterfaces.transliteration'
transliterate(char, default='?', prev='-', next='-')[source]

Transliterate the character.

  • char (str) – The character to transliterate.
  • default (str) – The character used when there is no transliteration.
  • prev (str) – The previous character
  • next (str) – The next character

The transliterated character which may be an empty string

Return type:


pywikibot.userinterfaces.win32_unicode module

Stdout, stderr and argv support for unicode.

class pywikibot.userinterfaces.win32_unicode.UnicodeInput(hConsole, name, bufsize=1024)[source]

Bases: io.IOBase

Unicode terminal input class.

__abstractmethods__ = frozenset()
__init__(hConsole, name, bufsize=1024)[source]

Initialize the input stream.

__module__ = 'pywikibot.userinterfaces.win32_unicode'

Read one line from the input.

class pywikibot.userinterfaces.win32_unicode.UnicodeOutput(hConsole, stream, fileno, name)[source]

Bases: io.IOBase

Unicode terminal output class.

__abstractmethods__ = frozenset()
__init__(hConsole, stream, fileno, name)[source]

Initialize the output stream.

__module__ = 'pywikibot.userinterfaces.win32_unicode'

Return the fileno.


Flush the stream.


Write the text to the output.


Write a list of lines by using write.


Force the console to use a TrueType font (Vista+).


Get Unicode console objects.

Returns:stdin, stdout, stderr, argv
Return type:tuple

Return the fileno or None if that doesn’t work.


Register codecs cp65001 as utf-8.