Popular recipes by Sebastien Martini http://code.activestate.com/recipes/users/2637141/2010-10-17T15:17:44-07:00ActiveState Code RecipesSimple HTTP server supporting SSL secure communications (Python) 2008-08-02T16:04:56-07:00Sebastien Martinihttp://code.activestate.com/recipes/users/2637141/http://code.activestate.com/recipes/442473-simple-http-server-supporting-ssl-secure-communica/ <p style="color: grey"> Python recipe 442473 by <a href="/recipes/users/2637141/">Sebastien Martini</a> (<a href="/recipes/tags/https/">https</a>, <a href="/recipes/tags/openssl/">openssl</a>, <a href="/recipes/tags/ssl/">ssl</a>, <a href="/recipes/tags/web/">web</a>). Revision 8. </p> <p>This recipe describes how to set up a simple HTTP server supporting SSL secure communications. It extends the SimpleHTTPServer standard module to support the SSL protocol. With this recipe, only the server is authenticated while the client remains unauthenticated (i.e. the server will not request a client certificate). Thus, the client (typically the browser) will be able to verify the server identity and secure its communications with the server.</p> <p>This recipe requires you already know the basis of SSL and how to set up <a href="http://www.openssl.org">OpenSSL</a>. This recipe is mostly derived from the examples provided with the <a href="http://pyopenssl.sourceforge.net">pyOpenSSL</a> package.</p> <h5>In order to apply this recipe, follow these few steps:</h5> <ol> <li>Install the OpenSSL package in order to generate key and certificate. Note: you probably already have this package installed if you are under Linux, or *BSD.</li> <li>Install the pyOpenSSL package, it is an OpenSSL library binding. You'll need to import this module for accessing OpenSSL's components.</li> <li>Generate a self-signed certificate compounded of a certificate and a private key for your server with the following command (it outputs them both in a single file named server.pem): <code>openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes</code></li> <li>Assuming you saved this recipe in SimpleSecureHTTPServer.py, start the server (with the appropriate rights): <code>python SimpleSecureHTTPServer.py</code></li> <li>Finally, browse to <a href="https://localhost">https://localhost</a>, or <a href="https://localhost:port" rel="nofollow">https://localhost:port</a> if your server listens a different port than 443.</li> </ol> Generating Code Coverage HTML Output (Python) 2010-10-17T15:17:44-07:00Sebastien Martinihttp://code.activestate.com/recipes/users/2637141/http://code.activestate.com/recipes/491274-generating-code-coverage-html-output/ <p style="color: grey"> Python recipe 491274 by <a href="/recipes/users/2637141/">Sebastien Martini</a> (<a href="/recipes/tags/coverage/">coverage</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/html/">html</a>). Revision 11. </p> <p>Code coverage testing is very useful especially for dynamic languages, it can easily give a view of the unused parts of your code. Not that this method is able to prove that statements are dead code, but instead help to prevent from syntax errors and to force yourself to think about your code, to find the right test cases reaching the unused statements.</p> <p>In that sense, the module <a href="http://www.nedbatchelder.com/code/modules/coverage.py">coverage.py</a> made by <a href="http://www.nedbatchelder.com">Ned Batchelder</a> is very useful and efficient.</p> <p>The analysis returned by this module is very accurate, but as unreached lines numbers are not very readable by itself, this recipe simply generate an html output highlighting unreached lines. This recipe is directely based upon a <a href="http://chrisarndt.de/en/software/python/colorize.html">source code colorizer</a> derived from <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298">this</a> recipe.</p>