blob: 077015ca28a98c29d56d847f541a07bbcb785d72 [file] [log] [blame] [edit]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gdata.tlslite.integration.TLSAsyncDispatcherMixIn</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="gdata.html"><font color="#ffffff">gdata</font></a>.<a href="gdata.tlslite.html"><font color="#ffffff">tlslite</font></a>.<a href="gdata.tlslite.integration.html"><font color="#ffffff">integration</font></a>.TLSAsyncDispatcherMixIn</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/tlslite/integration/TLSAsyncDispatcherMixIn.py">/usr/local/google/home/afshar/src/external-gdata-release/google3/src/gdata/tlslite/integration/TLSAsyncDispatcherMixIn.py</a></font></td></tr></table>
<p><tt>TLS&nbsp;Lite&nbsp;+&nbsp;asyncore.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="asyncore.html">asyncore</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></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>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="gdata.tlslite.integration.AsyncStateMachine.html#AsyncStateMachine">gdata.tlslite.integration.AsyncStateMachine.AsyncStateMachine</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gdata.tlslite.integration.TLSAsyncDispatcherMixIn.html#TLSAsyncDispatcherMixIn">TLSAsyncDispatcherMixIn</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="TLSAsyncDispatcherMixIn">class <strong>TLSAsyncDispatcherMixIn</strong></a>(<a href="gdata.tlslite.integration.AsyncStateMachine.html#AsyncStateMachine">gdata.tlslite.integration.AsyncStateMachine.AsyncStateMachine</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>This&nbsp;class&nbsp;can&nbsp;be&nbsp;"mixed&nbsp;in"&nbsp;with&nbsp;an<br>
L{asyncore.dispatcher}&nbsp;to&nbsp;add&nbsp;TLS&nbsp;support.<br>
&nbsp;<br>
This&nbsp;class&nbsp;essentially&nbsp;sits&nbsp;between&nbsp;the&nbsp;dispatcher&nbsp;and&nbsp;the&nbsp;select<br>
loop,&nbsp;intercepting&nbsp;events&nbsp;and&nbsp;only&nbsp;calling&nbsp;the&nbsp;dispatcher&nbsp;when<br>
applicable.<br>
&nbsp;<br>
In&nbsp;the&nbsp;case&nbsp;of&nbsp;<a href="#TLSAsyncDispatcherMixIn-handle_read">handle_read</a>(),&nbsp;a&nbsp;read&nbsp;operation&nbsp;will&nbsp;be&nbsp;activated,<br>
and&nbsp;when&nbsp;it&nbsp;completes,&nbsp;the&nbsp;bytes&nbsp;will&nbsp;be&nbsp;placed&nbsp;in&nbsp;a&nbsp;buffer&nbsp;where<br>
the&nbsp;dispatcher&nbsp;can&nbsp;retrieve&nbsp;them&nbsp;by&nbsp;calling&nbsp;<a href="#TLSAsyncDispatcherMixIn-recv">recv</a>(),&nbsp;and&nbsp;the<br>
dispatcher's&nbsp;<a href="#TLSAsyncDispatcherMixIn-handle_read">handle_read</a>()&nbsp;will&nbsp;be&nbsp;called.<br>
&nbsp;<br>
In&nbsp;the&nbsp;case&nbsp;of&nbsp;<a href="#TLSAsyncDispatcherMixIn-handle_write">handle_write</a>(),&nbsp;the&nbsp;dispatcher's&nbsp;<a href="#TLSAsyncDispatcherMixIn-handle_write">handle_write</a>()&nbsp;will<br>
be&nbsp;called,&nbsp;and&nbsp;when&nbsp;it&nbsp;calls&nbsp;<a href="#TLSAsyncDispatcherMixIn-send">send</a>(),&nbsp;a&nbsp;write&nbsp;operation&nbsp;will&nbsp;be<br>
activated.<br>
&nbsp;<br>
To&nbsp;use&nbsp;this&nbsp;class,&nbsp;you&nbsp;must&nbsp;combine&nbsp;it&nbsp;with&nbsp;an&nbsp;asyncore.dispatcher,<br>
and&nbsp;pass&nbsp;in&nbsp;a&nbsp;handshake&nbsp;operation&nbsp;with&nbsp;<a href="#TLSAsyncDispatcherMixIn-setServerHandshakeOp">setServerHandshakeOp</a>().<br>
&nbsp;<br>
Below&nbsp;is&nbsp;an&nbsp;example&nbsp;of&nbsp;using&nbsp;this&nbsp;class&nbsp;with&nbsp;medusa.&nbsp;&nbsp;This&nbsp;class&nbsp;is<br>
mixed&nbsp;in&nbsp;with&nbsp;http_channel&nbsp;to&nbsp;create&nbsp;http_tls_channel.&nbsp;&nbsp;Note:<br>
&nbsp;1.&nbsp;the&nbsp;mix-in&nbsp;is&nbsp;listed&nbsp;first&nbsp;in&nbsp;the&nbsp;inheritance&nbsp;list<br>
&nbsp;<br>
&nbsp;2.&nbsp;the&nbsp;input&nbsp;buffer&nbsp;size&nbsp;must&nbsp;be&nbsp;at&nbsp;least&nbsp;16K,&nbsp;otherwise&nbsp;the<br>
&nbsp;&nbsp;&nbsp;dispatcher&nbsp;might&nbsp;not&nbsp;read&nbsp;all&nbsp;the&nbsp;bytes&nbsp;from&nbsp;the&nbsp;TLS&nbsp;layer,<br>
&nbsp;&nbsp;&nbsp;leaving&nbsp;some&nbsp;bytes&nbsp;in&nbsp;limbo.<br>
&nbsp;<br>
&nbsp;3.&nbsp;IE&nbsp;seems&nbsp;to&nbsp;have&nbsp;a&nbsp;problem&nbsp;receiving&nbsp;a&nbsp;whole&nbsp;HTTP&nbsp;response&nbsp;in&nbsp;a<br>
&nbsp;single&nbsp;TLS&nbsp;record,&nbsp;so&nbsp;HTML&nbsp;pages&nbsp;containing&nbsp;'\r\n\r\n'&nbsp;won't<br>
&nbsp;be&nbsp;displayed&nbsp;on&nbsp;IE.<br>
&nbsp;<br>
Add&nbsp;the&nbsp;following&nbsp;text&nbsp;into&nbsp;'start_medusa.py',&nbsp;in&nbsp;the&nbsp;'HTTP&nbsp;Server'<br>
section::<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;tlslite.api&nbsp;import&nbsp;*<br>
&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;open("./serverX509Cert.pem").read()<br>
&nbsp;&nbsp;&nbsp;&nbsp;x509&nbsp;=&nbsp;X509()<br>
&nbsp;&nbsp;&nbsp;&nbsp;x509.parse(s)<br>
&nbsp;&nbsp;&nbsp;&nbsp;certChain&nbsp;=&nbsp;X509CertChain([x509])<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;open("./serverX509Key.pem").read()<br>
&nbsp;&nbsp;&nbsp;&nbsp;privateKey&nbsp;=&nbsp;parsePEMKey(s,&nbsp;private=True)<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;class&nbsp;http_tls_channel(<a href="#TLSAsyncDispatcherMixIn">TLSAsyncDispatcherMixIn</a>,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http_server.http_channel):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ac_in_buffer_size&nbsp;=&nbsp;16384<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;__init__&nbsp;(self,&nbsp;server,&nbsp;conn,&nbsp;addr):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;http_server.http_channel.<a href="#TLSAsyncDispatcherMixIn-__init__">__init__</a>(self,&nbsp;server,&nbsp;conn,&nbsp;addr)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#TLSAsyncDispatcherMixIn">TLSAsyncDispatcherMixIn</a>.<a href="#TLSAsyncDispatcherMixIn-__init__">__init__</a>(self,&nbsp;conn)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.<strong>tlsConnection</strong>.ignoreAbruptClose&nbsp;=&nbsp;True<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#TLSAsyncDispatcherMixIn-setServerHandshakeOp">setServerHandshakeOp</a>(certChain=certChain,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;privateKey=privateKey)<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;hs.channel_class&nbsp;=&nbsp;http_tls_channel<br>
&nbsp;<br>
If&nbsp;the&nbsp;TLS&nbsp;layer&nbsp;raises&nbsp;an&nbsp;exception,&nbsp;the&nbsp;exception&nbsp;will&nbsp;be&nbsp;caught<br>
in&nbsp;asyncore.dispatcher,&nbsp;which&nbsp;will&nbsp;call&nbsp;<a href="#TLSAsyncDispatcherMixIn-close">close</a>()&nbsp;on&nbsp;this&nbsp;class.&nbsp;&nbsp;The<br>
TLS&nbsp;layer&nbsp;always&nbsp;closes&nbsp;the&nbsp;TLS&nbsp;connection&nbsp;before&nbsp;raising&nbsp;an<br>
exception,&nbsp;so&nbsp;the&nbsp;close&nbsp;operation&nbsp;will&nbsp;complete&nbsp;right&nbsp;away,&nbsp;causing<br>
asyncore.dispatcher.<a href="#TLSAsyncDispatcherMixIn-close">close</a>()&nbsp;to&nbsp;be&nbsp;called,&nbsp;which&nbsp;closes&nbsp;the&nbsp;socket<br>
and&nbsp;removes&nbsp;this&nbsp;instance&nbsp;from&nbsp;the&nbsp;asyncore&nbsp;loop.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="TLSAsyncDispatcherMixIn-__init__"><strong>__init__</strong></a>(self, sock<font color="#909090">=None</font>)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-close"><strong>close</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-handle_read"><strong>handle_read</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-handle_write"><strong>handle_write</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-outCloseEvent"><strong>outCloseEvent</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-outConnectEvent"><strong>outConnectEvent</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-outReadEvent"><strong>outReadEvent</strong></a>(self, readBuffer)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-outWriteEvent"><strong>outWriteEvent</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-readable"><strong>readable</strong></a>(self)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-recv"><strong>recv</strong></a>(self, bufferSize<font color="#909090">=16384</font>)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-send"><strong>send</strong></a>(self, writeBuffer)</dt></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-writable"><strong>writable</strong></a>(self)</dt></dl>
<hr>
Methods inherited from <a href="gdata.tlslite.integration.AsyncStateMachine.html#AsyncStateMachine">gdata.tlslite.integration.AsyncStateMachine.AsyncStateMachine</a>:<br>
<dl><dt><a name="TLSAsyncDispatcherMixIn-inReadEvent"><strong>inReadEvent</strong></a>(self)</dt><dd><tt>Tell&nbsp;the&nbsp;state&nbsp;machine&nbsp;it&nbsp;can&nbsp;read&nbsp;from&nbsp;the&nbsp;socket.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-inWriteEvent"><strong>inWriteEvent</strong></a>(self)</dt><dd><tt>Tell&nbsp;the&nbsp;state&nbsp;machine&nbsp;it&nbsp;can&nbsp;write&nbsp;to&nbsp;the&nbsp;socket.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-setCloseOp"><strong>setCloseOp</strong></a>(self)</dt><dd><tt>Start&nbsp;a&nbsp;close&nbsp;operation.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-setHandshakeOp"><strong>setHandshakeOp</strong></a>(self, handshaker)</dt><dd><tt>Start&nbsp;a&nbsp;handshake&nbsp;operation.<br>
&nbsp;<br>
@type&nbsp;handshaker:&nbsp;generator<br>
@param&nbsp;handshaker:&nbsp;A&nbsp;generator&nbsp;created&nbsp;by&nbsp;using&nbsp;one&nbsp;of&nbsp;the<br>
asynchronous&nbsp;handshake&nbsp;functions&nbsp;(i.e.&nbsp;handshakeServerAsync,&nbsp;or<br>
handshakeClientxxx(...,&nbsp;async=True).</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-setServerHandshakeOp"><strong>setServerHandshakeOp</strong></a>(self, **args)</dt><dd><tt>Start&nbsp;a&nbsp;handshake&nbsp;operation.<br>
&nbsp;<br>
The&nbsp;arguments&nbsp;passed&nbsp;to&nbsp;this&nbsp;function&nbsp;will&nbsp;be&nbsp;forwarded&nbsp;to<br>
L{tlslite.TLSConnection.TLSConnection.handshakeServerAsync}.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-setWriteOp"><strong>setWriteOp</strong></a>(self, writeBuffer)</dt><dd><tt>Start&nbsp;a&nbsp;write&nbsp;operation.<br>
&nbsp;<br>
@type&nbsp;writeBuffer:&nbsp;str<br>
@param&nbsp;writeBuffer:&nbsp;The&nbsp;string&nbsp;to&nbsp;transmit.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-wantsReadEvent"><strong>wantsReadEvent</strong></a>(self)</dt><dd><tt>If&nbsp;the&nbsp;state&nbsp;machine&nbsp;wants&nbsp;to&nbsp;read.<br>
&nbsp;<br>
If&nbsp;an&nbsp;operation&nbsp;is&nbsp;active,&nbsp;this&nbsp;returns&nbsp;whether&nbsp;or&nbsp;not&nbsp;the<br>
operation&nbsp;wants&nbsp;to&nbsp;read&nbsp;from&nbsp;the&nbsp;socket.&nbsp;&nbsp;If&nbsp;an&nbsp;operation&nbsp;is<br>
not&nbsp;active,&nbsp;this&nbsp;returns&nbsp;None.<br>
&nbsp;<br>
@rtype:&nbsp;bool&nbsp;or&nbsp;None<br>
@return:&nbsp;If&nbsp;the&nbsp;state&nbsp;machine&nbsp;wants&nbsp;to&nbsp;read.</tt></dd></dl>
<dl><dt><a name="TLSAsyncDispatcherMixIn-wantsWriteEvent"><strong>wantsWriteEvent</strong></a>(self)</dt><dd><tt>If&nbsp;the&nbsp;state&nbsp;machine&nbsp;wants&nbsp;to&nbsp;write.<br>
&nbsp;<br>
If&nbsp;an&nbsp;operation&nbsp;is&nbsp;active,&nbsp;this&nbsp;returns&nbsp;whether&nbsp;or&nbsp;not&nbsp;the<br>
operation&nbsp;wants&nbsp;to&nbsp;write&nbsp;to&nbsp;the&nbsp;socket.&nbsp;&nbsp;If&nbsp;an&nbsp;operation&nbsp;is<br>
not&nbsp;active,&nbsp;this&nbsp;returns&nbsp;None.<br>
&nbsp;<br>
@rtype:&nbsp;bool&nbsp;or&nbsp;None<br>
@return:&nbsp;If&nbsp;the&nbsp;state&nbsp;machine&nbsp;wants&nbsp;to&nbsp;write.</tt></dd></dl>
</td></tr></table></td></tr></table>
</body></html>