[Python-Dev] shellwords (original) (raw)
Gustavo Niemeyer niemeyer@conectiva.com
Wed, 16 Apr 2003 16:23:27 -0300
- Previous message: [Python-Dev] shellwords
- Next message: [Python-Dev] shellwords
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Cool. Based on this thread and an experiment I tried, some obvious (to me) things come to mind:
* gettoken() needs to be fixed to handle the 'bar'asd'foo' case * the shlex class should handle strings as input, not just file-like objects * getword() or getwords() 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.gettoken() "'foo'" l.gettoken() "a'bar'"
New behavior:
l = shlex.shlex("'foo'a'bar'", posix=1) l.gettoken() 'fooabar'
Introduced iterator interface:
for i in shlex.shlex("'foo'a'bar'"): ... print i ... 'foo' a'bar'
New function, mimicking shellwords:
shlex.splitargs("'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 ]
- Previous message: [Python-Dev] shellwords
- Next message: [Python-Dev] shellwords
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]