diff --git a/IPython/core/history.py b/IPython/core/history.py index 0ee5e8a..af7c916 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -453,15 +453,10 @@ def magic_history(self, parameter_s = ''): print('%s:%s' % (str(in_num).ljust(width), line_sep[multiline]), file=outfile, end='') if pyprompts: - inline = ">>> " + inline + print(">>> ", end="", file=outfile) if multiline: - lines = inline.splitlines() - print('\n... '.join(lines), file=outfile) - print('... ', file=outfile) - else: - print(inline, file=outfile) - else: - print(inline, file=outfile) + inline = "\n... ".join(inline.splitlines()) + "\n..." + print(inline, file=outfile) if print_outputs and output: print(repr(output), file=outfile) diff --git a/IPython/core/magic.py b/IPython/core/magic.py index f6005c0..a9fdfe6 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -57,7 +57,7 @@ import IPython.utils.io from IPython.utils.path import get_py_filename from IPython.utils.process import arg_split, abbrev_cwd from IPython.utils.terminal import set_term_title -from IPython.utils.text import LSString, SList, StringTypes, format_screen +from IPython.utils.text import LSString, SList, format_screen from IPython.utils.timing import clock, clock2 from IPython.utils.warn import warn, error from IPython.utils.ipstruct import Struct @@ -2284,9 +2284,10 @@ Currently the magic system has the following functions:\n""" # by default this is done with temp files, except when the given # arg is a filename - use_temp = 1 + use_temp = True - if re.match(r'\d',args): + data = '' + if args[0].isdigit(): # Mode where user specifies ranges of lines, like in %macro. # This means that you can't edit files whose names begin with # numbers this way. Tough. @@ -2294,16 +2295,15 @@ Currently the magic system has the following functions:\n""" data = '\n'.join(self.extract_input_slices(ranges,opts_r)) elif args.endswith('.py'): filename = make_filename(args) - data = '' - use_temp = 0 + use_temp = False elif args: try: # Load the parameter given as a variable. If not a string, # process it as an object instead (below) #print '*** args',args,'type',type(args) # dbg - data = eval(args,self.shell.user_ns) - if not type(data) in StringTypes: + data = eval(args, self.shell.user_ns) + if not isinstance(data, basestring): raise DataIsObject except (NameError,SyntaxError): @@ -2313,13 +2313,11 @@ Currently the magic system has the following functions:\n""" warn("Argument given (%s) can't be found as a variable " "or as a filename." % args) return - - data = '' - use_temp = 0 + use_temp = False + except DataIsObject: - # macros have a special edit function - if isinstance(data,Macro): + if isinstance(data, Macro): self._edit_macro(args,data) return @@ -2358,9 +2356,7 @@ Currently the magic system has the following functions:\n""" warn('The file `%s` where `%s` was defined cannot ' 'be read.' % (filename,data)) return - use_temp = 0 - else: - data = '' + use_temp = False if use_temp: filename = self.shell.mktempfile(data) @@ -2383,7 +2379,7 @@ Currently the magic system has the following functions:\n""" if args.strip() == 'pasted_block': self.shell.user_ns['pasted_block'] = file_read(filename) - if opts.has_key('x'): # -x prevents actual execution + if 'x' in opts: # -x prevents actual execution print else: print 'done. Executing edited code...' diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 38825d8..9ccf2de 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -19,7 +19,6 @@ import __main__ import os import re import shutil -import types from IPython.external.path import path @@ -30,8 +29,6 @@ from IPython.utils.data import flatten # Code #----------------------------------------------------------------------------- -StringTypes = types.StringTypes - def unquote_ends(istr): """Remove a single pair of quotes from the endpoints of a string.""" @@ -325,7 +322,7 @@ def qw(words,flat=0,sep=None,maxsplit=-1): ['a', 'b', '1', '2', 'm', 'n', 'p', 'q'] """ - if type(words) in StringTypes: + if isinstance(words, basestring): return [word.strip() for word in words.split(sep,maxsplit) if word and not word.isspace() ] if flat: @@ -345,7 +342,7 @@ def qw_lol(indata): We need this to make sure the modules_some keys *always* end up as a list of lists.""" - if type(indata) in StringTypes: + if isinstance(indata, basestring): return [qw(indata)] else: return qw(indata) diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index d5071c9..412077b 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -18,7 +18,6 @@ from __future__ import print_function # Stdlib import inspect import os -import re # Our own from IPython.core.interactiveshell import ( @@ -31,7 +30,6 @@ from IPython.core.macro import Macro from IPython.core.payloadpage import install_payload_page from IPython.utils import io from IPython.utils.path import get_py_filename -from IPython.utils.text import StringTypes from IPython.utils.traitlets import Instance, Type, Dict from IPython.utils.warn import warn from IPython.zmq.session import extract_header @@ -433,9 +431,10 @@ class ZMQInteractiveShell(InteractiveShell): # by default this is done with temp files, except when the given # arg is a filename - use_temp = 1 + use_temp = True - if re.match(r'\d',args): + data = '' + if args[0].isdigit(): # Mode where user specifies ranges of lines, like in %macro. # This means that you can't edit files whose names begin with # numbers this way. Tough. @@ -443,16 +442,15 @@ class ZMQInteractiveShell(InteractiveShell): data = ''.join(self.extract_input_slices(ranges,opts_r)) elif args.endswith('.py'): filename = make_filename(args) - data = '' - use_temp = 0 + use_temp = False elif args: try: # Load the parameter given as a variable. If not a string, # process it as an object instead (below) #print '*** args',args,'type',type(args) # dbg - data = eval(args,self.shell.user_ns) - if not type(data) in StringTypes: + data = eval(args, self.shell.user_ns) + if not isinstance(data, basestring): raise DataIsObject except (NameError,SyntaxError): @@ -462,13 +460,11 @@ class ZMQInteractiveShell(InteractiveShell): warn("Argument given (%s) can't be found as a variable " "or as a filename." % args) return - - data = '' - use_temp = 0 + use_temp = False + except DataIsObject: - # macros have a special edit function - if isinstance(data,Macro): + if isinstance(data, Macro): self._edit_macro(args,data) return @@ -507,9 +503,7 @@ class ZMQInteractiveShell(InteractiveShell): warn('The file `%s` where `%s` was defined cannot ' 'be read.' % (filename,data)) return - use_temp = 0 - else: - data = '' + use_temp = False if use_temp: filename = self.shell.mktempfile(data)