Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't pass unicode sys.argv with %run or `ipython script.py` #898

Closed
wants to merge 1 commit into from

2 participants

@minrk
Owner

only affects Python 2.x

closes #710

@minrk minrk don't inject unicode into sys.argv
Protects %run and `ipython script.py` from getting unicode sys.argv on Python 2

closes #710
625ff81
@fperez
Owner

Looks solid, thanks! Merging with rebase to avoid recursive.

@fperez fperez closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 18, 2011
  1. @minrk

    don't inject unicode into sys.argv

    minrk authored
    Protects %run and `ipython script.py` from getting unicode sys.argv on Python 2
    
    closes #710
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 0 deletions.
  1. +3 −0  IPython/core/magic.py
  2. +4 −0 IPython/core/shellapp.py
View
3  IPython/core/magic.py
@@ -1612,6 +1612,9 @@ def magic_run(self, parameter_s ='', runner=None,
args = [ os.path.expanduser(a) for a in arg_lst[1:] ]
sys.argv = [filename] + args # put in the proper filename
+ # protect sys.argv from potential unicode strings on Python 2:
+ if not py3compat.PY3:
+ sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
if 'i' in opts:
# Run in user's interactive namespace
View
4 IPython/core/shellapp.py
@@ -28,6 +28,7 @@
from IPython.config.application import boolean_flag
from IPython.config.configurable import Configurable
from IPython.config.loader import Config
+from IPython.utils import py3compat
from IPython.utils.path import filefind
from IPython.utils.traitlets import Unicode, Instance, List, Bool
@@ -207,6 +208,9 @@ def _exec_file(self, fname):
# were run from a system shell.
save_argv = sys.argv
sys.argv = [full_filename] + self.extra_args[1:]
+ # protect sys.argv from potential unicode strings on Python 2:
+ if not py3compat.PY3:
+ sys.argv = [ py3compat.cast_bytes(a) for a in sys.argv ]
try:
if os.path.isfile(full_filename):
if full_filename.endswith('.ipy'):
Something went wrong with that request. Please try again.