| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="shlex-objects.html" /> |
| 13 | <link rel="parent" href="module-shlex.html" /> |
| 14 | <link rel="next" href="allos.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>5.21.2 Parsing Rules</title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="5.21.1 shlex Objects" |
| 24 | href="shlex-objects.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="5.21 shlex " |
| 27 | href="module-shlex.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="6. Generic Operating System" |
| 30 | href="allos.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="shlex-objects.html">5.21.1 shlex Objects</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="module-shlex.html">5.21 shlex </A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="allos.html">6. Generic Operating System</A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION0072120000000000000000"></A><A NAME="shlex-parsing-rules"></A> |
| 55 | <BR> |
| 56 | 5.21.2 Parsing Rules |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | When operating in non-POSIX mode, <tt class="class">shlex</tt> will try to obey to |
| 61 | the following rules. |
| 62 | |
| 63 | <P> |
| 64 | |
| 65 | <UL> |
| 66 | <LI>Quote characters are not recognized within words |
| 67 | (<code>Do"Not"Separate</code> is parsed as the single word |
| 68 | <code>Do"Not"Separate</code>); |
| 69 | </LI> |
| 70 | <LI>Escape characters are not recognized; |
| 71 | </LI> |
| 72 | <LI>Enclosing characters in quotes preserve the literal value of |
| 73 | all characters within the quotes; |
| 74 | </LI> |
| 75 | <LI>Closing quotes separate words (<code>"Do"Separate</code> is parsed |
| 76 | as <code>"Do"</code> and <code>Separate</code>); |
| 77 | </LI> |
| 78 | <LI>If <tt class="member">whitespace_split</tt> is <code>False</code>, any character not |
| 79 | declared to be a word character, whitespace, or a quote will be |
| 80 | returned as a single-character token. If it is <code>True</code>, |
| 81 | <tt class="class">shlex</tt> will only split words in whitespaces; |
| 82 | </LI> |
| 83 | <LI>EOF is signaled with an empty string (<code>''</code>); |
| 84 | </LI> |
| 85 | <LI>It's not possible to parse empty strings, even if quoted. |
| 86 | </LI> |
| 87 | </UL> |
| 88 | |
| 89 | <P> |
| 90 | When operating in POSIX mode, <tt class="class">shlex</tt> will try to obey to the |
| 91 | following parsing rules. |
| 92 | |
| 93 | <P> |
| 94 | |
| 95 | <UL> |
| 96 | <LI>Quotes are stripped out, and do not separate words |
| 97 | (<code>"Do"Not"Separate"</code> is parsed as the single word |
| 98 | <code>DoNotSeparate</code>); |
| 99 | </LI> |
| 100 | <LI>Non-quoted escape characters (e.g. "<tt class="character">\</tt>") |
| 101 | preserve the literal value of the next character that follows; |
| 102 | </LI> |
| 103 | <LI>Enclosing characters in quotes which are not part of |
| 104 | <tt class="member">escapedquotes</tt> (e.g. "<tt class="character">'</tt>") preserve the literal |
| 105 | value of all characters within the quotes; |
| 106 | </LI> |
| 107 | <LI>Enclosing characters in quotes which are part of |
| 108 | <tt class="member">escapedquotes</tt> (e.g. "<tt class="character">"</tt>") preserves the literal |
| 109 | value of all characters within the quotes, with the exception of |
| 110 | the characters mentioned in <tt class="member">escape</tt>. The escape characters |
| 111 | retain its special meaning only when followed by the quote in use, |
| 112 | or the escape character itself. Otherwise the escape character |
| 113 | will be considered a normal character. |
| 114 | </LI> |
| 115 | <LI>EOF is signaled with a <tt class="constant">None</tt> value; |
| 116 | </LI> |
| 117 | <LI>Quoted empty strings (<code>''</code>) are allowed; |
| 118 | </LI> |
| 119 | </UL> |
| 120 | |
| 121 | <P> |
| 122 | |
| 123 | <DIV CLASS="navigation"> |
| 124 | <div class='online-navigation'> |
| 125 | <p></p><hr /> |
| 126 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 127 | <tr> |
| 128 | <td class='online-navigation'><a rel="prev" title="5.21.1 shlex Objects" |
| 129 | href="shlex-objects.html"><img src='../icons/previous.png' |
| 130 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 131 | <td class='online-navigation'><a rel="parent" title="5.21 shlex " |
| 132 | href="module-shlex.html"><img src='../icons/up.png' |
| 133 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 134 | <td class='online-navigation'><a rel="next" title="6. Generic Operating System" |
| 135 | href="allos.html"><img src='../icons/next.png' |
| 136 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 137 | <td align="center" width="100%">Python Library Reference</td> |
| 138 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 139 | href="contents.html"><img src='../icons/contents.png' |
| 140 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 141 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 142 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 143 | <td class='online-navigation'><a rel="index" title="Index" |
| 144 | href="genindex.html"><img src='../icons/index.png' |
| 145 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 146 | </tr></table> |
| 147 | <div class='online-navigation'> |
| 148 | <b class="navlabel">Previous:</b> |
| 149 | <a class="sectref" rel="prev" href="shlex-objects.html">5.21.1 shlex Objects</A> |
| 150 | <b class="navlabel">Up:</b> |
| 151 | <a class="sectref" rel="parent" href="module-shlex.html">5.21 shlex </A> |
| 152 | <b class="navlabel">Next:</b> |
| 153 | <a class="sectref" rel="next" href="allos.html">6. Generic Operating System</A> |
| 154 | </div> |
| 155 | </div> |
| 156 | <hr /> |
| 157 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 158 | </DIV> |
| 159 | <!--End of Navigation Panel--> |
| 160 | <ADDRESS> |
| 161 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 162 | </ADDRESS> |
| 163 | </BODY> |
| 164 | </HTML> |