diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-04-23 16:41:47 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-09-03 22:14:08 +0100 |
commit | b643f49dfa48301e57a60aa0d407dcaceb9f6b2f (patch) | |
tree | 047b003e39fa99cf7b0826ee0c83273c9c1da318 /alot/helper.py | |
parent | 79ca9ff0fd334f0f502b86193a2b6acdbef1d089 (diff) |
add split_commandline helper
that splits ;-separated commandlines safely using shlex
Diffstat (limited to 'alot/helper.py')
-rw-r--r-- | alot/helper.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/alot/helper.py b/alot/helper.py index 3e5e9dce..ad605acb 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -24,6 +24,21 @@ import StringIO import logging +def split_commandline(s, comments=False, posix=True): + """ + splits semi-colon separated commandlines + """ + # encode s to utf-8 for shlex + if isinstance(s, unicode): + s = s.encode('utf-8') + lex = shlex.shlex(s, posix=posix) + lex.whitespace_split = True + lex.whitespace = ';' + if not comments: + lex.commenters = '' + return list(lex) + + def split_commandstring(cmdstring): """ split command string into a list of strings to pass on to subprocess.Popen |