updated code to handle printing on windows
[harrypotter-wikipedia-cdsw] / win_unicode_console / __init__.py
1
2 from win_unicode_console import streams, console, readline_hook
3
4 streams_ = streams
5
6
7 def enable(*, 
8         streams=["stdin", "stdout", "stderr"], 
9         transcode=None, 
10         use_readline_hook=True, 
11         use_pyreadline=True,
12         use_repl=False):
13         
14         if transcode is None:
15                 if use_readline_hook and use_pyreadline and readline_hook.pyreadline:
16                         transcode = True
17                                 # pyreadline assumes that encoding of all sys.stdio objects is the same
18                         
19                 elif use_repl:
20                         transcode = False
21                         
22                 else:
23                         transcode = True
24                                 # actually Python REPL assumes that sys.stdin.encoding == sys.stdout.encoding and cannot handle UTF-16 on both input and output
25         
26         streams_.enable(streams, transcode=transcode)
27         
28         if use_readline_hook:
29                 readline_hook.enable(use_pyreadline=use_pyreadline)
30         
31         if use_repl:
32                 console.enable()
33
34 def disable():
35         if console.running_console is not None:
36                 console.disable()
37         
38         readline_hook.disable()
39         streams.disable()

Benjamin Mako Hill || Want to submit a patch?