Skip to content

Commit

Permalink
print: handle missing fileno()
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Aug 20, 2016
1 parent 6df3160 commit 1f4a8d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions senf/_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ def _print_default(objects, sep, end, file, flush):
def _print_windows(objects, sep, end, file, flush):
"""The windows implementation of print_()"""

fileno = file.fileno()
h = winapi.INVALID_HANDLE_VALUE
if fileno == 1:
h = winapi.GetStdHandle(winapi.STD_OUTPUT_HANDLE)
elif fileno == 2:
h = winapi.GetStdHandle(winapi.STD_ERROR_HANDLE)

try:
fileno = file.fileno()
except (IOError, AttributeError):
pass
else:
if fileno == 1:
h = winapi.GetStdHandle(winapi.STD_OUTPUT_HANDLE)
elif fileno == 2:
h = winapi.GetStdHandle(winapi.STD_ERROR_HANDLE)

if h == winapi.INVALID_HANDLE_VALUE:
return _print_default(objects, sep, end, file, flush)
Expand Down

0 comments on commit 1f4a8d2

Please sign in to comment.