Permalink
Browse files

Use %r to obtain repr in string formatting.

  • Loading branch information...
1 parent a0a199f commit 5e451b6f8b2212d96a101fd1de6a63f00873be9f @takluyver committed Nov 20, 2011
Showing with 17 additions and 20 deletions.
  1. +10 −10 IPython/core/inputsplitter.py
  2. +7 −10 IPython/core/prefilter.py
@@ -502,7 +502,7 @@ def transform_assign_system(line):
if m is not None:
cmd = m.group('cmd')
lhs = m.group('lhs')
- new_line = '%s = get_ipython().getoutput(%s)' % (lhs, repr(cmd))
+ new_line = '%s = get_ipython().getoutput(%r)' % (lhs, cmd)
return new_line
return line
@@ -516,7 +516,7 @@ def transform_assign_magic(line):
if m is not None:
cmd = m.group('cmd')
lhs = m.group('lhs')
- new_line = '%s = get_ipython().magic(%s)' % (lhs, repr(cmd))
+ new_line = '%s = get_ipython().magic(%r)' % (lhs, cmd)
return new_line
return line
@@ -557,13 +557,13 @@ def _make_help_call(target, esc, lspace, next_input=None):
method = 'pinfo2' if esc == '??' \
else 'psearch' if '*' in target \
else 'pinfo'
- arg = repr(" ".join([method, target]))
+ arg = " ".join([method, target])
if next_input:
- tpl = '%sget_ipython().magic(%s, next_input=%s)'
- return tpl % (lspace, arg, repr(next_input))
+ tpl = '%sget_ipython().magic(%r, next_input=%r)'
+ return tpl % (lspace, arg, next_input)
else:
- return '%sget_ipython().magic(%s)' % (lspace, arg)
+ return '%sget_ipython().magic(%r)' % (lspace, arg)
_initial_space_re = re.compile(r'\s*')
_help_end_re = re.compile(r"""(%?
@@ -607,13 +607,13 @@ def __init__(self):
def _tr_system(line_info):
"Translate lines escaped with: !"
cmd = line_info.line.lstrip().lstrip(ESC_SHELL)
- return '%sget_ipython().system(%s)' % (line_info.pre, repr(cmd))
+ return '%sget_ipython().system(%r)' % (line_info.pre, cmd)
@staticmethod
def _tr_system2(line_info):
"Translate lines escaped with: !!"
cmd = line_info.line.lstrip()[2:]
- return '%sget_ipython().getoutput(%s)' % (line_info.pre, repr(cmd))
+ return '%sget_ipython().getoutput(%r)' % (line_info.pre, cmd)
@staticmethod
def _tr_help(line_info):
@@ -627,8 +627,8 @@ def _tr_help(line_info):
@staticmethod
def _tr_magic(line_info):
"Translate lines escaped with: %"
- tpl = '%sget_ipython().magic(%s)'
- cmd = repr(' '.join([line_info.ifun, line_info.the_rest]).strip())
+ tpl = '%sget_ipython().magic(%r)'
+ cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip()
return tpl % (line_info.pre, cmd)
@staticmethod
View
@@ -404,8 +404,8 @@ def transform(self, line, continue_prompt):
if m is not None:
cmd = m.group('cmd')
lhs = m.group('lhs')
- expr = repr("sc =%s" % cmd)
- new_line = '%s = get_ipython().magic(%s)' % (lhs, expr)
+ expr = "sc =%s" % cmd
+ new_line = '%s = get_ipython().magic(%r)' % (lhs, expr)
return new_line
return line
@@ -423,8 +423,7 @@ def transform(self, line, continue_prompt):
if m is not None:
cmd = m.group('cmd')
lhs = m.group('lhs')
- expr = repr(cmd)
- new_line = '%s = get_ipython().magic(%s)' % (lhs, expr)
+ new_line = '%s = get_ipython().magic(%r)' % (lhs, cmd)
return new_line
return line
@@ -732,8 +731,7 @@ def handle(self, line_info):
transformed = self.shell.alias_manager.expand_aliases(line_info.ifun,line_info.the_rest)
# pre is needed, because it carries the leading whitespace. Otherwise
# aliases won't work in indented sections.
- line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace,
- repr(transformed))
+ line_out = '%sget_ipython().system(%r)' % (line_info.pre_whitespace, transformed)
return line_out
@@ -761,8 +759,7 @@ def handle(self, line_info):
return magic_handler.handle(line_info)
else:
cmd = line.lstrip().lstrip(ESC_SHELL)
- line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace,
- repr(cmd))
+ line_out = '%sget_ipython().system(%r)' % (line_info.pre_whitespace, cmd)
return line_out
@@ -785,8 +782,8 @@ def handle(self, line_info):
"""Execute magic functions."""
ifun = line_info.ifun
the_rest = line_info.the_rest
- cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace,
- repr(ifun + " " + the_rest))
+ cmd = '%sget_ipython().magic(%r)' % (line_info.pre_whitespace,
+ (ifun + " " + the_rest))
return cmd

0 comments on commit 5e451b6

Please sign in to comment.