optionally ignore shlex's ValueError in arg_split #1130

Closed
wants to merge 5 commits into
from

Projects

None yet

1 participant

@minrk
IPython member

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
@minrk minrk 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
4f1e79b
J��rgen Stenarson Fixing shlex_split to return unicode on py2.x 5bd8972
Jörgen Stenarson 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.
aac154d
@minrk minrk use arg_split(...strict=False) in module_completer 963dd69
@minrk minrk add %run open-quote completerlib test fa99077
@minrk minrk added a commit to minrk/ipython that referenced this pull request Dec 12, 2011
@minrk minrk 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
790cb14
@minrk minrk added a commit that closed this pull request Dec 12, 2011
@minrk minrk 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
790cb14
@minrk minrk closed this in 790cb14 Dec 12, 2011
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
@minrk minrk 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
5799471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment