Package gnue :: Package common :: Package external :: Module shellwords
[show private | hide private]

Module gnue.common.external.shellwords

shellwords.py

Parse a string into words like a (POSIX) shell does.

License: Python Software Foundation License
         http://www.opensource.org/licenses/PythonSoftFoundation.html

This module parses a string into words according to the parings-rules
of a POSIX shell. These parsing rules are (quoted after 'man bash'):

1) Words are split at whitespace charakters; these are Space, Tab,
   Newline, Carriage-Return, Vertival-Tab (0B) and Form-Feet (0C).

   NB: Quotes do _not_ separate words! Thus
        "My"Fancy"Computer"
   will be parsed into a single word:
        MyFancyComputer

2) A non-quoted backslash (\) is the escape character. It preserves
   the literal value of the next character that follows.

3) Enclosing characters in single quotes preserves the literal value
   of each character within the quotes. A single quote may not occur
   between single quotes, even when preceded by a backslash.

   This means: baskslash (\) has no special meaning within single
   quotes. All charakters within single quotes are taken as-is.

4) Enclosing characters in double quotes preserves the literal value
   of all characters within the quotes, with the exception of \. The
   backslash retains its special meaning only when followed " or \. A
   double quote may be quoted within double quotes by preceding it
   with a backslash.

http://www.crazy-compilers.com/py-lib/#shellwords

Classes
Arg Simple helper class for a string-like type which distinguishs between 'empty' and 'undefined'.

Exceptions
EOFError  
UnmatchedDoubleQuoteError  
UnmatchedQuoteError  
UnmatchedSingleQuoteError  

Function Summary
  shellwords(line)

Variable Summary
str __author__ = 'Hartmut Goebel <h.goebel@crazy-compilers.c...
str __copyright__ = '(C) Copyright 2002 by Hartmut Goebel'
str __license__ = 'Python Software Foundation License'
str __url__ = 'http://www.crazy-compilers.com/py-lib/#shellw...
str __version__ = '0.2'
SRE_Pattern re_dquote = "(([^"\\]|\\.)*)"
SRE_Pattern re_esc_quote = \\([\\"])
SRE_Pattern re_escaped = \\(.)
SRE_Pattern re_outside = ([^\s\\'"]+)
SRE_Pattern re_squote = '(.*?)'

Function Details

shellwords(line)


Variable Details

__author__

Type:
str
Value:
'Hartmut Goebel <h.goebel@crazy-compilers.com>'                        

__copyright__

Type:
str
Value:
'(C) Copyright 2002 by Hartmut Goebel'                                 

__license__

Type:
str
Value:
'Python Software Foundation License'                                   

__url__

Type:
str
Value:
'http://www.crazy-compilers.com/py-lib/#shellwords'                    

__version__

Type:
str
Value:
'0.2'                                                                  

re_dquote

Type:
SRE_Pattern
Value:
"(([^"\\]|\\.)*)"                                                      

re_esc_quote

Type:
SRE_Pattern
Value:
\\([\\"])                                                              

re_escaped

Type:
SRE_Pattern
Value:
\\(.)                                                                  

re_outside

Type:
SRE_Pattern
Value:
([^\s\\'"]+)                                                           

re_squote

Type:
SRE_Pattern
Value:
'(.*?)'                                                                


GNUe Home

Private API

Developer's Corner