Skip to content

Commit

Permalink
Merge pull request ipython#3233 from minrk/scrubprefix
Browse files Browse the repository at this point in the history
check prefixes for swallowing kernel args
  • Loading branch information
ellisonbg committed Apr 29, 2013
2 parents 5303d82 + c24091c commit fe18cbe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions IPython/kernel/launcher.py
Expand Up @@ -61,6 +61,8 @@ def swallow_argv(argv, aliases=None, flags=None):
swallow_next = False
was_flag = False
for a in argv:
if a == '--':
break
if swallow_next:
swallow_next = False
# last arg was an alias, remove the next one
Expand All @@ -71,16 +73,19 @@ def swallow_argv(argv, aliases=None, flags=None):
continue
if a.startswith('-'):
split = a.lstrip('-').split('=')
alias = split[0]
if alias in aliases:
name = split[0]
# we use startswith because argparse accepts any arg to be specified
# by any leading section, as long as it is unique,
# so `--no-br` means `--no-browser` in the notebook, etc.
if any(alias.startswith(name) for alias in aliases):
stripped.remove(a)
if len(split) == 1:
# alias passed with arg via space
swallow_next = True
# could have been a flag that matches an alias, e.g. `existing`
# in which case, we might not swallow the next arg
was_flag = alias in flags
elif alias in flags and len(split) == 1:
was_flag = name in flags
elif len(split) == 1 and any(flag.startswith(name) for flag in flags):
# strip flag, but don't swallow next, as flags don't take args
stripped.remove(a)

Expand Down
2 changes: 1 addition & 1 deletion IPython/kernel/tests/test_launcher.py
Expand Up @@ -39,7 +39,7 @@ def test_swallow_argv():
([], ['-a', '5'], ['a'], None),
([], ['-a', '5'], ['a'], ['a']),
([], ['--foo'], None, ['foo']),
(['--foo'], ['--foo'], ['foobar'], []),
([], ['--foo'], ['foobar'], []),
([], ['--foo', '5'], ['foo'], []),
([], ['--foo=5'], ['foo'], []),
(['--foo=5'], ['--foo=5'], [], ['foo']),
Expand Down

0 comments on commit fe18cbe

Please sign in to comment.