Cool. Based on this thread and an experiment I tried, some obvious (to me) things come to mind:
* get_token() needs to be fixed to handle the 'bar'asd'foo' case
* the shlex class should handle strings as input, not just file-like objects
* get_word() or get_words() methods in the shlex class could implement the shellwords functionality
Ok, it was easier than I imagined. Here's an example of the new shlex. Maintaining the old behavior (notice that now strings are accepted as arguments):
import shlex l = shlex.shlex("'foo'a'bar'") l.get_token() "'foo'" l.get_token() "a'bar'"
New behavior:
l = shlex.shlex("'foo'a'bar'", posix=1) l.get_token() 'fooabar'
Introduced iterator interface:
for i in shlex.shlex("'foo'a'bar'"): ... print i ... 'foo' a'bar'
New function, mimicking shellwords:
shlex.split_args("'foo'a'bar' -o='foo bar'") ['fooabar', '-o=foo bar']
I'm not sure if "posix" and "split_args" are the best names for these features. Suggestions? I've just commited patch #722686 (and assigned to Guido, as he suggested recently ;-). -- Gustavo Niemeyer [ 2AAC 7928 0FBF 0299 5EB5 60E2 2253 B29A 6664 3A0C ]