Commit | Line | Data |
---|---|---|
920dae64 AT |
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="next" href="module-xml.sax.xmlreader.html" /> | |
13 | <link rel="prev" href="module-xml.sax.handler.html" /> | |
14 | <link rel="parent" href="markup.html" /> | |
15 | <link rel="next" href="module-xml.sax.xmlreader.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>13.11 xml.sax.saxutils -- SAX Utilities</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="13.10.4 ErrorHandler Objects" | |
25 | href="sax-error-handler.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="13. Structured Markup Processing" | |
28 | href="markup.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="13.12 xml.sax.xmlreader " | |
31 | href="module-xml.sax.xmlreader.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="sax-error-handler.html">13.10.4 ErrorHandler Objects</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-xml.sax.xmlreader.html">13.12 xml.sax.xmlreader </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION00151100000000000000000"> | |
56 | 13.11 <tt class="module">xml.sax.saxutils</tt> -- | |
57 | SAX Utilities</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-xml.sax.saxutils"></A> | |
62 | ||
63 | <P> | |
64 | ||
65 | <span class="versionnote">New in version 2.0.</span> | |
66 | ||
67 | <P> | |
68 | The module <tt class="module">xml.sax.saxutils</tt> contains a number of classes and | |
69 | functions that are commonly useful when creating SAX applications, | |
70 | either in direct use, or as base classes. | |
71 | ||
72 | <P> | |
73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
74 | <td><nobr><b><tt id='l2h-4509' xml:id='l2h-4509' class="function">escape</tt></b>(</nobr></td> | |
75 | <td><var>data</var><big>[</big><var>, entities</var><big>]</big><var></var>)</td></tr></table></dt> | |
76 | <dd> | |
77 | Escape "<tt class="character">&</tt>", "<tt class="character"><</tt>", and "<tt class="character">></tt>" in a string | |
78 | of data. | |
79 | ||
80 | <P> | |
81 | You can escape other strings of data by passing a dictionary as the | |
82 | optional <var>entities</var> parameter. The keys and values must all be | |
83 | strings; each key will be replaced with its corresponding value. | |
84 | </dl> | |
85 | ||
86 | <P> | |
87 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
88 | <td><nobr><b><tt id='l2h-4510' xml:id='l2h-4510' class="function">unescape</tt></b>(</nobr></td> | |
89 | <td><var>data</var><big>[</big><var>, entities</var><big>]</big><var></var>)</td></tr></table></dt> | |
90 | <dd> | |
91 | Unescape "<tt class="character">&amp;</tt>", "<tt class="character">&lt;</tt>", and "<tt class="character">&gt;</tt>" | |
92 | in a string of data. | |
93 | ||
94 | <P> | |
95 | You can unescape other strings of data by passing a dictionary as the | |
96 | optional <var>entities</var> parameter. The keys and values must all be | |
97 | strings; each key will be replaced with its corresponding value. | |
98 | ||
99 | <P> | |
100 | ||
101 | <span class="versionnote">New in version 2.3.</span> | |
102 | ||
103 | </dl> | |
104 | ||
105 | <P> | |
106 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
107 | <td><nobr><b><tt id='l2h-4511' xml:id='l2h-4511' class="function">quoteattr</tt></b>(</nobr></td> | |
108 | <td><var>data</var><big>[</big><var>, entities</var><big>]</big><var></var>)</td></tr></table></dt> | |
109 | <dd> | |
110 | Similar to <tt class="function">escape()</tt>, but also prepares <var>data</var> to be | |
111 | used as an attribute value. The return value is a quoted version of | |
112 | <var>data</var> with any additional required replacements. | |
113 | <tt class="function">quoteattr()</tt> will select a quote character based on the | |
114 | content of <var>data</var>, attempting to avoid encoding any quote | |
115 | characters in the string. If both single- and double-quote | |
116 | characters are already in <var>data</var>, the double-quote characters | |
117 | will be encoded and <var>data</var> will be wrapped in double-quotes. The | |
118 | resulting string can be used directly as an attribute value: | |
119 | ||
120 | <P> | |
121 | <div class="verbatim"><pre> | |
122 | >>> print "<element attr=%s>" % quoteattr("ab ' cd \" ef") | |
123 | <element attr="ab ' cd &quot; ef"> | |
124 | </pre></div> | |
125 | ||
126 | <P> | |
127 | This function is useful when generating attribute values for HTML or | |
128 | any SGML using the reference concrete syntax. | |
129 | ||
130 | <span class="versionnote">New in version 2.2.</span> | |
131 | ||
132 | </dl> | |
133 | ||
134 | <P> | |
135 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
136 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-4512' xml:id='l2h-4512' class="class">XMLGenerator</tt></b>(</nobr></td> | |
137 | <td><var></var><big>[</big><var>out</var><big>[</big><var>, encoding</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
138 | <dd> | |
139 | This class implements the <tt class="class">ContentHandler</tt> interface by | |
140 | writing SAX events back into an XML document. In other words, using | |
141 | an <tt class="class">XMLGenerator</tt> as the content handler will reproduce the | |
142 | original document being parsed. <var>out</var> should be a file-like | |
143 | object which will default to <var>sys.stdout</var>. <var>encoding</var> is the | |
144 | encoding of the output stream which defaults to <code>'iso-8859-1'</code>. | |
145 | </dl> | |
146 | ||
147 | <P> | |
148 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
149 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-4513' xml:id='l2h-4513' class="class">XMLFilterBase</tt></b>(</nobr></td> | |
150 | <td><var>base</var>)</td></tr></table></dt> | |
151 | <dd> | |
152 | This class is designed to sit between an <tt class="class">XMLReader</tt> and the | |
153 | client application's event handlers. By default, it does nothing | |
154 | but pass requests up to the reader and events on to the handlers | |
155 | unmodified, but subclasses can override specific methods to modify | |
156 | the event stream or the configuration requests as they pass through. | |
157 | </dl> | |
158 | ||
159 | <P> | |
160 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
161 | <td><nobr><b><tt id='l2h-4514' xml:id='l2h-4514' class="function">prepare_input_source</tt></b>(</nobr></td> | |
162 | <td><var>source</var><big>[</big><var>, base</var><big>]</big><var></var>)</td></tr></table></dt> | |
163 | <dd> | |
164 | This function takes an input source and an optional base URL and | |
165 | returns a fully resolved <tt class="class">InputSource</tt> object ready for | |
166 | reading. The input source can be given as a string, a file-like | |
167 | object, or an <tt class="class">InputSource</tt> object; parsers will use this | |
168 | function to implement the polymorphic <var>source</var> argument to their | |
169 | <tt class="method">parse()</tt> method. | |
170 | </dl> | |
171 | ||
172 | <DIV CLASS="navigation"> | |
173 | <div class='online-navigation'> | |
174 | <p></p><hr /> | |
175 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
176 | <tr> | |
177 | <td class='online-navigation'><a rel="prev" title="13.10.4 ErrorHandler Objects" | |
178 | href="sax-error-handler.html"><img src='../icons/previous.png' | |
179 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
180 | <td class='online-navigation'><a rel="parent" title="13. Structured Markup Processing" | |
181 | href="markup.html"><img src='../icons/up.png' | |
182 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
183 | <td class='online-navigation'><a rel="next" title="13.12 xml.sax.xmlreader " | |
184 | href="module-xml.sax.xmlreader.html"><img src='../icons/next.png' | |
185 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
186 | <td align="center" width="100%">Python Library Reference</td> | |
187 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
188 | href="contents.html"><img src='../icons/contents.png' | |
189 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
190 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
191 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
192 | <td class='online-navigation'><a rel="index" title="Index" | |
193 | href="genindex.html"><img src='../icons/index.png' | |
194 | border='0' height='32' alt='Index' width='32' /></A></td> | |
195 | </tr></table> | |
196 | <div class='online-navigation'> | |
197 | <b class="navlabel">Previous:</b> | |
198 | <a class="sectref" rel="prev" href="sax-error-handler.html">13.10.4 ErrorHandler Objects</A> | |
199 | <b class="navlabel">Up:</b> | |
200 | <a class="sectref" rel="parent" href="markup.html">13. Structured Markup Processing</A> | |
201 | <b class="navlabel">Next:</b> | |
202 | <a class="sectref" rel="next" href="module-xml.sax.xmlreader.html">13.12 xml.sax.xmlreader </A> | |
203 | </div> | |
204 | </div> | |
205 | <hr /> | |
206 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
207 | </DIV> | |
208 | <!--End of Navigation Panel--> | |
209 | <ADDRESS> | |
210 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
211 | </ADDRESS> | |
212 | </BODY> | |
213 | </HTML> |