Permalink
Browse files

BUG: execute_file fix failed on Windows.

Stripping code down to non-platform-specific essence
at cost of some unnecessary escaping.
  • Loading branch information...
1 parent a142ba4 commit 86ce21eda9635730e470cf0366219b0ffbc8d2c8 @jdmarch committed Dec 12, 2011
Showing with 14 additions and 6 deletions.
  1. +14 −6 IPython/frontend/qt/console/ipython_widget.py
@@ -277,13 +277,21 @@ def execute_file(self, path, hidden=False):
# Perhaps we should not be using %run directly, but while we
# are, it is necessary to quote or escape filenames containing spaces
- # or quotes. Note that in this context, because run uses posix
- # parsing, we can escape double quotes in a double quoted filename,
- # but can't escape singe quotes in a single quoted filename.
- if "'" in path:
+ # or quotes.
+
+ # In earlier code here, to minimize escaping, we sometimes quoted the
+ # filename with single quotes. But to do this, this code must be
+ # platform-aware, because run uses shlex rather than python string
+ # parsing, so that:
+ # * In Win: single quotes can be used in the filename without quoting,
+ # and we cannot use single quotes to quote the filename.
+ # * In *nix: we can escape double quotes in a double quoted filename,
+ # but can't escape single quotes in a single quoted filename.
+
+ # So to keep this code non-platform-specific and simple, we now only
+ # use double quotes to quote filenames, and escape when needed:
+ if ' ' in path or "'" in path or '"' in path:
path = '"%s"' % path.replace('"', '\\"')
- elif ' ' in path or '"' in path:
- path = "'%s'" % path
self.execute('%%run %s' % path, hidden=hidden)
#---------------------------------------------------------------------------

0 comments on commit 86ce21e

Please sign in to comment.