jenkins-bot has submitted this change and it was merged. Change subject: [FEAT] Raise QuitKeyboardInterrupt on Ctrl+C and Quit/q ......................................................................
[FEAT] Raise QuitKeyboardInterrupt on Ctrl+C and Quit/q Whenever 'input()' is used all KeyboardInterrupts are changed into QuitKeyboardInterrupts. As 'inputChoice()' uses 'input()' as well this applies also to 'inputChoice()'. Also sorted the inputs and didn't rename 'pywikibot' to 'wikipedia'. Change-Id: Ib3ef5aef5d0f7ab7338a2ec9dfdf7592c4067923 --- M pywikibot/bot.py M pywikibot/userinterfaces/terminal_interface_base.py 2 files changed, 15 insertions(+), 16 deletions(-) Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/bot.py b/pywikibot/bot.py index 1011d85..2417922 100644 --- a/pywikibot/bot.py +++ b/pywikibot/bot.py @@ -909,10 +909,6 @@ pywikibot.output('\nUser quit %s bot run...' % self.__class__.__name__) except KeyboardInterrupt: - # TODO: If the ^C occurred during an input() - # it should be handled as a QuitKeyboardInterrupt - # as developers shouldnt need a backtrace to find - # where the input() code is. if config.verbose_output: raise else: diff --git a/pywikibot/userinterfaces/terminal_interface_base.py b/pywikibot/userinterfaces/terminal_interface_base.py index 411cc31..c1363e1 100755 --- a/pywikibot/userinterfaces/terminal_interface_base.py +++ b/pywikibot/userinterfaces/terminal_interface_base.py @@ -9,10 +9,10 @@ from . import transliteration import re import sys -import pywikibot as wikipedia +import logging +import pywikibot from pywikibot import config from pywikibot.bot import VERBOSE, INFO, STDOUT, INPUT, WARNING -import logging transliterator = transliteration.transliterator(config.console_encoding) @@ -185,11 +185,14 @@ sys.stdout.write('\07') # TODO: make sure this is logged as well self.output(question + ' ') - if password: - import getpass - text = getpass.getpass('') - else: - text = self._raw_input() + try: + if password: + import getpass + text = getpass.getpass('') + else: + text = self._raw_input() + except KeyboardInterrupt: + raise pywikibot.QuitKeyboardInterrupt() text = unicode(text, self.encoding) return text @@ -245,20 +248,20 @@ """Show the user a CAPTCHA image and return the answer.""" try: import webbrowser - wikipedia.output(u'Opening CAPTCHA in your web browser...') + pywikibot.output(u'Opening CAPTCHA in your web browser...') if webbrowser.open(url): - return wikipedia.input( + return pywikibot.input( u'What is the solution of the CAPTCHA that is shown in ' u'your web browser?') else: raise except: - wikipedia.output(u'Error in opening web browser: %s' + pywikibot.output(u'Error in opening web browser: %s' % sys.exc_info()[0]) - wikipedia.output( + pywikibot.output( u'Please copy this url to your web browser and open it:\n %s' % url) - return wikipedia.input( + return pywikibot.input( u'What is the solution of the CAPTCHA at this url ?') def argvu(self): -- To view, visit https://gerrit.wikimedia.org/r/155768 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib3ef5aef5d0f7ab7338a2ec9dfdf7592c4067923 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: Mpaa <mpaa.w...@gmail.com> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits