<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>That’s working for me as well.  I went ahead and added a do_GET
implementation to the ProxyHandler class:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>    def do_GET(self):<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>        self.send_response(200)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>        self.send_header(&quot;Content-type&quot;,
&quot;text/html&quot;)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>        self.end_headers()<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>        stdout = sys.stdout<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>        self.wfile.write('&lt;html&gt;&lt;body&gt;hi' +
str(datetime.datetime.now()) + '&lt;/body&gt;&lt;/html&gt;')<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I generated the key by doing:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>C:\OpenSSL\bin\openssl.exe req -new -x509 -days 365 -nodes -out
cert.pem -keyout cert.pem<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>And I’m able to successfully able to make requests to both
CPython and IronPython from IE and FireFox.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>So I guess the next possible questions would be what version of
Windows you’re running on and did you create the certificate on Windows (maybe
there’s some difference in OpenSSL between the two platforms?)   Also are you
using the .NET 2 version or the .NET 4 version?  Also does my end-to-end repro
demonstrate the problem for you or are you doing something different?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> users-bounces@lists.ironpython.com
[mailto:users-bounces@lists.ironpython.com] <b>On Behalf Of </b>qiuyingbo@sohu.com<br>
<b>Sent:</b> Thursday, April 22, 2010 5:40 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] ssl server mode issue<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'>I generated certificate as the
instruction of http://docs.python.org/library/ssl.html:<o:p></o:p></p>

<pre>openssl req -new -x509 -days 365 -nodes -out cert.pem -keyout cert.pem<o:p></o:p></pre>

<p class=MsoNormal style='margin-bottom:12.0pt'><br>
<br>
<o:p></o:p></p>

<div id=mailcontent>

<blockquote style='border:none;border-left:solid black 1.5pt;padding:0in 0in 0in 4.0pt;
margin-left:7.5pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<div>

<p class=MsoNormal><span style='font-size:9.0pt;font-family:"SimSun","serif"'>-----
原文 ----- <o:p></o:p></span></p>

</div>

<p class=MsoNormal style='margin-bottom:12.0pt'><span style='font-size:9.0pt;
font-family:"SimSun","serif"'><br>
<b>发件人:</b> Dino Viehland <br>
<b>主 题:</b> Re: [IronPython] ssl server mode issue<br>
<b>时 间:</b> 2010年4月23日 6:46:11<o:p></o:p></span></p>

<div>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ok,
took me a while to get back to this, but I haven’t forgotten.&nbsp; So I’ve
taken your code below and combined it with the code in test_ssl to have the
full end to end test case.&nbsp; I’ve included that here.&nbsp; Let me know if
there’s anything that’s significantly different.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>First
thing I tried w/ this was using the ‘keycert.pem’ which copes with the CPython
test case and that seemed to behave similarly between IronPython and
CPython.&nbsp; There does seem to be one difference which is with CPython the
connection from the browser stays open and w/ IronPython it closes.&nbsp; This
is after a GET request which we can’t respond to:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>DINOV1.redmond.corp.microsoft.com
- - [22/Apr/2010 15:38:16] code 501, message Unsupported method ('GET')<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>DINOV1.redmond.corp.microsoft.com
- - [22/Apr/2010 15:38:16] &quot;GET / HTTP/1.1&quot; 501 –<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>That’s
probably a bug but not the issue you’re running into but I’ve opened a bug here:
http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=26852.&nbsp; <o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So
then I generated a self-signed request as described here: <a
href="http://sial.org/howto/openssl/self-signed/" target="_blank">http://sial.org/howto/openssl/self-signed/</a>
with a .cnf file as described here: <a
href="http://bugs.gentoo.org/show_bug.cgi?id=251047" target="_blank">http://bugs.gentoo.org/show_bug.cgi?id=251047</a>
but minus the x509_extensions line.&nbsp; With that I get the same result as I
get with keycert.pem.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So
my guess is that I’m not generating the self signed certificate in the same way
that you are and that there’s something about your cert which doesn’t
work.&nbsp; Does your generation differ from what I did?<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
BaseHTTPServer<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>from
BaseHTTPServer import HTTPServer<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>from
SimpleHTTPServer import SimpleHTTPRequestHandler<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
threading<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
socket<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
sys<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
traceback<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
ssl<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>CERTFILE
= 'host.pem'<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>HOST='localhost'<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>import
time<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>class
ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def do_CONNECT(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print self.raw_requestline <o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# &quot;CONNECT twitter.com:443 HTTP/1.1&quot;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.sslhost = self.raw_requestline.split()[1]<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.wfile.write(self.protocol_version + &quot; 200 Connection
established\r\n&quot;)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.wfile.write(&quot;Proxy-agent: qiuyingbo\r\n\r\n&quot;)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.rfile = pseudofile(ssl.wrap_socket(self.connection, None, CERTFILE, True))<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.wfile = self.rfile<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.handle_one_request()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>class
SocketServerHTTPSServer(threading.Thread):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
class HTTPSServer(HTTPServer):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def __init__(self, server_address, RequestHandlerClass, certfile):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
HTTPServer.__init__(self, server_address, RequestHandlerClass)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# we assume the certfile contains both private key and certificate<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.certfile = certfile<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = False<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active_lock = threading.Lock()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.allow_reuse_address = True<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def __str__(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return ('&lt;%s %s:%s&gt;' %<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(self.__class__.__name__,<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.server_name,<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.server_port))<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def get_request (self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# override this to wrap socket with SSL<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sock, addr = self.socket.accept()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sslconn = ssl.wrap_socket(sock, server_side=True,<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&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;
certfile=self.certfile)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return sslconn, addr<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# The methods overridden below this are mainly so that we<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# can run it in a thread and be able to stop it from another<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# You probably wouldn't need them in other uses.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def server_activate(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# We want to run this in a thread for testing purposes,<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# so we override this to set timeout, so that we get<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# a chance to stop the server<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.socket.settimeout(0.5)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
HTTPServer.server_activate(self)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def serve_forever(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# We want this to run in a thread, so we use a slightly<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# modified version of &quot;forever&quot;.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = True<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
while 1:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# We need to lock while handling the request.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#
Another thread can close the socket after self.active<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# has been checked and before the request is handled.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# This causes an exception when using the closed socket.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
with self.active_lock:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if not self.active:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&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;
break<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.handle_request()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
except socket.timeout:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pass<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
except KeyboardInterrupt:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;self.server_close()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
except:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sys.stdout.write(''.join(traceback.format_exception(*sys.exc_info())))<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
break<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
time.sleep(0.1)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
def server_close(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# Again, we want this to run in a thread, so we need to override<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# close to clear the &quot;active&quot; flag, so that serve_forever() will<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# terminate.<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
with self.active_lock:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
HTTPServer.server_close(self)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = False<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def __init__(self, certfile):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.flag = None<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = False<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.port = 1234<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.server = self.HTTPSServer(<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(HOST, self.port), ProxyHandler, certfile)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
threading.Thread.__init__(self)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.daemon = True<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def __str__(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return &quot;&lt;%s %s&gt;&quot; % (self.__class__.__name__, self.server)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def start (self, flag=None):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.flag = flag<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;threading.Thread.start(self)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def run (self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = True<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if self.flag:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.flag.set()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.server.serve_forever()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = False<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def stop (self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.active = False<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.server.server_close()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>class
pseudofile():<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
''' SSL Pseudo File Object'''<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def __init__(self, sslobj):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.sslobj = sslobj<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.closed = 0<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def read(self, size):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
chunks = []<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
read = 0<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
while read &lt; size:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
data = self.sslobj.read(size-read)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
read += len(data)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
chunks.append(data)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return ''.join(chunks)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def readline(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
line = []<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
while 1:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
char = self.sslobj.read(1)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line.append(char)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if char == &quot;\n&quot;: return ''.join(line)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def write(self, data):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bytes = len(data)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
while bytes &gt; 0:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sent = self.sslobj.write(data)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if sent == bytes:<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
break&nbsp;&nbsp;&nbsp; # avoid copy<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
data = data[sent:]<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bytes = bytes - sent<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
def flush(self):<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
pass<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;&nbsp;&nbsp;
close = flush<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>server=SocketServerHTTPSServer(CERTFILE)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>flag
= threading.Event()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>server.start(flag)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>#
wait for it to start<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>flag.wait()<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>print
'started'<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>time.sleep(100000)<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>&nbsp;<o:p></o:p></span></p>

<div style='border:none;border-left:solid windowtext 1.5pt;padding:0in 0in 0in 4.0pt;
border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color blue'>

<div>

<div>

<div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0in 0in 0in;
border-color:-moz-use-text-color -moz-use-text-color'>

<p><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> users-bounces@lists.ironpython.com
[mailto:users-bounces@lists.ironpython.com] <b>On Behalf Of </b>qiuyingbo@sohu.com<br>
<b>Sent:</b> Wednesday, April 14, 2010 5:41 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] ssl server mode issue<o:p></o:p></span></p>

</div>

</div>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>I'm doing a web
browser to ironpython connection. It is&nbsp;difficult to explain what I am
doing,&nbsp; I'm hacking a http proxy that inherit
BaseHTTPServer.BaseHTTPRequestHandler. Next code snippets show how I support
HTTPS proxy.. (Linux version run well)<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>class
ProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;&nbsp;&nbsp;
def do_CONNECT(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # print self.raw_requestline <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # &quot;CONNECT twitter.com:443
HTTP/1.1&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.sslhost =
self.raw_requestline.split()[1]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
self.wfile.write(self.protocol_version + &quot; 200 Connection
established\r\n&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.wfile.write(&quot;Proxy-agent:
qiuyingbo\r\n\r\n&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; import ssl<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.rfile =
pseudofile(ssl.wrap_socket(self.connection, None, CERTFILE, True))<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.wfile = self.rfile<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.handle_one_request()<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>class
pseudofile():<br>
&nbsp;&nbsp;&nbsp; ''' SSL Pseudo File Object'''<br>
&nbsp;&nbsp;&nbsp; def __init__(self, sslobj):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.sslobj = sslobj<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.closed = 0<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;&nbsp;&nbsp;
def read(self, size):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chunks = []<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read = 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while read &lt; size:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data =
self.sslobj.read(size-read)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; read +=
len(data)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
chunks.append(data)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ''.join(chunks)<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;&nbsp;&nbsp;
def readline(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line = []<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while 1:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char =
self.sslobj.read(1)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
line.append(char)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if char ==
&quot;\n&quot;: return ''.join(line)<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;&nbsp;&nbsp;
def write(self, data):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bytes = len(data)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while bytes &gt; 0:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sent =
self.sslobj.write(data)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if sent ==
bytes:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
break&nbsp;&nbsp;&nbsp; # avoid copy<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; data =
data[sent:]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bytes =
bytes - sent<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'><br>
&nbsp;&nbsp;&nbsp; def flush(self):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<o:p></o:p></span></p>

<p><span style='font-size:9.0pt;font-family:"SimSun","serif"'>&nbsp;&nbsp;&nbsp;
close = flush<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><span style='font-size:9.0pt;font-family:"SimSun","serif"'><br>
_______________________________________________<br>
Users mailing list<br>
Users@lists.ironpython.com<br>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com<o:p></o:p></span></p>

</div>

</blockquote>

</div>

</div>

</div>

</body>

</html>