Show More
@@ -18,6 +18,7 b' Authors:' | |||||
18 | #----------------------------------------------------------------------------- |
|
18 | #----------------------------------------------------------------------------- | |
19 | # Imports |
|
19 | # Imports | |
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
|
21 | from __future__ import print_function | |||
21 |
|
22 | |||
22 | import os |
|
23 | import os | |
23 | import sys |
|
24 | import sys | |
@@ -159,18 +160,18 b' class CrashHandler(object):' | |||||
159 |
|
160 | |||
160 | # print traceback to screen |
|
161 | # print traceback to screen | |
161 | if self.show_crash_traceback: |
|
162 | if self.show_crash_traceback: | |
162 |
print |
|
163 | print(traceback, file=sys.stderr) | |
163 |
|
164 | |||
164 | # and generate a complete report on disk |
|
165 | # and generate a complete report on disk | |
165 | try: |
|
166 | try: | |
166 | report = open(report_name,'w') |
|
167 | report = open(report_name,'w') | |
167 | except: |
|
168 | except: | |
168 |
print |
|
169 | print('Could not create crash report on disk.', file=sys.stderr) | |
169 | return |
|
170 | return | |
170 |
|
171 | |||
171 | # Inform user on stderr of what happened |
|
172 | # Inform user on stderr of what happened | |
172 |
print |
|
173 | print('\n'+'*'*70+'\n', file=sys.stderr) | |
173 |
print |
|
174 | print(self.message_template.format(**self.info), file=sys.stderr) | |
174 |
|
175 | |||
175 | # Construct report on disk |
|
176 | # Construct report on disk | |
176 | report.write(self.make_report(traceback)) |
|
177 | report.write(self.make_report(traceback)) | |
@@ -210,5 +211,5 b' def crash_handler_lite(etype, evalue, tb):' | |||||
210 | else: |
|
211 | else: | |
211 | # we are not in a shell, show generic config |
|
212 | # we are not in a shell, show generic config | |
212 | config = "c." |
|
213 | config = "c." | |
213 |
print |
|
214 | print(_lite_message_template.format(email=author_email, config=config), file=sys.stderr) | |
214 |
|
215 |
@@ -24,6 +24,7 b' http://www.python.org/2.2.3/license.html"""' | |||||
24 | # |
|
24 | # | |
25 | # |
|
25 | # | |
26 | #***************************************************************************** |
|
26 | #***************************************************************************** | |
|
27 | from __future__ import print_function | |||
27 |
|
28 | |||
28 | import bdb |
|
29 | import bdb | |
29 | import linecache |
|
30 | import linecache | |
@@ -46,7 +47,7 b" if '--pydb' in sys.argv:" | |||||
46 | # better protect against it. |
|
47 | # better protect against it. | |
47 | has_pydb = True |
|
48 | has_pydb = True | |
48 | except ImportError: |
|
49 | except ImportError: | |
49 |
print |
|
50 | print("Pydb (http://bashdb.sourceforge.net/pydb/) does not seem to be available") | |
50 |
|
51 | |||
51 | if has_pydb: |
|
52 | if has_pydb: | |
52 | from pydb import Pdb as OldPdb |
|
53 | from pydb import Pdb as OldPdb | |
@@ -60,12 +61,12 b' else:' | |||||
60 | # the Tracer constructor. |
|
61 | # the Tracer constructor. | |
61 | def BdbQuit_excepthook(et,ev,tb): |
|
62 | def BdbQuit_excepthook(et,ev,tb): | |
62 | if et==bdb.BdbQuit: |
|
63 | if et==bdb.BdbQuit: | |
63 |
print |
|
64 | print('Exiting Debugger.') | |
64 | else: |
|
65 | else: | |
65 | BdbQuit_excepthook.excepthook_ori(et,ev,tb) |
|
66 | BdbQuit_excepthook.excepthook_ori(et,ev,tb) | |
66 |
|
67 | |||
67 | def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None): |
|
68 | def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None): | |
68 |
print |
|
69 | print('Exiting Debugger.') | |
69 |
|
70 | |||
70 |
|
71 | |||
71 | class Tracer(object): |
|
72 | class Tracer(object): | |
@@ -294,7 +295,7 b' class Pdb(OldPdb):' | |||||
294 | def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ', |
|
295 | def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ', | |
295 | context = 3): |
|
296 | context = 3): | |
296 | #frame, lineno = frame_lineno |
|
297 | #frame, lineno = frame_lineno | |
297 |
print |
|
298 | print(self.format_stack_entry(frame_lineno, '', context), file=io.stdout) | |
298 |
|
299 | |||
299 | # vds: >> |
|
300 | # vds: >> | |
300 | frame, lineno = frame_lineno |
|
301 | frame, lineno = frame_lineno | |
@@ -434,7 +435,7 b' class Pdb(OldPdb):' | |||||
434 | src.append(line) |
|
435 | src.append(line) | |
435 | self.lineno = lineno |
|
436 | self.lineno = lineno | |
436 |
|
437 | |||
437 |
print |
|
438 | print(''.join(src), file=io.stdout) | |
438 |
|
439 | |||
439 | except KeyboardInterrupt: |
|
440 | except KeyboardInterrupt: | |
440 | pass |
|
441 | pass | |
@@ -455,7 +456,7 b' class Pdb(OldPdb):' | |||||
455 | else: |
|
456 | else: | |
456 | first = max(1, int(x) - 5) |
|
457 | first = max(1, int(x) - 5) | |
457 | except: |
|
458 | except: | |
458 |
print |
|
459 | print('*** Error in argument:', repr(arg)) | |
459 | return |
|
460 | return | |
460 | elif self.lineno is None: |
|
461 | elif self.lineno is None: | |
461 | first = max(1, self.curframe.f_lineno - 5) |
|
462 | first = max(1, self.curframe.f_lineno - 5) | |
@@ -514,12 +515,12 b' class Pdb(OldPdb):' | |||||
514 | ####################################################################### |
|
515 | ####################################################################### | |
515 |
|
516 | |||
516 | if not line: |
|
517 | if not line: | |
517 |
print |
|
518 | print('End of file', file=self.stdout) | |
518 | return 0 |
|
519 | return 0 | |
519 | line = line.strip() |
|
520 | line = line.strip() | |
520 | # Don't allow setting breakpoint at a blank line |
|
521 | # Don't allow setting breakpoint at a blank line | |
521 | if (not line or (line[0] == '#') or |
|
522 | if (not line or (line[0] == '#') or | |
522 | (line[:3] == '"""') or line[:3] == "'''"): |
|
523 | (line[:3] == '"""') or line[:3] == "'''"): | |
523 |
print |
|
524 | print('*** Blank or comment', file=self.stdout) | |
524 | return 0 |
|
525 | return 0 | |
525 | return lineno |
|
526 | return lineno |
@@ -21,6 +21,7 b' Authors:' | |||||
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 | # Imports |
|
22 | # Imports | |
23 | #----------------------------------------------------------------------------- |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | from __future__ import print_function | |||
24 |
|
25 | |||
25 | import __builtin__ |
|
26 | import __builtin__ | |
26 |
|
27 | |||
@@ -179,7 +180,7 b' class DisplayHook(Configurable):' | |||||
179 | # But avoid extraneous empty lines. |
|
180 | # But avoid extraneous empty lines. | |
180 | result_repr = '\n' + result_repr |
|
181 | result_repr = '\n' + result_repr | |
181 |
|
182 | |||
182 |
print |
|
183 | print(result_repr, file=io.stdout) | |
183 |
|
184 | |||
184 | def update_user_ns(self, result): |
|
185 | def update_user_ns(self, result): | |
185 | """Update user_ns with various things like _, __, _1, etc.""" |
|
186 | """Update user_ns with various things like _, __, _1, etc.""" |
@@ -16,6 +16,7 b'' | |||||
16 |
|
16 | |||
17 | from __future__ import with_statement |
|
17 | from __future__ import with_statement | |
18 | from __future__ import absolute_import |
|
18 | from __future__ import absolute_import | |
|
19 | from __future__ import print_function | |||
19 |
|
20 | |||
20 | import __builtin__ as builtin_mod |
|
21 | import __builtin__ as builtin_mod | |
21 | import __future__ |
|
22 | import __future__ | |
@@ -796,8 +797,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
796 |
|
797 | |||
797 | dp = getattr(self.hooks, name, None) |
|
798 | dp = getattr(self.hooks, name, None) | |
798 | if name not in IPython.core.hooks.__all__: |
|
799 | if name not in IPython.core.hooks.__all__: | |
799 |
print |
|
800 | print("Warning! Hook '%s' is not one of %s" % \ | |
800 | (name, IPython.core.hooks.__all__ ) |
|
801 | (name, IPython.core.hooks.__all__ )) | |
801 | if not dp: |
|
802 | if not dp: | |
802 | dp = IPython.core.hooks.CommandChainDispatcher() |
|
803 | dp = IPython.core.hooks.CommandChainDispatcher() | |
803 |
|
804 | |||
@@ -1318,7 +1319,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1318 | try: |
|
1319 | try: | |
1319 | vdict[name] = eval(name, cf.f_globals, cf.f_locals) |
|
1320 | vdict[name] = eval(name, cf.f_globals, cf.f_locals) | |
1320 | except: |
|
1321 | except: | |
1321 |
print |
|
1322 | print('Could not get variable %s from %s' % | |
1322 | (name,cf.f_code.co_name)) |
|
1323 | (name,cf.f_code.co_name)) | |
1323 | else: |
|
1324 | else: | |
1324 | raise ValueError('variables must be a dict/str/list/tuple') |
|
1325 | raise ValueError('variables must be a dict/str/list/tuple') | |
@@ -1493,7 +1494,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1493 | else: |
|
1494 | else: | |
1494 | pmethod(info.obj, oname) |
|
1495 | pmethod(info.obj, oname) | |
1495 | else: |
|
1496 | else: | |
1496 |
print |
|
1497 | print('Object `%s` not found.' % oname) | |
1497 | return 'not found' # so callers can take other action |
|
1498 | return 'not found' # so callers can take other action | |
1498 |
|
1499 | |||
1499 | def object_inspect(self, oname, detail_level=0): |
|
1500 | def object_inspect(self, oname, detail_level=0): | |
@@ -1587,10 +1588,10 b' class InteractiveShell(SingletonConfigurable):' | |||||
1587 | "The custom exceptions must be given AS A TUPLE." |
|
1588 | "The custom exceptions must be given AS A TUPLE." | |
1588 |
|
1589 | |||
1589 | def dummy_handler(self,etype,value,tb,tb_offset=None): |
|
1590 | def dummy_handler(self,etype,value,tb,tb_offset=None): | |
1590 |
print |
|
1591 | print('*** Simple custom exception handler ***') | |
1591 |
print |
|
1592 | print('Exception type :',etype) | |
1592 |
print |
|
1593 | print('Exception value:',value) | |
1593 |
print |
|
1594 | print('Traceback :',tb) | |
1594 | #print 'Source code :','\n'.join(self.buffer) |
|
1595 | #print 'Source code :','\n'.join(self.buffer) | |
1595 |
|
1596 | |||
1596 | def validate_stb(stb): |
|
1597 | def validate_stb(stb): | |
@@ -1631,11 +1632,11 b' class InteractiveShell(SingletonConfigurable):' | |||||
1631 | except: |
|
1632 | except: | |
1632 | # clear custom handler immediately |
|
1633 | # clear custom handler immediately | |
1633 | self.set_custom_exc((), None) |
|
1634 | self.set_custom_exc((), None) | |
1634 |
print |
|
1635 | print("Custom TB Handler failed, unregistering", file=io.stderr) | |
1635 | # show the exception in handler first |
|
1636 | # show the exception in handler first | |
1636 | stb = self.InteractiveTB.structured_traceback(*sys.exc_info()) |
|
1637 | stb = self.InteractiveTB.structured_traceback(*sys.exc_info()) | |
1637 |
print |
|
1638 | print(self.InteractiveTB.stb2text(stb), file=io.stdout) | |
1638 |
print |
|
1639 | print("The original exception:", file=io.stdout) | |
1639 | stb = self.InteractiveTB.structured_traceback( |
|
1640 | stb = self.InteractiveTB.structured_traceback( | |
1640 | (etype,value,tb), tb_offset=tb_offset |
|
1641 | (etype,value,tb), tb_offset=tb_offset | |
1641 | ) |
|
1642 | ) | |
@@ -1759,7 +1760,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1759 | Subclasses may override this method to put the traceback on a different |
|
1760 | Subclasses may override this method to put the traceback on a different | |
1760 | place, like a side channel. |
|
1761 | place, like a side channel. | |
1761 | """ |
|
1762 | """ | |
1762 |
print |
|
1763 | print(self.InteractiveTB.stb2text(stb), file=io.stdout) | |
1763 |
|
1764 | |||
1764 | def showsyntaxerror(self, filename=None): |
|
1765 | def showsyntaxerror(self, filename=None): | |
1765 | """Display the syntax error that just occurred. |
|
1766 | """Display the syntax error that just occurred. | |
@@ -2335,9 +2336,9 b' class InteractiveShell(SingletonConfigurable):' | |||||
2335 | # plain ascii works better w/ pyreadline, on some machines, so |
|
2336 | # plain ascii works better w/ pyreadline, on some machines, so | |
2336 | # we use it and only print uncolored rewrite if we have unicode |
|
2337 | # we use it and only print uncolored rewrite if we have unicode | |
2337 | rw = str(rw) |
|
2338 | rw = str(rw) | |
2338 |
print |
|
2339 | print(rw, file=io.stdout) | |
2339 | except UnicodeEncodeError: |
|
2340 | except UnicodeEncodeError: | |
2340 |
print |
|
2341 | print("------> " + cmd) | |
2341 |
|
2342 | |||
2342 | #------------------------------------------------------------------------- |
|
2343 | #------------------------------------------------------------------------- | |
2343 | # Things related to extracting values/expressions from kernel and user_ns |
|
2344 | # Things related to extracting values/expressions from kernel and user_ns | |
@@ -2626,17 +2627,17 b' class InteractiveShell(SingletonConfigurable):' | |||||
2626 | try: |
|
2627 | try: | |
2627 | func() |
|
2628 | func() | |
2628 | except KeyboardInterrupt: |
|
2629 | except KeyboardInterrupt: | |
2629 |
print |
|
2630 | print("\nKeyboardInterrupt", file=io.stderr) | |
2630 | except Exception: |
|
2631 | except Exception: | |
2631 | # register as failing: |
|
2632 | # register as failing: | |
2632 | self._post_execute[func] = False |
|
2633 | self._post_execute[func] = False | |
2633 | self.showtraceback() |
|
2634 | self.showtraceback() | |
2634 |
print |
|
2635 | print('\n'.join([ | |
2635 | "post-execution function %r produced an error." % func, |
|
2636 | "post-execution function %r produced an error." % func, | |
2636 | "If this problem persists, you can disable failing post-exec functions with:", |
|
2637 | "If this problem persists, you can disable failing post-exec functions with:", | |
2637 | "", |
|
2638 | "", | |
2638 | " get_ipython().disable_failing_post_execute = True" |
|
2639 | " get_ipython().disable_failing_post_execute = True" | |
2639 | ]) |
|
2640 | ]), file=io.stderr) | |
2640 |
|
2641 | |||
2641 | if store_history: |
|
2642 | if store_history: | |
2642 | # Write output to the database. Does nothing unless |
|
2643 | # Write output to the database. Does nothing unless | |
@@ -2698,7 +2699,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2698 |
|
2699 | |||
2699 | # Flush softspace |
|
2700 | # Flush softspace | |
2700 | if softspace(sys.stdout, 0): |
|
2701 | if softspace(sys.stdout, 0): | |
2701 |
|
2702 | print() | ||
2702 |
|
2703 | |||
2703 | except: |
|
2704 | except: | |
2704 | # It's possible to have exceptions raised here, typically by |
|
2705 | # It's possible to have exceptions raised here, typically by |
@@ -13,6 +13,7 b' reference the name under which an object is being read.' | |||||
13 | # Distributed under the terms of the BSD License. The full license is in |
|
13 | # Distributed under the terms of the BSD License. The full license is in | |
14 | # the file COPYING, distributed as part of this software. |
|
14 | # the file COPYING, distributed as part of this software. | |
15 | #***************************************************************************** |
|
15 | #***************************************************************************** | |
|
16 | from __future__ import print_function | |||
16 |
|
17 | |||
17 | __all__ = ['Inspector','InspectColors'] |
|
18 | __all__ = ['Inspector','InspectColors'] | |
18 |
|
19 | |||
@@ -335,11 +336,11 b' class Inspector:' | |||||
335 |
|
336 | |||
336 | def noinfo(self, msg, oname): |
|
337 | def noinfo(self, msg, oname): | |
337 | """Generic message when no information is found.""" |
|
338 | """Generic message when no information is found.""" | |
338 |
print |
|
339 | print('No %s found' % msg, end=' ') | |
339 | if oname: |
|
340 | if oname: | |
340 |
print |
|
341 | print('for %s' % oname) | |
341 | else: |
|
342 | else: | |
342 |
|
343 | print() | ||
343 |
|
344 | |||
344 | def pdef(self, obj, oname=''): |
|
345 | def pdef(self, obj, oname=''): | |
345 | """Print the definition header for any callable object. |
|
346 | """Print the definition header for any callable object. | |
@@ -347,7 +348,7 b' class Inspector:' | |||||
347 | If the object is a class, print the constructor information.""" |
|
348 | If the object is a class, print the constructor information.""" | |
348 |
|
349 | |||
349 | if not callable(obj): |
|
350 | if not callable(obj): | |
350 |
print |
|
351 | print('Object is not callable.') | |
351 | return |
|
352 | return | |
352 |
|
353 | |||
353 | header = '' |
|
354 | header = '' | |
@@ -362,7 +363,7 b' class Inspector:' | |||||
362 | if output is None: |
|
363 | if output is None: | |
363 | self.noinfo('definition header',oname) |
|
364 | self.noinfo('definition header',oname) | |
364 | else: |
|
365 | else: | |
365 |
print |
|
366 | print(header,self.format(output), end=' ', file=io.stdout) | |
366 |
|
367 | |||
367 | # In Python 3, all classes are new-style, so they all have __init__. |
|
368 | # In Python 3, all classes are new-style, so they all have __init__. | |
368 | @skip_doctest_py3 |
|
369 | @skip_doctest_py3 | |
@@ -449,9 +450,9 b' class Inspector:' | |||||
449 | # is defined, as long as the file isn't binary and is actually on the |
|
450 | # is defined, as long as the file isn't binary and is actually on the | |
450 | # filesystem. |
|
451 | # filesystem. | |
451 | if ofile.endswith(('.so', '.dll', '.pyd')): |
|
452 | if ofile.endswith(('.so', '.dll', '.pyd')): | |
452 |
print |
|
453 | print('File %r is binary, not printing.' % ofile) | |
453 | elif not os.path.isfile(ofile): |
|
454 | elif not os.path.isfile(ofile): | |
454 |
print |
|
455 | print('File %r does not exist, not printing.' % ofile) | |
455 | else: |
|
456 | else: | |
456 | # Print only text files, not extension binaries. Note that |
|
457 | # Print only text files, not extension binaries. Note that | |
457 | # getsourcelines returns lineno with 1-offset and page() uses |
|
458 | # getsourcelines returns lineno with 1-offset and page() uses |
@@ -25,6 +25,7 b' rid of that dependency, we could move it there.' | |||||
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
26 | # Imports |
|
26 | # Imports | |
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
|
28 | from __future__ import print_function | |||
28 |
|
29 | |||
29 | import os |
|
30 | import os | |
30 | import re |
|
31 | import re | |
@@ -57,18 +58,18 b' def page_dumb(strng, start=0, screen_lines=25):' | |||||
57 | out_ln = strng.splitlines()[start:] |
|
58 | out_ln = strng.splitlines()[start:] | |
58 | screens = chop(out_ln,screen_lines-1) |
|
59 | screens = chop(out_ln,screen_lines-1) | |
59 | if len(screens) == 1: |
|
60 | if len(screens) == 1: | |
60 |
print |
|
61 | print(os.linesep.join(screens[0]), file=io.stdout) | |
61 | else: |
|
62 | else: | |
62 | last_escape = "" |
|
63 | last_escape = "" | |
63 | for scr in screens[0:-1]: |
|
64 | for scr in screens[0:-1]: | |
64 | hunk = os.linesep.join(scr) |
|
65 | hunk = os.linesep.join(scr) | |
65 |
print |
|
66 | print(last_escape + hunk, file=io.stdout) | |
66 | if not page_more(): |
|
67 | if not page_more(): | |
67 | return |
|
68 | return | |
68 | esc_list = esc_re.findall(hunk) |
|
69 | esc_list = esc_re.findall(hunk) | |
69 | if len(esc_list) > 0: |
|
70 | if len(esc_list) > 0: | |
70 | last_escape = esc_list[-1] |
|
71 | last_escape = esc_list[-1] | |
71 |
print |
|
72 | print(last_escape + os.linesep.join(screens[-1]), file=io.stdout) | |
72 |
|
73 | |||
73 | def _detect_screen_size(use_curses, screen_lines_def): |
|
74 | def _detect_screen_size(use_curses, screen_lines_def): | |
74 | """Attempt to work out the number of lines on the screen. |
|
75 | """Attempt to work out the number of lines on the screen. | |
@@ -163,7 +164,7 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||||
163 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs |
|
164 | # Ugly kludge, but calling curses.initscr() flat out crashes in emacs | |
164 | TERM = os.environ.get('TERM','dumb') |
|
165 | TERM = os.environ.get('TERM','dumb') | |
165 | if TERM in ['dumb','emacs'] and os.name != 'nt': |
|
166 | if TERM in ['dumb','emacs'] and os.name != 'nt': | |
166 |
print |
|
167 | print(strng) | |
167 | return |
|
168 | return | |
168 | # chop off the topmost part of the string we don't want to see |
|
169 | # chop off the topmost part of the string we don't want to see | |
169 | str_lines = strng.splitlines()[start:] |
|
170 | str_lines = strng.splitlines()[start:] | |
@@ -183,13 +184,13 b' def page(strng, start=0, screen_lines=0, pager_cmd=None):' | |||||
183 | try: |
|
184 | try: | |
184 | screen_lines += _detect_screen_size(use_curses, screen_lines_def) |
|
185 | screen_lines += _detect_screen_size(use_curses, screen_lines_def) | |
185 | except (TypeError, UnsupportedOperation): |
|
186 | except (TypeError, UnsupportedOperation): | |
186 |
print |
|
187 | print(str_toprint, file=io.stdout) | |
187 | return |
|
188 | return | |
188 |
|
189 | |||
189 | #print 'numlines',numlines,'screenlines',screen_lines # dbg |
|
190 | #print 'numlines',numlines,'screenlines',screen_lines # dbg | |
190 | if numlines <= screen_lines : |
|
191 | if numlines <= screen_lines : | |
191 | #print '*** normal print' # dbg |
|
192 | #print '*** normal print' # dbg | |
192 |
print |
|
193 | print(str_toprint, file=io.stdout) | |
193 | else: |
|
194 | else: | |
194 | # Try to open pager and default to internal one if that fails. |
|
195 | # Try to open pager and default to internal one if that fails. | |
195 | # All failure modes are tagged as 'retval=1', to match the return |
|
196 | # All failure modes are tagged as 'retval=1', to match the return | |
@@ -250,7 +251,7 b' def page_file(fname, start=0, pager_cmd=None):' | |||||
250 | start -= 1 |
|
251 | start -= 1 | |
251 | page(open(fname).read(),start) |
|
252 | page(open(fname).read(),start) | |
252 | except: |
|
253 | except: | |
253 |
print |
|
254 | print('Unable to show file',repr(fname)) | |
254 |
|
255 | |||
255 |
|
256 | |||
256 | def get_pager_cmd(pager_cmd=None): |
|
257 | def get_pager_cmd(pager_cmd=None): | |
@@ -325,13 +326,13 b" def snip_print(str,width = 75,print_full = 0,header = ''):" | |||||
325 | page(header+str) |
|
326 | page(header+str) | |
326 | return 0 |
|
327 | return 0 | |
327 |
|
328 | |||
328 |
print |
|
329 | print(header, end=' ') | |
329 | if len(str) < width: |
|
330 | if len(str) < width: | |
330 |
print |
|
331 | print(str) | |
331 | snip = 0 |
|
332 | snip = 0 | |
332 | else: |
|
333 | else: | |
333 | whalf = int((width -5)/2) |
|
334 | whalf = int((width -5)/2) | |
334 |
print |
|
335 | print(str[:whalf] + ' <...> ' + str[-whalf:]) | |
335 | snip = 1 |
|
336 | snip = 1 | |
336 | if snip and print_full == 2: |
|
337 | if snip and print_full == 2: | |
337 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
|
338 | if raw_input(header+' Snipped. View (y/n)? [N]').lower() == 'y': |
@@ -87,6 +87,7 b' Some of the known remaining caveats are:' | |||||
87 |
|
87 | |||
88 | - C extension modules cannot be reloaded, and so cannot be autoreloaded. |
|
88 | - C extension modules cannot be reloaded, and so cannot be autoreloaded. | |
89 | """ |
|
89 | """ | |
|
90 | from __future__ import print_function | |||
90 |
|
91 | |||
91 | skip_doctest = True |
|
92 | skip_doctest = True | |
92 |
|
93 | |||
@@ -244,8 +245,8 b' class ModuleReloader(object):' | |||||
244 | if py_filename in self.failed: |
|
245 | if py_filename in self.failed: | |
245 | del self.failed[py_filename] |
|
246 | del self.failed[py_filename] | |
246 | except: |
|
247 | except: | |
247 |
print |
|
248 | print("[autoreload of %s failed: %s]" % ( | |
248 | modname, traceback.format_exc(1)) |
|
249 | modname, traceback.format_exc(1)), file=sys.stderr) | |
249 | self.failed[py_filename] = pymtime |
|
250 | self.failed[py_filename] = pymtime | |
250 |
|
251 | |||
251 | #------------------------------------------------------------------------------ |
|
252 | #------------------------------------------------------------------------------ |
@@ -13,6 +13,7 b'' | |||||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
|
16 | from __future__ import print_function | |||
16 |
|
17 | |||
17 | import bdb |
|
18 | import bdb | |
18 | import os |
|
19 | import os | |
@@ -59,8 +60,8 b' def get_default_editor():' | |||||
59 | def get_pasted_lines(sentinel, l_input=py3compat.input): |
|
60 | def get_pasted_lines(sentinel, l_input=py3compat.input): | |
60 | """ Yield pasted lines until the user enters the given sentinel value. |
|
61 | """ Yield pasted lines until the user enters the given sentinel value. | |
61 | """ |
|
62 | """ | |
62 |
print |
|
63 | print("Pasting code; enter '%s' alone on the line to stop or use Ctrl-D." \ | |
63 | % sentinel |
|
64 | % sentinel) | |
64 | while True: |
|
65 | while True: | |
65 | try: |
|
66 | try: | |
66 | l = l_input(':') |
|
67 | l = l_input(':') | |
@@ -69,7 +70,7 b' def get_pasted_lines(sentinel, l_input=py3compat.input):' | |||||
69 | else: |
|
70 | else: | |
70 | yield l |
|
71 | yield l | |
71 | except EOFError: |
|
72 | except EOFError: | |
72 |
print |
|
73 | print('<EOF>') | |
73 | return |
|
74 | return | |
74 |
|
75 | |||
75 |
|
76 | |||
@@ -153,7 +154,7 b' class TerminalMagics(Magics):' | |||||
153 | if name: |
|
154 | if name: | |
154 | # If storing it for further editing |
|
155 | # If storing it for further editing | |
155 | self.shell.user_ns[name] = SList(b.splitlines()) |
|
156 | self.shell.user_ns[name] = SList(b.splitlines()) | |
156 |
print |
|
157 | print("Block assigned to '%s'" % name) | |
157 | else: |
|
158 | else: | |
158 | self.shell.user_ns['pasted_block'] = b |
|
159 | self.shell.user_ns['pasted_block'] = b | |
159 | self.shell.run_cell(b) |
|
160 | self.shell.run_cell(b) | |
@@ -170,7 +171,7 b' class TerminalMagics(Magics):' | |||||
170 | raise UsageError( |
|
171 | raise UsageError( | |
171 | "Variable 'pasted_block' is not a string, can't execute") |
|
172 | "Variable 'pasted_block' is not a string, can't execute") | |
172 |
|
173 | |||
173 |
print |
|
174 | print("Re-executing '%s...' (%d chars)"% (b.split('\n',1)[0], len(b))) | |
174 | self.shell.run_cell(b) |
|
175 | self.shell.run_cell(b) | |
175 |
|
176 | |||
176 | @line_magic |
|
177 | @line_magic | |
@@ -178,7 +179,7 b' class TerminalMagics(Magics):' | |||||
178 | """Toggle autoindent on/off (if available).""" |
|
179 | """Toggle autoindent on/off (if available).""" | |
179 |
|
180 | |||
180 | self.shell.set_autoindent() |
|
181 | self.shell.set_autoindent() | |
181 |
print |
|
182 | print("Automatic indentation is:",['OFF','ON'][self.shell.autoindent]) | |
182 |
|
183 | |||
183 | @skip_doctest |
|
184 | @skip_doctest | |
184 | @line_magic |
|
185 | @line_magic |
@@ -168,6 +168,7 b" print 'bye!'" | |||||
168 | # the file COPYING, distributed as part of this software. |
|
168 | # the file COPYING, distributed as part of this software. | |
169 | # |
|
169 | # | |
170 | #***************************************************************************** |
|
170 | #***************************************************************************** | |
|
171 | from __future__ import print_function | |||
171 |
|
172 | |||
172 | import os |
|
173 | import os | |
173 | import re |
|
174 | import re | |
@@ -318,7 +319,7 b' class Demo(object):' | |||||
318 |
|
319 | |||
319 | if index is None: |
|
320 | if index is None: | |
320 | if self.finished: |
|
321 | if self.finished: | |
321 |
print |
|
322 | print('Demo finished. Use <demo_name>.reset() if you want to rerun it.', file=io.stdout) | |
322 | return None |
|
323 | return None | |
323 | index = self.block_index |
|
324 | index = self.block_index | |
324 | else: |
|
325 | else: | |
@@ -387,9 +388,9 b' class Demo(object):' | |||||
387 | if index is None: |
|
388 | if index is None: | |
388 | return |
|
389 | return | |
389 |
|
390 | |||
390 |
print |
|
391 | print(self.marquee('<%s> block # %s (%s remaining)' % | |
391 | (self.title,index,self.nblocks-index-1)) |
|
392 | (self.title,index,self.nblocks-index-1)), file=io.stdout) | |
392 |
print |
|
393 | print((self.src_blocks_colored[index]), file=io.stdout) | |
393 | sys.stdout.flush() |
|
394 | sys.stdout.flush() | |
394 |
|
395 | |||
395 | def show_all(self): |
|
396 | def show_all(self): | |
@@ -402,12 +403,12 b' class Demo(object):' | |||||
402 | marquee = self.marquee |
|
403 | marquee = self.marquee | |
403 | for index,block in enumerate(self.src_blocks_colored): |
|
404 | for index,block in enumerate(self.src_blocks_colored): | |
404 | if silent[index]: |
|
405 | if silent[index]: | |
405 |
print |
|
406 | print(marquee('<%s> SILENT block # %s (%s remaining)' % | |
406 | (title,index,nblocks-index-1)) |
|
407 | (title,index,nblocks-index-1)), file=io.stdout) | |
407 | else: |
|
408 | else: | |
408 |
print |
|
409 | print(marquee('<%s> block # %s (%s remaining)' % | |
409 | (title,index,nblocks-index-1)) |
|
410 | (title,index,nblocks-index-1)), file=io.stdout) | |
410 |
print |
|
411 | print(block, end=' ', file=io.stdout) | |
411 | sys.stdout.flush() |
|
412 | sys.stdout.flush() | |
412 |
|
413 | |||
413 | def run_cell(self,source): |
|
414 | def run_cell(self,source): | |
@@ -432,18 +433,18 b' class Demo(object):' | |||||
432 | next_block = self.src_blocks[index] |
|
433 | next_block = self.src_blocks[index] | |
433 | self.block_index += 1 |
|
434 | self.block_index += 1 | |
434 | if self._silent[index]: |
|
435 | if self._silent[index]: | |
435 |
print |
|
436 | print(marquee('Executing silent block # %s (%s remaining)' % | |
436 | (index,self.nblocks-index-1)) |
|
437 | (index,self.nblocks-index-1)), file=io.stdout) | |
437 | else: |
|
438 | else: | |
438 | self.pre_cmd() |
|
439 | self.pre_cmd() | |
439 | self.show(index) |
|
440 | self.show(index) | |
440 | if self.auto_all or self._auto[index]: |
|
441 | if self.auto_all or self._auto[index]: | |
441 |
print |
|
442 | print(marquee('output:'), file=io.stdout) | |
442 | else: |
|
443 | else: | |
443 |
print |
|
444 | print(marquee('Press <q> to quit, <Enter> to execute...'), end=' ', file=io.stdout) | |
444 | ans = raw_input().strip() |
|
445 | ans = raw_input().strip() | |
445 | if ans: |
|
446 | if ans: | |
446 |
print |
|
447 | print(marquee('Block NOT executed'), file=io.stdout) | |
447 | return |
|
448 | return | |
448 | try: |
|
449 | try: | |
449 | save_argv = sys.argv |
|
450 | save_argv = sys.argv | |
@@ -462,9 +463,9 b' class Demo(object):' | |||||
462 | mq1 = self.marquee('END OF DEMO') |
|
463 | mq1 = self.marquee('END OF DEMO') | |
463 | if mq1: |
|
464 | if mq1: | |
464 | # avoid spurious print >>io.stdout,s if empty marquees are used |
|
465 | # avoid spurious print >>io.stdout,s if empty marquees are used | |
465 |
print |
|
466 | print(file=io.stdout) | |
466 |
print |
|
467 | print(mq1, file=io.stdout) | |
467 |
print |
|
468 | print(self.marquee('Use <demo_name>.reset() if you want to rerun it.'), file=io.stdout) | |
468 | self.finished = True |
|
469 | self.finished = True | |
469 |
|
470 | |||
470 | # These methods are meant to be overridden by subclasses who may wish to |
|
471 | # These methods are meant to be overridden by subclasses who may wish to |
@@ -29,6 +29,7 b' NOTES:' | |||||
29 | - Because pexpect only works under Unix or Windows-Cygwin, this has the same |
|
29 | - Because pexpect only works under Unix or Windows-Cygwin, this has the same | |
30 | limitations. This means that it will NOT work under native windows Python. |
|
30 | limitations. This means that it will NOT work under native windows Python. | |
31 | """ |
|
31 | """ | |
|
32 | from __future__ import print_function | |||
32 |
|
33 | |||
33 | # Stdlib imports |
|
34 | # Stdlib imports | |
34 | import optparse |
|
35 | import optparse | |
@@ -248,7 +249,7 b' class InteractiveRunner(object):' | |||||
248 | if end_normal: |
|
249 | if end_normal: | |
249 | if interact: |
|
250 | if interact: | |
250 | c.send('\n') |
|
251 | c.send('\n') | |
251 |
print |
|
252 | print('<< Starting interactive mode >>', end=' ') | |
252 | try: |
|
253 | try: | |
253 | c.interact() |
|
254 | c.interact() | |
254 | except OSError: |
|
255 | except OSError: | |
@@ -261,7 +262,7 b' class InteractiveRunner(object):' | |||||
261 | else: |
|
262 | else: | |
262 | if interact: |
|
263 | if interact: | |
263 | e="Further interaction is not possible: child process is dead." |
|
264 | e="Further interaction is not possible: child process is dead." | |
264 |
print |
|
265 | print(e, file=sys.stderr) | |
265 |
|
266 | |||
266 | # Leave the child ready for more input later on, otherwise select just |
|
267 | # Leave the child ready for more input later on, otherwise select just | |
267 | # hangs on the second invocation. |
|
268 | # hangs on the second invocation. | |
@@ -283,7 +284,7 b' class InteractiveRunner(object):' | |||||
283 | opts,args = parser.parse_args(argv) |
|
284 | opts,args = parser.parse_args(argv) | |
284 |
|
285 | |||
285 | if len(args) != 1: |
|
286 | if len(args) != 1: | |
286 |
print |
|
287 | print("You must supply exactly one file to run.", file=sys.stderr) | |
287 | sys.exit(1) |
|
288 | sys.exit(1) | |
288 |
|
289 | |||
289 | self.run_file(args[0],opts.interact) |
|
290 | self.run_file(args[0],opts.interact) |
@@ -2,6 +2,7 b'' | |||||
2 |
|
2 | |||
3 | Not the most elegant or fine-grained, but it does cover at least the bulk |
|
3 | Not the most elegant or fine-grained, but it does cover at least the bulk | |
4 | functionality.""" |
|
4 | functionality.""" | |
|
5 | from __future__ import print_function | |||
5 |
|
6 | |||
6 | # Global to make tests extra verbose and help debugging |
|
7 | # Global to make tests extra verbose and help debugging | |
7 | VERBOSE = True |
|
8 | VERBOSE = True | |
@@ -50,10 +51,10 b' class RunnerTestCase(unittest.TestCase):' | |||||
50 | if ol1 != ol2: |
|
51 | if ol1 != ol2: | |
51 | mismatch += 1 |
|
52 | mismatch += 1 | |
52 | if VERBOSE: |
|
53 | if VERBOSE: | |
53 |
print |
|
54 | print('<<< line %s does not match:' % n) | |
54 |
print |
|
55 | print(repr(ol1)) | |
55 |
print |
|
56 | print(repr(ol2)) | |
56 |
print |
|
57 | print('>>>') | |
57 | self.assert_(mismatch==0,'Number of mismatched lines: %s' % |
|
58 | self.assert_(mismatch==0,'Number of mismatched lines: %s' % | |
58 | mismatch) |
|
59 | mismatch) | |
59 |
|
60 |
@@ -1,6 +1,7 b'' | |||||
1 | """Test suite for pylab_import_all magic |
|
1 | """Test suite for pylab_import_all magic | |
2 | Modified from the irunner module but using regex. |
|
2 | Modified from the irunner module but using regex. | |
3 | """ |
|
3 | """ | |
|
4 | from __future__ import print_function | |||
4 |
|
5 | |||
5 | # Global to make tests extra verbose and help debugging |
|
6 | # Global to make tests extra verbose and help debugging | |
6 | VERBOSE = True |
|
7 | VERBOSE = True | |
@@ -58,10 +59,10 b' class RunnerTestCase(unittest.TestCase):' | |||||
58 | if not re.match(ol1,ol2): |
|
59 | if not re.match(ol1,ol2): | |
59 | mismatch += 1 |
|
60 | mismatch += 1 | |
60 | if VERBOSE: |
|
61 | if VERBOSE: | |
61 |
print |
|
62 | print('<<< line %s does not match:' % n) | |
62 |
print |
|
63 | print(repr(ol1)) | |
63 |
print |
|
64 | print(repr(ol2)) | |
64 |
print |
|
65 | print('>>>') | |
65 | self.assert_(mismatch==0,'Number of mismatched lines: %s' % |
|
66 | self.assert_(mismatch==0,'Number of mismatched lines: %s' % | |
66 | mismatch) |
|
67 | mismatch) | |
67 |
|
68 |
@@ -11,6 +11,7 b' Authors:' | |||||
11 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
12 | # the file COPYING, distributed as part of this software. |
|
12 | # the file COPYING, distributed as part of this software. | |
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
|
14 | from __future__ import print_function | |||
14 |
|
15 | |||
15 | import sys |
|
16 | import sys | |
16 | import tempfile |
|
17 | import tempfile | |
@@ -70,13 +71,13 b' def generate_output():' | |||||
70 | import sys |
|
71 | import sys | |
71 | from IPython.core.display import display, HTML, Math |
|
72 | from IPython.core.display import display, HTML, Math | |
72 |
|
73 | |||
73 |
print |
|
74 | print("stdout") | |
74 | print >> sys.stderr, "stderr" |
|
75 | print("stderr", file=sys.stderr) | |
75 |
|
76 | |||
76 | display(HTML("<b>HTML</b>")) |
|
77 | display(HTML("<b>HTML</b>")) | |
77 |
|
78 | |||
78 |
print |
|
79 | print("stdout2") | |
79 | print >> sys.stderr, "stderr2" |
|
80 | print("stderr2", file=sys.stderr) | |
80 |
|
81 | |||
81 | display(Math(r"\alpha=\beta")) |
|
82 | display(Math(r"\alpha=\beta")) | |
82 |
|
83 | |||
@@ -154,7 +155,7 b' class ClusterTestCase(BaseZMQTestCase):' | |||||
154 | time.sleep(0.1) |
|
155 | time.sleep(0.1) | |
155 | self.client.spin() |
|
156 | self.client.spin() | |
156 | if not f(): |
|
157 | if not f(): | |
157 |
print |
|
158 | print("Warning: Awaited condition never arrived") | |
158 |
|
159 | |||
159 | def setUp(self): |
|
160 | def setUp(self): | |
160 | BaseZMQTestCase.setUp(self) |
|
161 | BaseZMQTestCase.setUp(self) | |
@@ -180,4 +181,4 b' class ClusterTestCase(BaseZMQTestCase):' | |||||
180 | # self.context.term() |
|
181 | # self.context.term() | |
181 | # print tempfile.TemporaryFile().fileno(), |
|
182 | # print tempfile.TemporaryFile().fileno(), | |
182 | # sys.stdout.flush() |
|
183 | # sys.stdout.flush() | |
183 | No newline at end of file |
|
184 |
@@ -24,6 +24,7 b' itself from the command line. There are two ways of running this script:' | |||||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 | # Imports |
|
25 | # Imports | |
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
|
27 | from __future__ import print_function | |||
27 |
|
28 | |||
28 | # Stdlib |
|
29 | # Stdlib | |
29 | import glob |
|
30 | import glob | |
@@ -423,7 +424,7 b' class IPTester(object):' | |||||
423 |
|
424 | |||
424 | for pid in self.pids: |
|
425 | for pid in self.pids: | |
425 | try: |
|
426 | try: | |
426 |
print |
|
427 | print('Cleaning stale PID:', pid) | |
427 | os.kill(pid, signal.SIGKILL) |
|
428 | os.kill(pid, signal.SIGKILL) | |
428 | except OSError: |
|
429 | except OSError: | |
429 | # This is just a best effort, if we fail or the process was |
|
430 | # This is just a best effort, if we fail or the process was | |
@@ -527,8 +528,8 b' def run_iptestall():' | |||||
527 | t_start = time.time() |
|
528 | t_start = time.time() | |
528 | try: |
|
529 | try: | |
529 | for (name, runner) in runners: |
|
530 | for (name, runner) in runners: | |
530 |
print |
|
531 | print('*'*70) | |
531 |
print |
|
532 | print('IPython test group:',name) | |
532 | res = runner.run() |
|
533 | res = runner.run() | |
533 | if res: |
|
534 | if res: | |
534 | failed.append( (name, runner) ) |
|
535 | failed.append( (name, runner) ) | |
@@ -539,26 +540,26 b' def run_iptestall():' | |||||
539 | nrunners = len(runners) |
|
540 | nrunners = len(runners) | |
540 | nfail = len(failed) |
|
541 | nfail = len(failed) | |
541 | # summarize results |
|
542 | # summarize results | |
542 |
|
543 | print() | ||
543 |
print |
|
544 | print('*'*70) | |
544 |
print |
|
545 | print('Test suite completed for system with the following information:') | |
545 |
print |
|
546 | print(report()) | |
546 |
print |
|
547 | print('Ran %s test groups in %.3fs' % (nrunners, t_tests)) | |
547 |
|
548 | print() | ||
548 |
print |
|
549 | print('Status:') | |
549 | if not failed: |
|
550 | if not failed: | |
550 |
print |
|
551 | print('OK') | |
551 | else: |
|
552 | else: | |
552 | # If anything went wrong, point out what command to rerun manually to |
|
553 | # If anything went wrong, point out what command to rerun manually to | |
553 | # see the actual errors and individual summary |
|
554 | # see the actual errors and individual summary | |
554 |
print |
|
555 | print('ERROR - %s out of %s test groups failed.' % (nfail, nrunners)) | |
555 | for name, failed_runner in failed: |
|
556 | for name, failed_runner in failed: | |
556 |
print |
|
557 | print('-'*40) | |
557 |
print |
|
558 | print('Runner failed:',name) | |
558 |
print |
|
559 | print('You may wish to rerun this one individually, with:') | |
559 | failed_call_args = [py3compat.cast_unicode(x) for x in failed_runner.call_args] |
|
560 | failed_call_args = [py3compat.cast_unicode(x) for x in failed_runner.call_args] | |
560 |
print |
|
561 | print(u' '.join(failed_call_args)) | |
561 |
|
562 | print() | ||
562 | # Ensure that our exit code indicates failure |
|
563 | # Ensure that our exit code indicates failure | |
563 | sys.exit(1) |
|
564 | sys.exit(1) | |
564 |
|
565 |
@@ -28,11 +28,13 b' It shows how to use the built-in keyword, token and tokenize modules to' | |||||
28 | scan Python source code and re-emit it with no changes to its original |
|
28 | scan Python source code and re-emit it with no changes to its original | |
29 | formatting (which is the hard part). |
|
29 | formatting (which is the hard part). | |
30 | """ |
|
30 | """ | |
|
31 | from __future__ import print_function | |||
31 |
|
32 | |||
32 | __all__ = ['ANSICodeColors','Parser'] |
|
33 | __all__ = ['ANSICodeColors','Parser'] | |
33 |
|
34 | |||
34 | _scheme_default = 'Linux' |
|
35 | _scheme_default = 'Linux' | |
35 |
|
36 | |||
|
37 | ||||
36 | # Imports |
|
38 | # Imports | |
37 | import StringIO |
|
39 | import StringIO | |
38 | import keyword |
|
40 | import keyword | |
@@ -283,7 +285,7 b' If no filename is given, or if filename is -, read standard input."""' | |||||
283 | try: |
|
285 | try: | |
284 | stream = open(fname) |
|
286 | stream = open(fname) | |
285 | except IOError as msg: |
|
287 | except IOError as msg: | |
286 |
print |
|
288 | print(msg, file=sys.stderr) | |
287 | sys.exit(1) |
|
289 | sys.exit(1) | |
288 |
|
290 | |||
289 | parser = Parser() |
|
291 | parser = Parser() |
@@ -11,6 +11,7 b'' | |||||
11 | #----------------------------------------------------------------------------- |
|
11 | #----------------------------------------------------------------------------- | |
12 | # Imports |
|
12 | # Imports | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | from __future__ import print_function | |||
14 |
|
15 | |||
15 | import sys |
|
16 | import sys | |
16 |
|
17 | |||
@@ -33,7 +34,7 b' def test_tee_simple():' | |||||
33 | chan = StringIO() |
|
34 | chan = StringIO() | |
34 | text = 'Hello' |
|
35 | text = 'Hello' | |
35 | tee = Tee(chan, channel='stdout') |
|
36 | tee = Tee(chan, channel='stdout') | |
36 | print >> chan, text |
|
37 | print(text, file=chan) | |
37 | nt.assert_equal(chan.getvalue(), text+"\n") |
|
38 | nt.assert_equal(chan.getvalue(), text+"\n") | |
38 |
|
39 | |||
39 |
|
40 | |||
@@ -48,7 +49,7 b' class TeeTestCase(dec.ParametricTestCase):' | |||||
48 | setattr(sys, channel, trap) |
|
49 | setattr(sys, channel, trap) | |
49 |
|
50 | |||
50 | tee = Tee(chan, channel=channel) |
|
51 | tee = Tee(chan, channel=channel) | |
51 | print >> chan, text, |
|
52 | print(text, end='', file=chan) | |
52 | setattr(sys, channel, std_ori) |
|
53 | setattr(sys, channel, std_ori) | |
53 | trap_val = trap.getvalue() |
|
54 | trap_val = trap.getvalue() | |
54 | nt.assert_equals(chan.getvalue(), text) |
|
55 | nt.assert_equals(chan.getvalue(), text) | |
@@ -78,8 +79,8 b' def test_capture_output():' | |||||
78 | """capture_output() context works""" |
|
79 | """capture_output() context works""" | |
79 |
|
80 | |||
80 | with capture_output() as io: |
|
81 | with capture_output() as io: | |
81 |
print |
|
82 | print('hi, stdout') | |
82 | print >> sys.stderr, 'hi, stderr' |
|
83 | print('hi, stderr', file=sys.stderr) | |
83 |
|
84 | |||
84 | nt.assert_equals(io.stdout, 'hi, stdout\n') |
|
85 | nt.assert_equals(io.stdout, 'hi, stdout\n') | |
85 | nt.assert_equals(io.stderr, 'hi, stderr\n') |
|
86 | nt.assert_equals(io.stderr, 'hi, stderr\n') |
@@ -13,6 +13,7 b" Utilities for warnings. Shoudn't we just use the built in warnings module." | |||||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
|
16 | from __future__ import print_function | |||
16 |
|
17 | |||
17 | import sys |
|
18 | import sys | |
18 |
|
19 | |||
@@ -43,7 +44,7 b' def warn(msg,level=2,exit_val=1):' | |||||
43 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] |
|
44 | header = ['','','WARNING: ','ERROR: ','FATAL ERROR: '] | |
44 | io.stderr.write('%s%s' % (header[level],msg)) |
|
45 | io.stderr.write('%s%s' % (header[level],msg)) | |
45 | if level == 4: |
|
46 | if level == 4: | |
46 |
print |
|
47 | print('Exiting.\n', file=io.stderr) | |
47 | sys.exit(exit_val) |
|
48 | sys.exit(exit_val) | |
48 |
|
49 | |||
49 |
|
50 |
@@ -5,6 +5,8 b'' | |||||
5 | #----------------------------------------------------------------------------- |
|
5 | #----------------------------------------------------------------------------- | |
6 | # Imports |
|
6 | # Imports | |
7 | #----------------------------------------------------------------------------- |
|
7 | #----------------------------------------------------------------------------- | |
|
8 | from __future__ import print_function | |||
|
9 | ||||
8 | # stdlib |
|
10 | # stdlib | |
9 | import cPickle as pickle |
|
11 | import cPickle as pickle | |
10 | import code |
|
12 | import code | |
@@ -57,25 +59,25 b' class Console(code.InteractiveConsole):' | |||||
57 | return |
|
59 | return | |
58 | c = omsg.content.code.rstrip() |
|
60 | c = omsg.content.code.rstrip() | |
59 | if c: |
|
61 | if c: | |
60 |
print |
|
62 | print('[IN from %s]' % omsg.parent_header.username) | |
61 |
print |
|
63 | print(c) | |
62 |
|
64 | |||
63 | def handle_pyout(self, omsg): |
|
65 | def handle_pyout(self, omsg): | |
64 | #print omsg # dbg |
|
66 | #print omsg # dbg | |
65 | if omsg.parent_header.session == self.session.session: |
|
67 | if omsg.parent_header.session == self.session.session: | |
66 |
print |
|
68 | print("%s%s" % (sys.ps3, omsg.content.data)) | |
67 | else: |
|
69 | else: | |
68 |
print |
|
70 | print('[Out from %s]' % omsg.parent_header.username) | |
69 |
print |
|
71 | print(omsg.content.data) | |
70 |
|
72 | |||
71 | def print_pyerr(self, err): |
|
73 | def print_pyerr(self, err): | |
72 |
print |
|
74 | print(err.etype,':', err.evalue, file=sys.stderr) | |
73 |
print |
|
75 | print(''.join(err.traceback), file=sys.stderr) | |
74 |
|
76 | |||
75 | def handle_pyerr(self, omsg): |
|
77 | def handle_pyerr(self, omsg): | |
76 | if omsg.parent_header.session == self.session.session: |
|
78 | if omsg.parent_header.session == self.session.session: | |
77 | return |
|
79 | return | |
78 |
print |
|
80 | print('[ERR from %s]' % omsg.parent_header.username, file=sys.stderr) | |
79 | self.print_pyerr(omsg.content) |
|
81 | self.print_pyerr(omsg.content) | |
80 |
|
82 | |||
81 | def handle_stream(self, omsg): |
|
83 | def handle_stream(self, omsg): | |
@@ -83,8 +85,8 b' class Console(code.InteractiveConsole):' | |||||
83 | outstream = sys.stdout |
|
85 | outstream = sys.stdout | |
84 | else: |
|
86 | else: | |
85 | outstream = sys.stderr |
|
87 | outstream = sys.stderr | |
86 |
print |
|
88 | print('*ERR*', end=' ', file=outstream) | |
87 |
print |
|
89 | print(omsg.content.data, end=' ', file=outstream) | |
88 |
|
90 | |||
89 | def handle_output(self, omsg): |
|
91 | def handle_output(self, omsg): | |
90 | handler = self.handlers.get(omsg.msg_type, None) |
|
92 | handler = self.handlers.get(omsg.msg_type, None) | |
@@ -107,12 +109,12 b' class Console(code.InteractiveConsole):' | |||||
107 | if rep.content.status == 'error': |
|
109 | if rep.content.status == 'error': | |
108 | self.print_pyerr(rep.content) |
|
110 | self.print_pyerr(rep.content) | |
109 | elif rep.content.status == 'aborted': |
|
111 | elif rep.content.status == 'aborted': | |
110 |
print |
|
112 | print("ERROR: ABORTED", file=sys.stderr) | |
111 | ab = self.messages[rep.parent_header.msg_id].content |
|
113 | ab = self.messages[rep.parent_header.msg_id].content | |
112 | if 'code' in ab: |
|
114 | if 'code' in ab: | |
113 |
print |
|
115 | print(ab.code, file=sys.stderr) | |
114 | else: |
|
116 | else: | |
115 |
print |
|
117 | print(ab, file=sys.stderr) | |
116 |
|
118 | |||
117 | def recv_reply(self): |
|
119 | def recv_reply(self): | |
118 | ident,rep = self.session.recv(self.request_socket) |
|
120 | ident,rep = self.session.recv(self.request_socket) | |
@@ -153,7 +155,7 b' class Console(code.InteractiveConsole):' | |||||
153 | time.sleep(0.05) |
|
155 | time.sleep(0.05) | |
154 | else: |
|
156 | else: | |
155 | # We exited without hearing back from the kernel! |
|
157 | # We exited without hearing back from the kernel! | |
156 |
print |
|
158 | print('ERROR!!! kernel never got back to us!!!', file=sys.stderr) | |
157 |
|
159 | |||
158 |
|
160 | |||
159 | class InteractiveClient(object): |
|
161 | class InteractiveClient(object): |
@@ -6,6 +6,7 b' use from bintree_script.py' | |||||
6 | Provides parallel [all]reduce functionality |
|
6 | Provides parallel [all]reduce functionality | |
7 |
|
7 | |||
8 | """ |
|
8 | """ | |
|
9 | from __future__ import print_function | |||
9 |
|
10 | |||
10 | import cPickle as pickle |
|
11 | import cPickle as pickle | |
11 | import re |
|
12 | import re | |
@@ -92,7 +93,7 b' def depth(n, tree):' | |||||
92 | def print_bintree(tree, indent=' '): |
|
93 | def print_bintree(tree, indent=' '): | |
93 | """print a binary tree""" |
|
94 | """print a binary tree""" | |
94 | for n in sorted(tree.keys()): |
|
95 | for n in sorted(tree.keys()): | |
95 |
print |
|
96 | print("%s%s" % (indent * depth(n,tree), n)) | |
96 |
|
97 | |||
97 | #---------------------------------------------------------------------------- |
|
98 | #---------------------------------------------------------------------------- | |
98 | # Communicator class for a binary-tree map |
|
99 | # Communicator class for a binary-tree map |
General Comments 0
You need to be logged in to leave comments.
Login now