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

Min RK Fernando Perez
Min RK
Owner

only affects Python 2.x

closes #710

Min RK 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
Fernando Perez
Owner

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

Fernando Perez 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. Min RK

    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
3  IPython/core/magic.py
View
@@ -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
4 IPython/core/shellapp.py
View
@@ -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.