Show More
@@ -32,7 +32,7 b' import sys' | |||
|
32 | 32 | from IPython.utils import PyColorize |
|
33 | 33 | from IPython.core import ipapi |
|
34 | 34 | from IPython.utils import coloransi |
|
35 |
|
|
|
35 | import IPython.utils.io | |
|
36 | 36 | from IPython.core.excolors import exception_colors |
|
37 | 37 | |
|
38 | 38 | # See if we can use pydb. |
@@ -171,7 +171,7 b' class Pdb(OldPdb):' | |||
|
171 | 171 | |
|
172 | 172 | # Parent constructor: |
|
173 | 173 | if has_pydb and completekey is None: |
|
174 | OldPdb.__init__(self,stdin=stdin,stdout=Term.cout) | |
|
174 | OldPdb.__init__(self,stdin=stdin,stdout=IPython.utils.io.Term.cout) | |
|
175 | 175 | else: |
|
176 | 176 | OldPdb.__init__(self,completekey,stdin,stdout) |
|
177 | 177 | |
@@ -279,7 +279,7 b' class Pdb(OldPdb):' | |||
|
279 | 279 | def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ', |
|
280 | 280 | context = 3): |
|
281 | 281 | #frame, lineno = frame_lineno |
|
282 | print >>Term.cout, self.format_stack_entry(frame_lineno, '', context) | |
|
282 | print >>IPython.utils.io.Term.cout, self.format_stack_entry(frame_lineno, '', context) | |
|
283 | 283 | |
|
284 | 284 | # vds: >> |
|
285 | 285 | frame, lineno = frame_lineno |
@@ -419,7 +419,7 b' class Pdb(OldPdb):' | |||
|
419 | 419 | src.append(line) |
|
420 | 420 | self.lineno = lineno |
|
421 | 421 | |
|
422 | print >>Term.cout, ''.join(src) | |
|
422 | print >>IPython.utils.io.Term.cout, ''.join(src) | |
|
423 | 423 | |
|
424 | 424 | except KeyboardInterrupt: |
|
425 | 425 | pass |
@@ -5,7 +5,8 b'' | |||
|
5 | 5 | import fnmatch |
|
6 | 6 | import os |
|
7 | 7 | |
|
8 | from IPython.utils.io import Term, ask_yes_no | |
|
8 | import IPython.utils.io | |
|
9 | from IPython.utils.io import ask_yes_no | |
|
9 | 10 | from IPython.utils.warn import warn |
|
10 | 11 | from IPython.core import ipapi |
|
11 | 12 | |
@@ -62,7 +63,7 b" def magic_history(self, parameter_s = ''):" | |||
|
62 | 63 | try: |
|
63 | 64 | outfname = opts['f'] |
|
64 | 65 | except KeyError: |
|
65 | outfile = Term.cout # default | |
|
66 | outfile = IPython.utils.io.Term.cout # default | |
|
66 | 67 | # We don't want to close stdout at the end! |
|
67 | 68 | close_at_end = False |
|
68 | 69 | else: |
@@ -101,7 +102,7 b" def magic_history(self, parameter_s = ''):" | |||
|
101 | 102 | init, final = map(int, args) |
|
102 | 103 | else: |
|
103 | 104 | warn('%hist takes 0, 1 or 2 arguments separated by spaces.') |
|
104 | print >> Term.cout, self.magic_hist.__doc__ | |
|
105 | print >> IPython.utils.io.Term.cout, self.magic_hist.__doc__ | |
|
105 | 106 | return |
|
106 | 107 | |
|
107 | 108 | width = len(str(final)) |
@@ -46,7 +46,7 b' import sys' | |||
|
46 | 46 | |
|
47 | 47 | from pprint import PrettyPrinter |
|
48 | 48 | |
|
49 |
|
|
|
49 | import IPython.utils.io | |
|
50 | 50 | from IPython.utils.process import shell |
|
51 | 51 | |
|
52 | 52 | from IPython.core.error import TryNext |
@@ -175,13 +175,13 b' def result_display(self,arg):' | |||
|
175 | 175 | # So that multi-line strings line up with the left column of |
|
176 | 176 | # the screen, instead of having the output prompt mess up |
|
177 | 177 | # their first line. |
|
178 | Term.cout.write('\n') | |
|
179 | print >>Term.cout, out | |
|
178 | IPython.utils.io.Term.cout.write('\n') | |
|
179 | print >>IPython.utils.io.Term.cout, out | |
|
180 | 180 | else: |
|
181 | 181 | # By default, the interactive prompt uses repr() to display results, |
|
182 | 182 | # so we should honor this. Users who'd rather use a different |
|
183 | 183 | # mechanism can easily override this hook. |
|
184 | print >>Term.cout, repr(arg) | |
|
184 | print >>IPython.utils.io.Term.cout, repr(arg) | |
|
185 | 185 | # the default display hook doesn't manipulate the value to put in history |
|
186 | 186 | return None |
|
187 | 187 |
@@ -53,7 +53,8 b' from IPython.utils import PyColorize' | |||
|
53 | 53 | from IPython.utils import pickleshare |
|
54 | 54 | from IPython.utils.doctestreload import doctest_reload |
|
55 | 55 | from IPython.utils.ipstruct import Struct |
|
56 | from IPython.utils.io import Term, ask_yes_no | |
|
56 | import IPython.utils.io | |
|
57 | from IPython.utils.io import ask_yes_no | |
|
57 | 58 | from IPython.utils.path import get_home_dir, get_ipython_dir, HomeDirError |
|
58 | 59 | from IPython.utils.process import getoutput, getoutputerror |
|
59 | 60 | from IPython.utils.strdispatch import StrDispatch |
@@ -250,6 +251,10 b' class InteractiveShell(Configurable, Magic):' | |||
|
250 | 251 | self.init_syntax_highlighting() |
|
251 | 252 | self.init_hooks() |
|
252 | 253 | self.init_pushd_popd_magic() |
|
254 | # TODO: init_io() needs to happen before init_traceback handlers | |
|
255 | # because the traceback handlers hardcode the stdout/stderr streams. | |
|
256 | # This logic in in debugger.Pdb and should eventually be changed. | |
|
257 | self.init_io() | |
|
253 | 258 | self.init_traceback_handlers(custom_exceptions) |
|
254 | 259 | self.init_user_ns() |
|
255 | 260 | self.init_logger() |
@@ -411,6 +416,17 b' class InteractiveShell(Configurable, Magic):' | |||
|
411 | 416 | 'NoColor', |
|
412 | 417 | self.object_info_string_level) |
|
413 | 418 | |
|
419 | def init_io(self): | |
|
420 | import IPython.utils.io | |
|
421 | if sys.platform == 'win32' and readline.have_readline and \ | |
|
422 | self.readline_use: | |
|
423 | Term = IPython.utils.io.IOTerm( | |
|
424 | cout=readline._outputfile,cerr=readline._outputfile | |
|
425 | ) | |
|
426 | else: | |
|
427 | Term = IPython.utils.io.IOTerm() | |
|
428 | IPython.utils.io.Term = Term | |
|
429 | ||
|
414 | 430 | def init_prompts(self): |
|
415 | 431 | # Initialize cache, set in/out prompts and printing system |
|
416 | 432 | self.outputcache = CachedOutput(self, |
@@ -1997,12 +2013,12 b' class InteractiveShell(Configurable, Magic):' | |||
|
1997 | 2013 | # TODO: This should be removed when Term is refactored. |
|
1998 | 2014 | def write(self,data): |
|
1999 | 2015 | """Write a string to the default output""" |
|
2000 | Term.cout.write(data) | |
|
2016 | IPython.utils.io.Term.cout.write(data) | |
|
2001 | 2017 | |
|
2002 | 2018 | # TODO: This should be removed when Term is refactored. |
|
2003 | 2019 | def write_err(self,data): |
|
2004 | 2020 | """Write a string to the default error output""" |
|
2005 | Term.cerr.write(data) | |
|
2021 | IPython.utils.io.Term.cerr.write(data) | |
|
2006 | 2022 | |
|
2007 | 2023 | def ask_yes_no(self,prompt,default=True): |
|
2008 | 2024 | if self.quiet: |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | # the file COPYING, distributed as part of this software. |
|
8 | 8 | #***************************************************************************** |
|
9 | 9 | |
|
10 |
|
|
|
10 | import IPython.utils.io | |
|
11 | 11 | from IPython.core.autocall import IPyAutocall |
|
12 | 12 | |
|
13 | 13 | class Macro(IPyAutocall): |
@@ -32,7 +32,7 b' class Macro(IPyAutocall):' | |||
|
32 | 32 | return 'IPython.macro.Macro(%s)' % repr(self.value) |
|
33 | 33 | |
|
34 | 34 | def __call__(self,*args): |
|
35 | Term.cout.flush() | |
|
35 | IPython.utils.io.Term.cout.flush() | |
|
36 | 36 | self._ip.user_ns['_margv'] = args |
|
37 | 37 | self._ip.runlines(self.value) |
|
38 | 38 |
@@ -58,7 +58,8 b' from IPython.lib.pylabtools import mpl_runner' | |||
|
58 | 58 | from IPython.lib.inputhook import enable_gui |
|
59 | 59 | from IPython.external.Itpl import itpl, printpl |
|
60 | 60 | from IPython.testing import decorators as testdec |
|
61 |
from IPython.utils.io import |
|
|
61 | from IPython.utils.io import file_read, nlprint | |
|
62 | import IPython.utils.io | |
|
62 | 63 | from IPython.utils.path import get_py_filename |
|
63 | 64 | from IPython.utils.process import arg_split, abbrev_cwd |
|
64 | 65 | from IPython.utils.terminal import set_term_title |
@@ -3093,7 +3094,7 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
3093 | 3094 | # If all looks ok, proceed |
|
3094 | 3095 | out,err = self.shell.getoutputerror(cmd) |
|
3095 | 3096 | if err: |
|
3096 | print >> Term.cerr,err | |
|
3097 | print >> IPython.utils.io.Term.cerr, err | |
|
3097 | 3098 | if opts.has_key('l'): |
|
3098 | 3099 | out = SList(out.split('\n')) |
|
3099 | 3100 | else: |
@@ -3143,7 +3144,7 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
3143 | 3144 | if parameter_s: |
|
3144 | 3145 | out,err = self.shell.getoutputerror(parameter_s) |
|
3145 | 3146 | if err: |
|
3146 | print >> Term.cerr,err | |
|
3147 | print >> IPython.utils.io.Term.cerr, err | |
|
3147 | 3148 | return SList(out.split('\n')) |
|
3148 | 3149 | |
|
3149 | 3150 | def magic_r(self, parameter_s=''): |
@@ -30,7 +30,7 b' import types' | |||
|
30 | 30 | from IPython.core.page import page |
|
31 | 31 | from IPython.external.Itpl import itpl |
|
32 | 32 | from IPython.utils import PyColorize |
|
33 |
|
|
|
33 | import IPython.utils.io | |
|
34 | 34 | from IPython.utils.text import indent |
|
35 | 35 | from IPython.utils.wildcard import list_namespace |
|
36 | 36 | from IPython.utils.coloransi import * |
@@ -249,7 +249,7 b' class Inspector:' | |||
|
249 | 249 | if output is None: |
|
250 | 250 | self.noinfo('definition header',oname) |
|
251 | 251 | else: |
|
252 | print >>Term.cout, header,self.format(output), | |
|
252 | print >>IPython.utils.io.Term.cout, header,self.format(output), | |
|
253 | 253 | |
|
254 | 254 | def pdoc(self,obj,oname='',formatter = None): |
|
255 | 255 | """Print the docstring for any object. |
@@ -36,7 +36,7 b' from IPython.core import ipapi' | |||
|
36 | 36 | from IPython.core.error import TryNext |
|
37 | 37 | from IPython.utils.cursesimport import use_curses |
|
38 | 38 | from IPython.utils.data import chop |
|
39 |
|
|
|
39 | import IPython.utils.io | |
|
40 | 40 | from IPython.utils.process import xsys |
|
41 | 41 | from IPython.utils.terminal import get_terminal_size |
|
42 | 42 | |
@@ -56,18 +56,18 b' def page_dumb(strng, start=0, screen_lines=25):' | |||
|
56 | 56 | out_ln = strng.splitlines()[start:] |
|
57 | 57 | screens = chop(out_ln,screen_lines-1) |
|
58 | 58 | if len(screens) == 1: |
|
59 | print >>Term.cout, os.linesep.join(screens[0]) | |
|
59 | print >>IPython.utils.io.Term.cout, os.linesep.join(screens[0]) | |
|
60 | 60 | else: |
|
61 | 61 | last_escape = "" |
|
62 | 62 | for scr in screens[0:-1]: |
|
63 | 63 | hunk = os.linesep.join(scr) |
|
64 | print >>Term.cout, last_escape + hunk | |
|
64 | print >>IPython.utils.io.Term.cout, last_escape + hunk | |
|
65 | 65 | if not page_more(): |
|
66 | 66 | return |
|
67 | 67 | esc_list = esc_re.findall(hunk) |
|
68 | 68 | if len(esc_list) > 0: |
|
69 | 69 | last_escape = esc_list[-1] |
|
70 | print >>Term.cout, last_escape + os.linesep.join(screens[-1]) | |
|
70 | print >>IPython.utils.io.Term.cout, last_escape + os.linesep.join(screens[-1]) | |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | def page(strng, start=0, screen_lines=0, pager_cmd=None): |
@@ -156,7 +156,7 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||
|
156 | 156 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
157 | 157 | if numlines <= screen_lines : |
|
158 | 158 | #print '*** normal print' # dbg |
|
159 | print >>Term.cout, str_toprint | |
|
159 | print >>IPython.utils.io.Term.cout, str_toprint | |
|
160 | 160 | else: |
|
161 | 161 | # Try to open pager and default to internal one if that fails. |
|
162 | 162 | # All failure modes are tagged as 'retval=1', to match the return |
@@ -262,13 +262,13 b" if os.name == 'nt' and os.environ.get('TERM','dumb') != 'emacs':" | |||
|
262 | 262 | |
|
263 | 263 | @return: True if need print more lines, False if quit |
|
264 | 264 | """ |
|
265 | Term.cout.write('---Return to continue, q to quit--- ') | |
|
265 | IPython.utils.io.Term.cout.write('---Return to continue, q to quit--- ') | |
|
266 | 266 | ans = msvcrt.getch() |
|
267 | 267 | if ans in ("q", "Q"): |
|
268 | 268 | result = False |
|
269 | 269 | else: |
|
270 | 270 | result = True |
|
271 | Term.cout.write("\b"*37 + " "*37 + "\b"*37) | |
|
271 | IPython.utils.io.Term.cout.write("\b"*37 + " "*37 + "\b"*37) | |
|
272 | 272 | return result |
|
273 | 273 | else: |
|
274 | 274 | def page_more(): |
@@ -36,7 +36,7 b' from IPython.core.splitinput import split_user_input' | |||
|
36 | 36 | from IPython.core.page import page |
|
37 | 37 | |
|
38 | 38 | from IPython.utils.traitlets import List, Int, Any, Str, CBool, Bool, Instance |
|
39 |
|
|
|
39 | import IPython.utils.io | |
|
40 | 40 | from IPython.utils.text import make_quoted_expr |
|
41 | 41 | from IPython.utils.autoattr import auto_attr |
|
42 | 42 | |
@@ -922,7 +922,7 b' class AutoHandler(PrefilterHandler):' | |||
|
922 | 922 | # plain ascii works better w/ pyreadline, on some machines, so |
|
923 | 923 | # we use it and only print uncolored rewrite if we have unicode |
|
924 | 924 | rw = str(rw) |
|
925 | print >>Term.cout, rw | |
|
925 | print >>IPython.utils.io.Term.cout, rw | |
|
926 | 926 | except UnicodeEncodeError: |
|
927 | 927 | print "-------------->" + newcmd |
|
928 | 928 |
@@ -25,7 +25,7 b' from IPython.core.error import TryNext' | |||
|
25 | 25 | from IPython.utils import coloransi |
|
26 | 26 | import IPython.utils.generics |
|
27 | 27 | from IPython.utils.warn import warn |
|
28 |
|
|
|
28 | import IPython.utils.io | |
|
29 | 29 | |
|
30 | 30 | #**************************************************************************** |
|
31 | 31 | #Color schemes for Prompts. |
@@ -537,7 +537,7 b' class CachedOutput:' | |||
|
537 | 537 | except KeyError: |
|
538 | 538 | pass |
|
539 | 539 | if arg is not None: |
|
540 | cout_write = Term.cout.write # fast lookup | |
|
540 | cout_write = IPython.utils.io.Term.cout.write # fast lookup | |
|
541 | 541 | # first handle the cache and counters |
|
542 | 542 | |
|
543 | 543 | # do not print output if input ends in ';' |
@@ -577,7 +577,7 b' class CachedOutput:' | |||
|
577 | 577 | if self.logger.log_output: |
|
578 | 578 | self.logger.log_write(repr(arg),'output') |
|
579 | 579 | cout_write(self.output_sep2) |
|
580 | Term.cout.flush() | |
|
580 | IPython.utils.io.Term.cout.flush() | |
|
581 | 581 | |
|
582 | 582 | def _display(self,arg): |
|
583 | 583 | """Default printer method, uses pprint. |
@@ -95,7 +95,7 b' from IPython.core import debugger, ipapi' | |||
|
95 | 95 | from IPython.core.display_trap import DisplayTrap |
|
96 | 96 | from IPython.core.excolors import exception_colors |
|
97 | 97 | from IPython.utils.data import uniq_stable |
|
98 |
|
|
|
98 | import IPython.utils.io | |
|
99 | 99 | from IPython.utils.warn import info, error |
|
100 | 100 | |
|
101 | 101 | # Globals |
@@ -313,14 +313,11 b' def _format_traceback_lines(lnum, index, lines, Colors, lvals=None,scheme=None):' | |||
|
313 | 313 | class TBTools: |
|
314 | 314 | """Basic tools used by all traceback printer classes.""" |
|
315 | 315 | |
|
316 | #: Default output stream, can be overridden at call time. A special value | |
|
317 | #: of 'stdout' *as a string* can be given to force extraction of sys.stdout | |
|
318 | #: at runtime. This allows testing exception printing with doctests, that | |
|
319 | #: swap sys.stdout just at execution time. | |
|
320 | #: Warning: be VERY careful to set this to one of the Term streams, NEVER | |
|
321 | #: directly to sys.stdout/err, because under win32 the Term streams come from | |
|
322 | #: pyreadline and know how to handle color correctly, whie stdout/err don't. | |
|
323 | out_stream = Term.cerr | |
|
316 | # This attribute us used in globalipapp.py to have stdout used for | |
|
317 | # writting exceptions. This is needed so nose can trap them. This attribute | |
|
318 | # should be None (the default, which will use IPython.utils.io.Term) or | |
|
319 | # the string 'stdout' which will cause the override to sys.stdout. | |
|
320 | out_stream = None | |
|
324 | 321 | |
|
325 | 322 | def __init__(self,color_scheme = 'NoColor',call_pdb=False): |
|
326 | 323 | # Whether to call the interactive pdb debugger after printing |
@@ -384,9 +381,9 b' class ListTB(TBTools):' | |||
|
384 | 381 | TBTools.__init__(self,color_scheme = color_scheme,call_pdb=0) |
|
385 | 382 | |
|
386 | 383 | def __call__(self, etype, value, elist): |
|
387 | Term.cout.flush() | |
|
388 | Term.cerr.write(self.text(etype,value,elist)) | |
|
389 | Term.cerr.write('\n') | |
|
384 | IPython.utils.io.Term.cout.flush() | |
|
385 | IPython.utils.io.Term.cerr.write(self.text(etype,value,elist)) | |
|
386 | IPython.utils.io.Term.cerr.write('\n') | |
|
390 | 387 | |
|
391 | 388 | def text(self, etype, value, elist, context=5): |
|
392 | 389 | """Return a color formatted string with the traceback info. |
@@ -535,10 +532,13 b' class ListTB(TBTools):' | |||
|
535 | 532 | """ |
|
536 | 533 | # This method needs to use __call__ from *this* class, not the one from |
|
537 | 534 | # a subclass whose signature or behavior may be different |
|
538 | Term.cout.flush() | |
|
539 | ostream = sys.stdout if self.out_stream == 'stdout' else Term.cerr | |
|
535 | if self.out_stream == 'stdout': | |
|
536 | ostream = sys.stdout | |
|
537 | else: | |
|
538 | ostream = IPython.utils.io.Term.cerr | |
|
539 | ostream.flush() | |
|
540 | 540 | ostream.write(ListTB.text(self, etype, value, [])) |
|
541 |
ostream.flush() |
|
|
541 | ostream.flush() | |
|
542 | 542 | |
|
543 | 543 | def _some_str(self, value): |
|
544 | 544 | # Lifted from traceback.py |
@@ -659,7 +659,7 b' class VerboseTB(TBTools):' | |||
|
659 | 659 | # So far, I haven't been able to find an isolated example to |
|
660 | 660 | # reproduce the problem. |
|
661 | 661 | inspect_error() |
|
662 | traceback.print_exc(file=Term.cerr) | |
|
662 | traceback.print_exc(file=IPython.utils.io.Term.cerr) | |
|
663 | 663 | info('\nUnfortunately, your original traceback can not be constructed.\n') |
|
664 | 664 | return '' |
|
665 | 665 | |
@@ -696,7 +696,7 b' class VerboseTB(TBTools):' | |||
|
696 | 696 | # able to remove this try/except when 2.4 becomes a |
|
697 | 697 | # requirement. Bug details at http://python.org/sf/1005466 |
|
698 | 698 | inspect_error() |
|
699 | traceback.print_exc(file=Term.cerr) | |
|
699 | traceback.print_exc(file=IPython.utils.io.Term.cerr) | |
|
700 | 700 | info("\nIPython's exception reporting continues...\n") |
|
701 | 701 | |
|
702 | 702 | if func == '?': |
@@ -717,7 +717,7 b' class VerboseTB(TBTools):' | |||
|
717 | 717 | # and barfs out. At some point I should dig into this one |
|
718 | 718 | # and file a bug report about it. |
|
719 | 719 | inspect_error() |
|
720 | traceback.print_exc(file=Term.cerr) | |
|
720 | traceback.print_exc(file=IPython.utils.io.Term.cerr) | |
|
721 | 721 | info("\nIPython's exception reporting continues...\n") |
|
722 | 722 | call = tpl_call_fail % func |
|
723 | 723 | |
@@ -910,9 +910,9 b' class VerboseTB(TBTools):' | |||
|
910 | 910 | def handler(self, info=None): |
|
911 | 911 | (etype, evalue, etb) = info or sys.exc_info() |
|
912 | 912 | self.tb = etb |
|
913 | Term.cout.flush() | |
|
914 | Term.cerr.write(self.text(etype, evalue, etb)) | |
|
915 | Term.cerr.write('\n') | |
|
913 | IPython.utils.io.Term.cout.flush() | |
|
914 | IPython.utils.io.Term.cerr.write(self.text(etype, evalue, etb)) | |
|
915 | IPython.utils.io.Term.cerr.write('\n') | |
|
916 | 916 | |
|
917 | 917 | # Changed so an instance can just be called as VerboseTB_inst() and print |
|
918 | 918 | # out the right info on its own. |
@@ -1032,8 +1032,11 b' class AutoFormattedTB(FormattedTB):' | |||
|
1032 | 1032 | given at initialization time. """ |
|
1033 | 1033 | |
|
1034 | 1034 | if out is None: |
|
1035 |
|
|
|
1036 | Term.cout.flush() | |
|
1035 | if self.out_stream == 'stdout': | |
|
1036 | out = sys.stdout | |
|
1037 | else: | |
|
1038 | out = IPython.utils.io.Term.cerr | |
|
1039 | out.flush() | |
|
1037 | 1040 | if tb_offset is not None: |
|
1038 | 1041 | tb_offset, self.tb_offset = self.tb_offset, tb_offset |
|
1039 | 1042 | out.write(self.text(etype, evalue, etb)) |
@@ -24,7 +24,7 b' import locale' | |||
|
24 | 24 | from thread_ex import ThreadEx |
|
25 | 25 | |
|
26 | 26 | from IPython.core import iplib |
|
27 |
|
|
|
27 | import IPython.utils.io | |
|
28 | 28 | |
|
29 | 29 | ############################################################################## |
|
30 | 30 | class _Helper(object): |
@@ -133,7 +133,7 b' from IPython.external import simplegeneric' | |||
|
133 | 133 | from IPython.external import path |
|
134 | 134 | |
|
135 | 135 | try: |
|
136 |
|
|
|
136 | import IPython.utils.io | |
|
137 | 137 | from IPython.utils import generics |
|
138 | 138 | except ImportError: |
|
139 | 139 | Term = None |
@@ -31,7 +31,7 b' from IPython.kernel.core.redirector_output_trap import RedirectorOutputTrap' | |||
|
31 | 31 | |
|
32 | 32 | from IPython.kernel.core.sync_traceback_trap import SyncTracebackTrap |
|
33 | 33 | |
|
34 |
|
|
|
34 | import IPython.utils.io | |
|
35 | 35 | |
|
36 | 36 | from linefrontendbase import LineFrontEndBase, common_prefix |
|
37 | 37 |
@@ -14,7 +14,7 b' from IPython.core.iplib import InteractiveShell' | |||
|
14 | 14 | from IPython.utils.ipstruct import Struct |
|
15 | 15 | import Queue,thread,threading,signal |
|
16 | 16 | from signal import signal, SIGINT |
|
17 |
|
|
|
17 | import IPython.utils.io, ask_yes_no | |
|
18 | 18 | from IPython.utils.warn import warn, error |
|
19 | 19 | from IPython.utils.decorators import flag_calls |
|
20 | 20 | from IPython.core import shellglobals |
@@ -39,7 +39,7 b' from IPython.core.error import TryNext' | |||
|
39 | 39 | from IPython.external import pretty |
|
40 | 40 | from IPython.core.plugin import Plugin |
|
41 | 41 | from IPython.utils.traitlets import Bool, List, Instance |
|
42 |
|
|
|
42 | import IPython.utils.io | |
|
43 | 43 | from IPython.utils.autoattr import auto_attr |
|
44 | 44 | from IPython.utils.importstring import import_item |
|
45 | 45 | |
@@ -100,8 +100,8 b' class PrettyResultDisplay(Plugin):' | |||
|
100 | 100 | # So that multi-line strings line up with the left column of |
|
101 | 101 | # the screen, instead of having the output prompt mess up |
|
102 | 102 | # their first line. |
|
103 | Term.cout.write('\n') | |
|
104 | print >>Term.cout, out | |
|
103 | IPython.utils.io.Term.cout.write('\n') | |
|
104 | print >>IPython.utils.io.Term.cout, out | |
|
105 | 105 | else: |
|
106 | 106 | raise TryNext |
|
107 | 107 |
@@ -32,7 +32,7 b' from IPython.external.Itpl import ItplNS' | |||
|
32 | 32 | from IPython.utils import coloransi |
|
33 | 33 | from IPython.core import release |
|
34 | 34 | from IPython.core.error import TryNext |
|
35 |
|
|
|
35 | import IPython.utils.io | |
|
36 | 36 | from IPython.utils.warn import warn |
|
37 | 37 | import IPython.utils.generics |
|
38 | 38 |
@@ -176,7 +176,8 b' import shlex' | |||
|
176 | 176 | import sys |
|
177 | 177 | |
|
178 | 178 | from IPython.utils.PyColorize import Parser |
|
179 |
from IPython.utils.io import file_read, file_readlines |
|
|
179 | from IPython.utils.io import file_read, file_readlines | |
|
180 | import IPython.utils.io | |
|
180 | 181 | from IPython.utils.text import marquee |
|
181 | 182 | |
|
182 | 183 | __all__ = ['Demo','IPythonDemo','LineDemo','IPythonLineDemo','DemoError'] |
@@ -318,7 +319,7 b' class Demo(object):' | |||
|
318 | 319 | |
|
319 | 320 | if index is None: |
|
320 | 321 | if self.finished: |
|
321 | print >>Term.cout, 'Demo finished. Use <demo_name>.reset() if you want to rerun it.' | |
|
322 | print >>IPython.utils.io.Term.cout, 'Demo finished. Use <demo_name>.reset() if you want to rerun it.' | |
|
322 | 323 | return None |
|
323 | 324 | index = self.block_index |
|
324 | 325 | else: |
@@ -387,9 +388,9 b' class Demo(object):' | |||
|
387 | 388 | if index is None: |
|
388 | 389 | return |
|
389 | 390 | |
|
390 | print >>Term.cout, self.marquee('<%s> block # %s (%s remaining)' % | |
|
391 | print >>IPython.utils.io.Term.cout, self.marquee('<%s> block # %s (%s remaining)' % | |
|
391 | 392 | (self.title,index,self.nblocks-index-1)) |
|
392 | print >>Term.cout,(self.src_blocks_colored[index]) | |
|
393 | print >>IPython.utils.io.Term.cout,(self.src_blocks_colored[index]) | |
|
393 | 394 | sys.stdout.flush() |
|
394 | 395 | |
|
395 | 396 | def show_all(self): |
@@ -402,12 +403,12 b' class Demo(object):' | |||
|
402 | 403 | marquee = self.marquee |
|
403 | 404 | for index,block in enumerate(self.src_blocks_colored): |
|
404 | 405 | if silent[index]: |
|
405 | print >>Term.cout, marquee('<%s> SILENT block # %s (%s remaining)' % | |
|
406 | print >>IPython.utils.io.Term.cout, marquee('<%s> SILENT block # %s (%s remaining)' % | |
|
406 | 407 | (title,index,nblocks-index-1)) |
|
407 | 408 | else: |
|
408 | print >>Term.cout, marquee('<%s> block # %s (%s remaining)' % | |
|
409 | print >>IPython.utils.io.Term.cout, marquee('<%s> block # %s (%s remaining)' % | |
|
409 | 410 | (title,index,nblocks-index-1)) |
|
410 | print >>Term.cout, block, | |
|
411 | print >>IPython.utils.io.Term.cout, block, | |
|
411 | 412 | sys.stdout.flush() |
|
412 | 413 | |
|
413 | 414 | def runlines(self,source): |
@@ -432,18 +433,18 b' class Demo(object):' | |||
|
432 | 433 | next_block = self.src_blocks[index] |
|
433 | 434 | self.block_index += 1 |
|
434 | 435 | if self._silent[index]: |
|
435 | print >>Term.cout, marquee('Executing silent block # %s (%s remaining)' % | |
|
436 | print >>IPython.utils.io.Term.cout, marquee('Executing silent block # %s (%s remaining)' % | |
|
436 | 437 | (index,self.nblocks-index-1)) |
|
437 | 438 | else: |
|
438 | 439 | self.pre_cmd() |
|
439 | 440 | self.show(index) |
|
440 | 441 | if self.auto_all or self._auto[index]: |
|
441 | print >>Term.cout, marquee('output:') | |
|
442 | print >>IPython.utils.io.Term.cout, marquee('output:') | |
|
442 | 443 | else: |
|
443 | print >>Term.cout, marquee('Press <q> to quit, <Enter> to execute...'), | |
|
444 | print >>IPython.utils.io.Term.cout, marquee('Press <q> to quit, <Enter> to execute...'), | |
|
444 | 445 | ans = raw_input().strip() |
|
445 | 446 | if ans: |
|
446 | print >>Term.cout, marquee('Block NOT executed') | |
|
447 | print >>IPython.utils.io.Term.cout, marquee('Block NOT executed') | |
|
447 | 448 | return |
|
448 | 449 | try: |
|
449 | 450 | save_argv = sys.argv |
@@ -461,10 +462,10 b' class Demo(object):' | |||
|
461 | 462 | if self.block_index == self.nblocks: |
|
462 | 463 | mq1 = self.marquee('END OF DEMO') |
|
463 | 464 | if mq1: |
|
464 | # avoid spurious print >>Term.cout,s if empty marquees are used | |
|
465 | print >>Term.cout | |
|
466 | print >>Term.cout, mq1 | |
|
467 | print >>Term.cout, self.marquee('Use <demo_name>.reset() if you want to rerun it.') | |
|
465 | # avoid spurious print >>IPython.utils.io.Term.cout,s if empty marquees are used | |
|
466 | print >>IPython.utils.io.Term.cout | |
|
467 | print >>IPython.utils.io.Term.cout, mq1 | |
|
468 | print >>IPython.utils.io.Term.cout, self.marquee('Use <demo_name>.reset() if you want to rerun it.') | |
|
468 | 469 | self.finished = True |
|
469 | 470 | |
|
470 | 471 | # These methods are meant to be overridden by subclasses who may wish to |
@@ -65,21 +65,10 b' class IOTerm:' | |||
|
65 | 65 | # In the future, having IPython channel all its I/O operations through |
|
66 | 66 | # this class will make it easier to embed it into other environments which |
|
67 | 67 | # are not a normal terminal (such as a GUI-based shell) |
|
68 | def __init__(self,cin=None,cout=None,cerr=None): | |
|
69 | self.cin = IOStream(cin,sys.stdin) | |
|
70 | self.cout = IOStream(cout,sys.stdout) | |
|
71 | self.cerr = IOStream(cerr,sys.stderr) | |
|
72 | ||
|
73 | ||
|
74 | # Global variable to be used for all I/O | |
|
75 | Term = IOTerm() | |
|
76 | ||
|
77 | ||
|
78 | import IPython.utils.rlineimpl as readline | |
|
79 | # Remake Term to use the readline i/o facilities | |
|
80 | if sys.platform == 'win32' and readline.have_readline: | |
|
81 | ||
|
82 | Term = IOTerm(cout=readline._outputfile,cerr=readline._outputfile) | |
|
68 | def __init__(self, cin=None, cout=None, cerr=None): | |
|
69 | self.cin = IOStream(cin, sys.stdin) | |
|
70 | self.cout = IOStream(cout, sys.stdout) | |
|
71 | self.cerr = IOStream(cerr, sys.stderr) | |
|
83 | 72 | |
|
84 | 73 | |
|
85 | 74 | class Tee(object): |
@@ -16,7 +16,7 b" Utilities for warnings. Shoudn't we just use the built in warnings module." | |||
|
16 | 16 | |
|
17 | 17 | import sys |
|
18 | 18 | |
|
19 |
|
|
|
19 | import IPython.utils.io | |
|
20 | 20 | |
|
21 | 21 | #----------------------------------------------------------------------------- |
|
22 | 22 | # Code |
@@ -25,7 +25,7 b' from IPython.utils.io import Term' | |||
|
25 | 25 | def warn(msg,level=2,exit_val=1): |
|
26 | 26 | """Standard warning printer. Gives formatting consistency. |
|
27 | 27 | |
|
28 | Output is sent to Term.cerr (sys.stderr by default). | |
|
28 | Output is sent to IPython.utils.io.Term.cerr (sys.stderr by default). | |
|
29 | 29 | |
|
30 | 30 | Options: |
|
31 | 31 | |
@@ -41,9 +41,9 b' def warn(msg,level=2,exit_val=1):' | |||
|
41 | 41 | |
|
42 | 42 | if level>0: |
|
43 | 43 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
44 | print >> Term.cerr, '%s%s' % (header[level],msg) | |
|
44 | print >> IPython.utils.io.Term.cerr, '%s%s' % (header[level],msg) | |
|
45 | 45 | if level == 4: |
|
46 | print >> Term.cerr,'Exiting.\n' | |
|
46 | print >> IPython.utils.io.Term.cerr,'Exiting.\n' | |
|
47 | 47 | sys.exit(exit_val) |
|
48 | 48 | |
|
49 | 49 |
@@ -266,9 +266,12 b' def main():' | |||
|
266 | 266 | req_port = bind_port(req_socket, namespace.ip, namespace.req) |
|
267 | 267 | print >>sys.__stdout__, "REQ Channel on port", req_port |
|
268 | 268 | |
|
269 |
# Redirect input streams |
|
|
269 | # Redirect input streams. This needs to be done before the Kernel is done | |
|
270 | # because currently the Kernel creates a ZMQInteractiveShell, which | |
|
271 | # holds references to sys.stdout and sys.stderr. | |
|
270 | 272 | sys.stdout = OutStream(session, pub_socket, u'stdout') |
|
271 | 273 | sys.stderr = OutStream(session, pub_socket, u'stderr') |
|
274 | # Set a displayhook. | |
|
272 | 275 | sys.displayhook = DisplayHook(session, pub_socket) |
|
273 | 276 | |
|
274 | 277 | # Create the kernel. |
@@ -19,4 +19,13 b' class ZMQInteractiveShell(InteractiveShell):' | |||
|
19 | 19 | print line |
|
20 | 20 | return p.wait() |
|
21 | 21 | |
|
22 | def init_io(self): | |
|
23 | # This will just use sys.stdout and sys.stderr. If you want to | |
|
24 | # override sys.stdout and sys.stderr themselves, you need to do that | |
|
25 | # *before* instantiating this class, because Term holds onto | |
|
26 | # references to the underlying streams. | |
|
27 | import IPython.utils.io | |
|
28 | Term = IPython.utils.io.IOTerm() | |
|
29 | IPython.utils.io.Term = Term | |
|
30 | ||
|
22 | 31 | InteractiveShellABC.register(ZMQInteractiveShell) |
General Comments 0
You need to be logged in to leave comments.
Login now