optionally ignore shlex's ValueError in arg_split #1130

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
1 participant
@minrk
Member

minrk commented Dec 8, 2011

Sometimes we pass things that aren't really command-line args to arg_split, e.g:

%timeit python_code(" ")

These things probably shouldn't be parsed as command-line args, but they are.
So we should at least prevent them from raising, when shlex doesn't think they are valid shell args.

This commit protects this sort of thing from raising errors. Another
approach would be to use a different function when parsing things that
are clearly not command-line args (like Python code), but this works for now.

closes #1109

minrk and others added some commits Dec 8, 2011

add strict flag to arg_split, to optionally ignore shlex parse errors
Sometimes we pass things that aren't really command-line args to arg_split, e.g:

    %timeit python_code(" ")

This commit adds a `strict` flag, which defaults to the same raising behavior
as before.

Currently magic_timeit is the *only* place, we use strict=False, but it should
also be done in completions (PR #1116).

closes #1109
Replaced shlex_split with arg_split from _process_common.
shlex_split was removed since it was a unicode unsafe version of
arg_split. Tests were added to test magic_run_completer.

@minrk minrk closed this in 790cb14 Dec 12, 2011

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

Merge shlex PRs (#1130, #1116)
* arg_split now takes optional strict flag, to ignore ValueErrors in
  shlex parsing
* %timeit uses strict=False, to avoid errors parsing python code
* %run completer uses arg_split(strict=False) for its unicode behavior, instead
  of custom shlex derivative, which is now redundant.

closes #1109
closes #1115
closes #1116
closes #1130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment