1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module xmlstream</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>xmlstream</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/kalfa/debian/mypackages/jabber.py/jabber.py-0.5.0/jabber/xmlstream.py">/home/kalfa/debian/mypackages/jabber.py/jabber.py-0.5.0/jabber/xmlstream.py</a></font></td></tr></table>
<p><tt>xmlstream.py provides simple functionality for implementing<br>
XML stream based network protocols. It is used as a base<br>
for jabber.py.<br>
<br>
xmlstream.py manages the network connectivity and xml parsing<br>
of the stream. When a complete 'protocol element' ( meaning a<br>
complete child of the xmlstreams root ) is parsed the dipatch<br>
method is called with a '<a href="#Node">Node</a>' instance of this structure.<br>
The <a href="#Node">Node</a> class is a very simple XML DOM like class for<br>
manipulating XML documents or 'protocol elements' in this<br>
case.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="debug.html">debug</a><br>
<a href="debug.html">debug</a><br>
</td><td width="25%" valign=top><a href="re.html">re</a><br>
<a href="socket.html">socket</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
<a href="time.html">time</a><br>
</td><td width="25%" valign=top><a href="_xmlplus.html">_xmlplus</a><br>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="xmlstream.html#Node">Node</a>
</font></dt><dt><font face="helvetica, arial"><a href="xmlstream.html#NodeBuilder">NodeBuilder</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="xmlstream.html#Stream">Stream</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="xmlstream.html#Client">Client</a>
</font></dt></dl>
</dd>
</dl>
</dd>
<dt><font face="helvetica, arial"><a href="xmlstream.html#Server">Server</a>
</font></dt><dt><font face="helvetica, arial"><a href="xmlstream.html#error">error</a>
</font></dt></dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Client">class <strong>Client</strong></a>(<a href="xmlstream.html#Stream">Stream</a>)</font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt>Method resolution order:</dt>
<dd><a href="xmlstream.html#Client">Client</a></dd>
<dd><a href="xmlstream.html#Stream">Stream</a></dd>
<dd><a href="xmlstream.html#NodeBuilder">NodeBuilder</a></dd>
</dl>
<hr>
Methods defined here:<br>
<dl><dt><a name="Client-__init__"><strong>__init__</strong></a>(self, host, port, namespace, debug<font color="#909090">=['always']</font>, log<font color="#909090">=None</font>, sock<font color="#909090">=None</font>, id<font color="#909090">=None</font>, connection<font color="#909090">=1</font>, hostIP<font color="#909090">=None</font>, proxy<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="Client-connect"><strong>connect</strong></a>(self)</dt><dd><tt>Attempt to connect to specified host</tt></dd></dl>
<dl><dt><a name="Client-getSocket"><strong>getSocket</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="xmlstream.html#Stream">Stream</a>:<br>
<dl><dt><a name="Client-disconnect"><strong>disconnect</strong></a>(self)</dt><dd><tt>Close the stream and socket</tt></dd></dl>
<dl><dt><a name="Client-disconnectHandler"><strong>disconnectHandler</strong></a>(self, conn)</dt><dd><tt>Called when a Network Error or disconnection occurs.<br>
Designed to be overidden</tt></dd></dl>
<dl><dt><a name="Client-disconnected"><strong>disconnected</strong></a>(self, conn)</dt><dd><tt>Called when a Network Error or disconnection occurs.</tt></dd></dl>
<dl><dt><a name="Client-getIncomingID"><strong>getIncomingID</strong></a>(self)</dt><dd><tt>Returns the streams ID</tt></dd></dl>
<dl><dt><a name="Client-getOutgoingID"><strong>getOutgoingID</strong></a>(self)</dt><dd><tt>Returns the streams ID</tt></dd></dl>
<dl><dt><a name="Client-log"><strong>log</strong></a>(self, data, inout<font color="#909090">=''</font>)</dt><dd><tt>Logs data to the specified filehandle. Data is time stamped<br>
and prefixed with inout</tt></dd></dl>
<dl><dt><a name="Client-process"><strong>process</strong></a>(self, timeout<font color="#909090">=0</font>)</dt><dd><tt>Receives incoming data (if any) and processes it.<br>
Waits for data no more than timeout seconds.</tt></dd></dl>
<dl><dt><a name="Client-read"><strong>read</strong></a>(self)</dt><dd><tt>Reads incoming data. Blocks until done. Calls <a href="#Client-disconnected">disconnected</a>(self) if appropriate.</tt></dd></dl>
<dl><dt><a name="Client-timestampLog"><strong>timestampLog</strong></a>(self, timestamp)</dt><dd><tt>Enable or disable the showing of a timestamp in the log.<br>
By default, timestamping is enabled.</tt></dd></dl>
<dl><dt><a name="Client-write"><strong>write</strong></a>(self, raw_data)</dt><dd><tt>Writes raw outgoing data. Blocks until done.<br>
If supplied data is not unicode string, ENCODING<br>
is used for convertion. Avoid this!<br>
Always send your data as a unicode string.</tt></dd></dl>
<hr>
Methods inherited from <a href="xmlstream.html#NodeBuilder">NodeBuilder</a>:<br>
<dl><dt><a name="Client-DEBUG"><strong>DEBUG</strong></a>(self, dup1, dup2<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="Client-dispatch"><strong>dispatch</strong></a>(self, dom)</dt></dl>
<dl><dt><a name="Client-getDom"><strong>getDom</strong></a>(self)</dt></dl>
<dl><dt><a name="Client-handle_data"><strong>handle_data</strong></a>(self, data)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="Client-unknown_endtag"><strong>unknown_endtag</strong></a>(self, tag)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="Client-unknown_starttag"><strong>unknown_starttag</strong></a>(self, tag, attrs)</dt><dd><tt>XML Parser callback</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Node">class <strong>Node</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A simple XML DOM like class<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Node-__init__"><strong>__init__</strong></a>(self, tag<font color="#909090">=None</font>, parent<font color="#909090">=None</font>, attrs<font color="#909090">={}</font>, payload<font color="#909090">=[]</font>, node<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="Node-__str__"><strong>__str__</strong></a>(self)</dt></dl>
<dl><dt><a name="Node-getAttr"><strong>getAttr</strong></a>(self, key)</dt><dd><tt>Get a value for the nodes named attribute.</tt></dd></dl>
<dl><dt><a name="Node-getChildren"><strong>getChildren</strong></a>(self)</dt><dd><tt>Returns a nodes children</tt></dd></dl>
<dl><dt><a name="Node-getData"><strong>getData</strong></a>(self)</dt><dd><tt>Return the nodes textual data</tt></dd></dl>
<dl><dt><a name="Node-getDataAsParts"><strong>getDataAsParts</strong></a>(self)</dt><dd><tt>Return the node data as an array</tt></dd></dl>
<dl><dt><a name="Node-getName"><strong>getName</strong></a>(self)</dt><dd><tt>Set the nodes tag name.</tt></dd></dl>
<dl><dt><a name="Node-getNamespace"><strong>getNamespace</strong></a>(self)</dt><dd><tt>Returns the nodes namespace.</tt></dd></dl>
<dl><dt><a name="Node-getParent"><strong>getParent</strong></a>(self)</dt><dd><tt>return the nodes parent node.</tt></dd></dl>
<dl><dt><a name="Node-getTag"><strong>getTag</strong></a>(self, name, index<font color="#909090">=None</font>)</dt><dd><tt>Returns a child node with tag name. Returns None<br>
if not found.</tt></dd></dl>
<dl><dt><a name="Node-getTags"><strong>getTags</strong></a>(self, name)</dt><dd><tt>Like getTag but returns a list with matching child nodes</tt></dd></dl>
<dl><dt><a name="Node-insertData"><strong>insertData</strong></a>(self, data)</dt><dd><tt>Set the nodes textual data</tt></dd></dl>
<dl><dt><a name="Node-insertNode"><strong>insertNode</strong></a>(self, node)</dt><dd><tt>Add a child node to the node</tt></dd></dl>
<dl><dt><a name="Node-insertTag"><strong>insertTag</strong></a>(self, name<font color="#909090">=None</font>, attrs<font color="#909090">={}</font>, payload<font color="#909090">=[]</font>, node<font color="#909090">=None</font>)</dt><dd><tt>Add a child tag of name 'name' to the node.<br>
<br>
Returns the newly created node.</tt></dd></dl>
<dl><dt><a name="Node-insertXML"><strong>insertXML</strong></a>(self, xml_str)</dt><dd><tt>Add raw xml as a child of the node</tt></dd></dl>
<dl><dt><a name="Node-putAttr"><strong>putAttr</strong></a>(self, key, val)</dt><dd><tt>Add a name/value attribute to the node.</tt></dd></dl>
<dl><dt><a name="Node-putData"><strong>putData</strong></a>(self, data)</dt><dd><tt>Set the nodes textual data</tt></dd></dl>
<dl><dt><a name="Node-removeTag"><strong>removeTag</strong></a>(self, tag)</dt><dd><tt>Pops out specified child and returns it.</tt></dd></dl>
<dl><dt><a name="Node-setName"><strong>setName</strong></a>(self, val)</dt><dd><tt>Set the nodes tag name.</tt></dd></dl>
<dl><dt><a name="Node-setNamespace"><strong>setNamespace</strong></a>(self, namespace)</dt><dd><tt>Set the nodes namespace.</tt></dd></dl>
<dl><dt><a name="Node-setParent"><strong>setParent</strong></a>(self, node)</dt><dd><tt>Set the nodes parent node.</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="NodeBuilder">class <strong>NodeBuilder</strong></a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>builds a 'minidom' from data parsed to it. Primarily for insertXML<br>
method of <a href="#Node">Node</a><br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="NodeBuilder-DEBUG"><strong>DEBUG</strong></a>(self, dup1, dup2<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="NodeBuilder-__init__"><strong>__init__</strong></a>(self, data<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="NodeBuilder-dispatch"><strong>dispatch</strong></a>(self, dom)</dt></dl>
<dl><dt><a name="NodeBuilder-getDom"><strong>getDom</strong></a>(self)</dt></dl>
<dl><dt><a name="NodeBuilder-handle_data"><strong>handle_data</strong></a>(self, data)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="NodeBuilder-unknown_endtag"><strong>unknown_endtag</strong></a>(self, tag)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="NodeBuilder-unknown_starttag"><strong>unknown_starttag</strong></a>(self, tag, attrs)</dt><dd><tt>XML Parser callback</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Server">class <strong>Server</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Server-__init__"><strong>__init__</strong></a>(self, maxclients<font color="#909090">=10</font>)</dt></dl>
<dl><dt><a name="Server-now"><strong>now</strong></a>(self)</dt></dl>
<dl><dt><a name="Server-serve"><strong>serve</strong></a>(self)</dt></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="Stream">class <strong>Stream</strong></a>(<a href="xmlstream.html#NodeBuilder">NodeBuilder</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Extention of <a href="#NodeBuilder">NodeBuilder</a> class. Handles stream of XML stanzas.<br>
Calls dispatch method for every child of root node<br>
(stream:stream for jabber stream).<br>
attributes _read, _write and _reader must be set by external entity<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Stream-__init__"><strong>__init__</strong></a>(self, namespace, debug<font color="#909090">=['always']</font>, log<font color="#909090">=None</font>, id<font color="#909090">=None</font>, timestampLog<font color="#909090">=1</font>)</dt></dl>
<dl><dt><a name="Stream-connect"><strong>connect</strong></a>(self)</dt></dl>
<dl><dt><a name="Stream-disconnect"><strong>disconnect</strong></a>(self)</dt><dd><tt>Close the stream and socket</tt></dd></dl>
<dl><dt><a name="Stream-disconnectHandler"><strong>disconnectHandler</strong></a>(self, conn)</dt><dd><tt>Called when a Network Error or disconnection occurs.<br>
Designed to be overidden</tt></dd></dl>
<dl><dt><a name="Stream-disconnected"><strong>disconnected</strong></a>(self, conn)</dt><dd><tt>Called when a Network Error or disconnection occurs.</tt></dd></dl>
<dl><dt><a name="Stream-getIncomingID"><strong>getIncomingID</strong></a>(self)</dt><dd><tt>Returns the streams ID</tt></dd></dl>
<dl><dt><a name="Stream-getOutgoingID"><strong>getOutgoingID</strong></a>(self)</dt><dd><tt>Returns the streams ID</tt></dd></dl>
<dl><dt><a name="Stream-log"><strong>log</strong></a>(self, data, inout<font color="#909090">=''</font>)</dt><dd><tt>Logs data to the specified filehandle. Data is time stamped<br>
and prefixed with inout</tt></dd></dl>
<dl><dt><a name="Stream-process"><strong>process</strong></a>(self, timeout<font color="#909090">=0</font>)</dt><dd><tt>Receives incoming data (if any) and processes it.<br>
Waits for data no more than timeout seconds.</tt></dd></dl>
<dl><dt><a name="Stream-read"><strong>read</strong></a>(self)</dt><dd><tt>Reads incoming data. Blocks until done. Calls <a href="#Stream-disconnected">disconnected</a>(self) if appropriate.</tt></dd></dl>
<dl><dt><a name="Stream-timestampLog"><strong>timestampLog</strong></a>(self, timestamp)</dt><dd><tt>Enable or disable the showing of a timestamp in the log.<br>
By default, timestamping is enabled.</tt></dd></dl>
<dl><dt><a name="Stream-write"><strong>write</strong></a>(self, raw_data)</dt><dd><tt>Writes raw outgoing data. Blocks until done.<br>
If supplied data is not unicode string, ENCODING<br>
is used for convertion. Avoid this!<br>
Always send your data as a unicode string.</tt></dd></dl>
<hr>
Methods inherited from <a href="xmlstream.html#NodeBuilder">NodeBuilder</a>:<br>
<dl><dt><a name="Stream-DEBUG"><strong>DEBUG</strong></a>(self, dup1, dup2<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="Stream-dispatch"><strong>dispatch</strong></a>(self, dom)</dt></dl>
<dl><dt><a name="Stream-getDom"><strong>getDom</strong></a>(self)</dt></dl>
<dl><dt><a name="Stream-handle_data"><strong>handle_data</strong></a>(self, data)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="Stream-unknown_endtag"><strong>unknown_endtag</strong></a>(self, tag)</dt><dd><tt>XML Parser callback</tt></dd></dl>
<dl><dt><a name="Stream-unknown_starttag"><strong>unknown_starttag</strong></a>(self, tag, attrs)</dt><dd><tt>XML Parser callback</tt></dd></dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="error">class <strong>error</strong></a></font></td></tr>
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="error-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>
<dl><dt><a name="error-__str__"><strong>__str__</strong></a>(self)</dt></dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-XMLescape"><strong>XMLescape</strong></a>(txt)</dt><dd><tt>Escape XML entities</tt></dd></dl>
<dl><dt><a name="-XMLunescape"><strong>XMLunescape</strong></a>(txt)</dt><dd><tt>Unescape XML entities</tt></dd></dl>
<dl><dt><a name="-select"><strong>select</strong></a>(...)</dt><dd><tt><a href="#-select">select</a>(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)<br>
<br>
Wait until one or more file descriptors are ready for some kind of I/O.<br>
The first three arguments are lists of file descriptors to be waited for:<br>
rlist -- wait until ready for reading<br>
wlist -- wait until ready for writing<br>
xlist -- wait for an ``exceptional condition''<br>
If only one kind of condition is required, pass [] for the other lists.<br>
A file descriptor is either a socket or file object, or a small integer<br>
gotten from a fileno() method call on one of those.<br>
<br>
The optional 4th argument specifies a timeout in seconds; it may be<br>
a floating point number to specify fractions of seconds. If it is absent<br>
or None, the call will never time out.<br>
<br>
The return value is a tuple of three lists corresponding to the first three<br>
arguments; each contains the subset of the corresponding file descriptors<br>
that are ready.<br>
<br>
*** IMPORTANT NOTICE ***<br>
On Windows, only sockets are supported; on Unix, all file descriptors.</tt></dd></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>BLOCK_SIZE</strong> = 1024<br>
<strong>DBG_ALWAYS</strong> = 'always'<br>
<strong>DBG_CONN_ERROR</strong> = 'conn-error'<br>
<strong>DBG_INIT</strong> = 'init'<br>
<strong>DBG_XML</strong> = ['xml-parse', 'xml-raw']<br>
<strong>DBG_XML_PARSE</strong> = 'xml-parse'<br>
<strong>DBG_XML_RAW</strong> = 'xml-raw'<br>
<strong>ENCODING</strong> = 'utf-8'<br>
<strong>False</strong> = 0<br>
<strong>STDIO</strong> = 0<br>
<strong>TCP</strong> = 1<br>
<strong>TCP_SSL</strong> = 2<br>
<strong>True</strong> = 1<br>
<strong>VERSION</strong> = '0.5'</td></tr></table>
</body></html>
|