jenkins-bot has submitted this change and it was merged.
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(-)
Approvals: Mpaa: Looks good to me, approved Dalba: Looks good to me, but someone else must approve jenkins-bot: Verified
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
pywikibot-commits@lists.wikimedia.org