XZise has uploaded a new change for review. https://gerrit.wikimedia.org/r/195089
Change subject: [FIX] Win32 UI: Ignore fileno if not supported ...................................................................... [FIX] Win32 UI: Ignore fileno if not supported On some environments, like IDLE, getting the fileno of a std stream raises an UnsupportedOperation error. See also: https://mail.python.org/pipermail/python-list/2014-November/693894.html Change-Id: Idf934258e704176f788d68ecfa7edad9a3066f6d --- M pywikibot/userinterfaces/win32_unicode.py 1 file changed, 13 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/89/195089/1 diff --git a/pywikibot/userinterfaces/win32_unicode.py b/pywikibot/userinterfaces/win32_unicode.py index 3e77812..b1eca21 100755 --- a/pywikibot/userinterfaces/win32_unicode.py +++ b/pywikibot/userinterfaces/win32_unicode.py @@ -20,6 +20,7 @@ # ################################################ from __future__ import print_function +from io import UnsupportedOperation import sys stdin = sys.stdin stdout = sys.stdout @@ -86,16 +87,19 @@ return ((GetFileType(handle) & ~FILE_TYPE_REMOTE) != FILE_TYPE_CHAR or GetConsoleMode(handle, byref(DWORD())) == 0) - old_stdin_fileno = None - old_stdout_fileno = None - old_stderr_fileno = None + def old_fileno(std_name): + # some environments like IDLE don't support the fileno operation + # handle those like std streams which don't have fileno at all + std = getattr(sys, 'std{0}'.format(std_name)) + if hasattr(std, 'fileno'): + try: + return std.fileno() + except UnsupportedOperation: + pass - if hasattr(sys.stdin, 'fileno'): - old_stdin_fileno = sys.stdin.fileno() - if hasattr(sys.stdout, 'fileno'): - old_stdout_fileno = sys.stdout.fileno() - if hasattr(sys.stderr, 'fileno'): - old_stderr_fileno = sys.stderr.fileno() + old_stdin_fileno = old_fileno('in') + old_stdout_fileno = old_fileno('out') + old_stderr_fileno = old_fileno('err') STDIN_FILENO = 0 STDOUT_FILENO = 1 -- To view, visit https://gerrit.wikimedia.org/r/195089 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idf934258e704176f788d68ecfa7edad9a3066f6d Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits