def win_get_unicode_stream(stream, excepted_fileno, output_handle, encoding):
 old_fileno = getattr(stream, 'fileno', (lambda : None))()
 if (old_fileno == excepted_fileno):
  from ctypes import windll, WINFUNCTYPE
  from ctypes.wintypes import DWORD, HANDLE
  GetStdHandle = WINFUNCTYPE(HANDLE, DWORD)(('GetStdHandle', windll.kernel32))
  real_output_handle = GetStdHandle(DWORD(output_handle))
  if win_handle_is_a_console(real_output_handle):
   return WinUnicodeConsoleOutput(real_output_handle, old_fileno, stream.name, encoding)
 return WinUnicodeOutput(stream, old_fileno, encoding)

def win_get_unicode_stream ( stream , excepted_fileno , output_handle , encoding ) : old_fileno = getattr ( stream , 'fileno' , ( lambda : None ) ) ( ) if ( old_fileno == excepted_fileno ) : from ctypes import windll , WINFUNCTYPE from ctypes . wintypes import DWORD , HANDLE GetStdHandle = WINFUNCTYPE ( HANDLE , DWORD ) ( ( 'GetStdHandle' , windll . kernel32 ) ) real_output_handle = GetStdHandle ( DWORD ( output_handle ) ) if win_handle_is_a_console ( real_output_handle ) : return WinUnicodeConsoleOutput ( real_output_handle , old_fileno , stream . name , encoding ) return WinUnicodeOutput ( stream , old_fileno , encoding )
returns a unicode-compatible stream .