Differences between revisions 15 and 16
Revision 15 as of 2012-04-15 19:42:47
Size: 19415
Editor: sto93-h01-31-33-194-28
Comment:
Revision 16 as of 2012-04-15 19:54:19
Size: 4693
Editor: PaulBoddie
Comment: Revert vandalism.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
REMARK Molecular Alignment Simulation. = BaseHTTPServer =
Line 3: Line 3:
REMARK Simulation parameters. You can use this to make a simple HTTP web server.
Line 5: Line 5:
DATA PALES_MODE STERIC <<TableOfContents>>
Line 7: Line 7:
DATA PALES LC_TYPE wall
DATA PALES LC_CONCENTRATION 0.050
DATA PALES ORIENT_SPHERE 100
DATA PALES ORIENT_PSI 18
DATA PALES GRID_SPACING 0.200
DATA PALES MODEL_RADIUS 20.000
DATA PALES LC_ORDER 0.800
DATA PALES ATOM_RADIUS 0.000
DATA PALES SEL_SIMPLE_FLAG 0
DATA PALES SURF_FLAG 1
== Official Documentation ==

 * [[http://docs.python.org/lib/module-BaseHTTPServer.html|BaseHTTPServer module documentation]] - what we use directly
 * [[http://docs.python.org/lib/module-SocketServer.html|SocketServer module documentation]] - behind the BaseHttpServer

== Example Code ==

=== Responding with an HTML Page ===

{{{
#!python
import time
import BaseHTTPServer
Line 19: Line 22:
REMARK Order matrix.

DATA SAUPE 4.2576e-04 8.7422e-04 -1.9599e-04 7.0604e-04 -2.3539e-04

DATA IRREDUCIBLE REPRESENTATION (A0,A1R,A1I,A2R,A2I) 1.4527e+01 -1.9670e+01 -6.5579e+00 1.2178e+01 5.4603e+00
DATA IRREDUCIBLE GENERAL_MAGNITUDE 3.7777e+01
HOST_NAME = 'example.net' # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 80 # Maybe set this to 9000.
Line 27: Line 26:
REMARK Eigensystem & Euler angles for clockwise rotation about z, y', z''. class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_HEAD(s):
        s.send_response(200)
        s.send_header("Content-type", "text/html")
        s.end_headers()
    def do_GET(s):
        """Respond to a GET request."""
        s.send_response(200)
        s.send_header("Content-type", "text/html")
        s.end_headers()
        s.wfile.write("<html><head><title>Title goes here.</title></head>")
        s.wfile.write("<body><p>This is a test.</p>")
        # If someone went to "http://something.somewhere.net/foo/bar/",
        # then s.path equals "/foo/bar/".
        s.wfile.write("<p>You accessed path: %s</p>" % s.path)
        s.wfile.write("</body></html>")
Line 29: Line 43:
DATA EIGENVALUES (Axx,Ayy,Azz) -3.8808e-04 -7.0394e-04 1.0920e-03
DATA EIGENVECTORS
DATA EIGENVECTORS XAXIS 7.5792e-01 1.8876e-02 -6.5207e-01
DATA EIGENVECTORS YAXIS 9.8850e-02 9.8472e-01 1.4340e-01
DATA EIGENVECTORS ZAXIS 6.4481e-01 -1.7314e-01 7.4447e-01
if __name__ == '__main__':
    server_class = BaseHTTPServer.HTTPServer
    httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
    print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
}}}
Line 35: Line 55:
DATA Q_EULER_SOLUTIONS ALPHA BETA GAMMA
DATA Q_EULER_ANGLES 1 167.60 41.89 195.03
DATA Q_EULER_ANGLES 2 347.60 41.89 195.03
DATA Q_EULER_ANGLES 3 12.40 138.11 15.03
DATA Q_EULER_ANGLES 4 192.40 138.11 15.03
=== Responding with URL Redirection ===

This code demonstrates simple URL redirection:

{{{
#!python
"""
URL redirection example.
"""

import BaseHTTPServer
import time
import sys
Line 42: Line 70:
REMARK Euler angles (psi/theta/phi) for rotation about x, y, z. HOST_NAME = 'example.net' # !!!REMEMBER TO CHANGE THIS!!!
PORT_NUMBER = 80 # Maybe set this to 9000.
REDIRECTIONS = {"/slashdot/": "http://slashdot.org/",
                "/freshmeat/": "http://freshmeat.net/"}
LAST_RESORT = "http://google.com/"
Line 44: Line 76:
DATA EULER_SOLUTIONS 2
DATA EULER_ANGLES -13.09 -40.15 7.43
DATA EULER_ANGLES 166.91 220.15 187.43
class RedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_HEAD(s):
        s.send_response(301)
        s.send_header("Location", REDIRECTIONS.get(s.path, LAST_RESORT))
        s.end_headers()
    def do_GET(s):
        s.do_HEAD()
Line 48: Line 84:
DATA Da 5.460104e-04
DATA Dr 1.052881e-04
if __name__ == '__main__':
    server_class = BaseHTTPServer.HTTPServer
    httpd = server_class((HOST_NAME, PORT_NUMBER), RedirectHandler)
    print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)
}}}
Line 51: Line 96:
== Parameterizing ==
Line 52: Line 98:
REMARK Dipolar couplings. When you want to make your server respect some parameters, it's easiest to do so via the ''server,'' rather than the ''handler.''
Line 54: Line 100:
DATA N 204
DATA RMS 23.350
DATA Chi2 111227.539
DATA CORR R 0.000
DATA CORNILESCU Q 0.000
DATA REGRESSION OFFSET nan +/- nan [Hz]
DATA REGRESSION SLOPE nan +/- nan [Hz]
DATA REGRESSION BAX SLOPE 0.000 +/- 0.000 [Hz]
That is, make a subclass of the server, that accepts some additional parameters. Have the server record those parameters.
Line 63: Line 102:
VARS RESID_I RESNAME_I ATOMNAME_I RESID_J RESNAME_J ATOMNAME_J DI D_OBS D D_DIFF DD W
FORMAT %4d %4s %4s %4d %4s %4s %9.2f %9.3f %9.3f %9.3f %.2f %.2f
Then, in the handler, use {{{s.server}}} to get to the server, and access the parameters through it.
Line 66: Line 104:
    1 DC C6 1 DC H6 48034.72 0.0000 -13.0777 13.0777 1.0000 1.00
    2 DG C8 2 DG H8 47935.51 0.0000 -18.1723 18.1723 1.0000 1.00
    3 DC C6 3 DC H6 48003.32 0.0000 -14.5739 14.5739 1.0000 1.00
    4 DA C8 4 DA H8 48019.80 0.0000 8.5285 -8.5285 1.0000 1.00
    5 DC C6 5 DC H6 47905.83 0.0000 44.3661 -44.3661 1.0000 1.00
    6 DG C8 6 DG H8 47923.18 0.0000 49.2634 -49.2634 1.0000 1.00
    7 DT C6 7 DT H6 47987.81 0.0000 3.1808 -3.1808 1.0000 1.00
    8 DA C8 8 DA H8 47962.53 0.0000 -23.0739 23.0739 1.0000 1.00
    9 DC C6 9 DC H6 48011.41 0.0000 -19.3974 19.3974 1.0000 1.00
   10 DG C8 10 DG H8 47952.43 0.0000 -5.5175 5.5175 1.0000 1.00
   11 DC C6 11 DC H6 47975.36 0.0000 28.5141 -28.5141 1.0000 1.00
   12 DG C8 12 DG H8 47989.86 0.0000 19.3519 -19.3519 1.0000 1.00
   13 DC C6 13 DC H6 47984.04 0.0000 -20.1162 20.1162 1.0000 1.00
   14 DG C8 14 DG H8 47922.48 0.0000 16.7200 -16.7200 1.0000 1.00
   15 DC C6 15 DC H6 48011.71 0.0000 18.4095 -18.4095 1.0000 1.00
   16 DG C8 16 DG H8 47883.14 0.0000 -6.5866 6.5866 1.0000 1.00
   17 DT C6 17 DT H6 47896.27 0.0000 -32.0341 32.0341 1.0000 1.00
   18 DA C8 18 DA H8 47950.29 0.0000 -20.2824 20.2824 1.0000 1.00
   19 DC C6 19 DC H6 47985.25 0.0000 16.5687 -16.5687 1.0000 1.00
   20 DG C8 20 DG H8 47942.03 0.0000 50.0871 -50.0871 1.0000 1.00
   21 DT C6 21 DT H6 47985.55 0.0000 27.4519 -27.4519 1.0000 1.00
   22 DG C8 22 DG H8 48034.02 0.0000 0.1400 -0.1400 1.0000 1.00
   23 DC C6 23 DC H6 47981.99 0.0000 -23.8438 23.8438 1.0000 1.00
   24 DG C8 24 DG H8 47900.84 0.0000 -15.5709 15.5709 1.0000 1.00
    1 DC C5 1 DC H5 47918.23 0.0000 -5.2517 5.2517 1.0000 1.00
    3 DC C5 3 DC H5 47889.37 0.0000 10.9592 -10.9592 1.0000 1.00
    5 DC C5 5 DC H5 47948.18 0.0000 -26.5440 26.5440 1.0000 1.00
    9 DC C5 9 DC H5 48105.39 0.0000 -3.7114 3.7114 1.0000 1.00
   11 DC C5 11 DC H5 48007.43 0.0000 -26.2035 26.2035 1.0000 1.00
   13 DC C5 13 DC H5 47860.52 0.0000 -0.8109 0.8109 1.0000 1.00
   15 DC C5 15 DC H5 47890.40 0.0000 6.9953 -6.9953 1.0000 1.00
   19 DC C5 19 DC H5 48032.95 0.0000 -29.4635 29.4635 1.0000 1.00
   23 DC C5 23 DC H5 47949.05 0.0000 25.8265 -25.8265 1.0000 1.00
    4 DA C2 4 DA H2 47963.97 0.0000 -22.2942 22.2942 1.0000 1.00
    8 DA C2 8 DA H2 48032.10 0.0000 15.6144 -15.6144 1.0000 1.00
   18 DA C2 18 DA H2 47963.04 0.0000 -22.2331 22.2331 1.0000 1.00
    1 DC C1' 1 DC H1' 46678.34 0.0000 -24.0873 24.0873 1.0000 1.00
    2 DG C1' 2 DG H1' 46607.04 0.0000 36.5069 -36.5069 1.0000 1.00
    3 DC C1' 3 DC H1' 46612.36 0.0000 2.7156 -2.7156 1.0000 1.00
    4 DA C1' 4 DA H1' 46538.55 0.0000 -27.8184 27.8184 1.0000 1.00
    5 DC C1' 5 DC H1' 46567.89 0.0000 -13.2531 13.2531 1.0000 1.00
    6 DG C1' 6 DG H1' 46677.38 0.0000 26.9539 -26.9539 1.0000 1.00
    7 DT C1' 7 DT H1' 46680.67 0.0000 50.5952 -50.5952 1.0000 1.00
    8 DA C1' 8 DA H1' 46682.11 0.0000 22.0260 -22.0260 1.0000 1.00
    9 DC C1' 9 DC H1' 46577.24 0.0000 -21.5641 21.5641 1.0000 1.00
   10 DG C1' 10 DG H1' 46638.79 0.0000 -19.3871 19.3871 1.0000 1.00
   11 DC C1' 11 DC H1' 46733.75 0.0000 -20.5240 20.5240 1.0000 1.00
   12 DG C1' 12 DG H1' 46649.77 0.0000 42.6278 -42.6278 1.0000 1.00
   13 DC C1' 13 DC H1' 46687.34 0.0000 -31.5306 31.5306 1.0000 1.00
   14 DG C1' 14 DG H1' 46588.79 0.0000 -10.2085 10.2085 1.0000 1.00
   15 DC C1' 15 DC H1' 46706.29 0.0000 17.5348 -17.5348 1.0000 1.00
   16 DG C1' 16 DG H1' 46549.16 0.0000 39.4927 -39.4927 1.0000 1.00
   17 DT C1' 17 DT H1' 46734.80 0.0000 12.9308 -12.9308 1.0000 1.00
   18 DA C1' 18 DA H1' 46602.57 0.0000 -32.1779 32.1779 1.0000 1.00
   19 DC C1' 19 DC H1' 46620.64 0.0000 -22.6075 22.6075 1.0000 1.00
   20 DG C1' 20 DG H1' 46631.06 0.0000 9.1467 -9.1467 1.0000 1.00
   21 DT C1' 21 DT H1' 46646.71 0.0000 41.6149 -41.6149 1.0000 1.00
   22 DG C1' 22 DG H1' 46717.27 0.0000 22.2796 -22.2796 1.0000 1.00
   23 DC C1' 23 DC H1' 46618.82 0.0000 1.9396 -1.9396 1.0000 1.00
   24 DG C1' 24 DG H1' 46690.14 0.0000 -32.5276 32.5276 1.0000 1.00
    1 DC C2' 1 DC 1H2' 46614.33 0.0000 -1.8716 1.8716 1.0000 1.00
    2 DG C2' 2 DG 1H2' 46620.42 0.0000 34.3554 -34.3554 1.0000 1.00
    3 DC C2' 3 DC 1H2' 46588.53 0.0000 -17.5063 17.5063 1.0000 1.00
    4 DA C2' 4 DA 1H2' 46655.97 0.0000 -15.7506 15.7506 1.0000 1.00
    5 DC C2' 5 DC 1H2' 46552.43 0.0000 -18.2820 18.2820 1.0000 1.00
    6 DG C2' 6 DG 1H2' 46727.87 0.0000 15.0926 -15.0926 1.0000 1.00
    7 DT C2' 7 DT 1H2' 46553.44 0.0000 48.9890 -48.9890 1.0000 1.00
    8 DA C2' 8 DA 1H2' 46688.87 0.0000 34.8586 -34.8586 1.0000 1.00
    9 DC C2' 9 DC 1H2' 46641.70 0.0000 -0.8779 0.8779 1.0000 1.00
   10 DG C2' 10 DG 1H2' 46604.23 0.0000 -15.9395 15.9395 1.0000 1.00
   11 DC C2' 11 DC 1H2' 46536.85 0.0000 -22.9918 22.9918 1.0000 1.00
   12 DG C2' 12 DG 1H2' 46673.59 0.0000 42.4215 -42.4215 1.0000 1.00
   13 DC C2' 13 DC 1H2' 46644.80 0.0000 -30.1579 30.1579 1.0000 1.00
   14 DG C2' 14 DG 1H2' 46666.69 0.0000 -22.9781 22.9781 1.0000 1.00
   15 DC C2' 15 DC 1H2' 46725.28 0.0000 -17.7358 17.7358 1.0000 1.00
   16 DG C2' 16 DG 1H2' 46655.08 0.0000 21.5235 -21.5235 1.0000 1.00
   17 DT C2' 17 DT 1H2' 46688.56 0.0000 13.7654 -13.7654 1.0000 1.00
   18 DA C2' 18 DA 1H2' 46662.86 0.0000 -26.6324 26.6324 1.0000 1.00
   19 DC C2' 19 DC 1H2' 46599.68 0.0000 -23.9353 23.9353 1.0000 1.00
   20 DG C2' 20 DG 1H2' 46652.71 0.0000 -18.6270 18.6270 1.0000 1.00
   21 DT C2' 21 DT 1H2' 46695.61 0.0000 38.0929 -38.0929 1.0000 1.00
   22 DG C2' 22 DG 1H2' 46627.51 0.0000 42.5315 -42.5315 1.0000 1.00
   23 DC C2' 23 DC 1H2' 46622.37 0.0000 27.0295 -27.0295 1.0000 1.00
   24 DG C2' 24 DG 1H2' 46757.21 0.0000 -31.8798 31.8798 1.0000 1.00
    1 DC C2' 1 DC 2H2' 46727.61 0.0000 17.0814 -17.0814 1.0000 1.00
    2 DG C2' 2 DG 2H2' 46730.74 0.0000 3.5882 -3.5882 1.0000 1.00
    3 DC C2' 3 DC 2H2' 46678.76 0.0000 -29.6546 29.6546 1.0000 1.00
    4 DA C2' 4 DA 2H2' 46623.77 0.0000 -32.0720 32.0720 1.0000 1.00
    5 DC C2' 5 DC 2H2' 46727.52 0.0000 -18.9770 18.9770 1.0000 1.00
    6 DG C2' 6 DG 2H2' 46637.30 0.0000 -18.9610 18.9610 1.0000 1.00
    7 DT C2' 7 DT 2H2' 46718.25 0.0000 -1.5252 1.5252 1.0000 1.00
    8 DA C2' 8 DA 2H2' 46675.42 0.0000 -3.8332 3.8332 1.0000 1.00
    9 DC C2' 9 DC 2H2' 46661.56 0.0000 -17.9823 17.9823 1.0000 1.00
   10 DG C2' 10 DG 2H2' 46583.82 0.0000 9.6197 -9.6197 1.0000 1.00
   11 DC C2' 11 DC 2H2' 46587.41 0.0000 28.8337 -28.8337 1.0000 1.00
   12 DG C2' 12 DG 2H2' 46564.12 0.0000 9.9391 -9.9391 1.0000 1.00
   13 DC C2' 13 DC 2H2' 46708.62 0.0000 11.4080 -11.4080 1.0000 1.00
   14 DG C2' 14 DG 2H2' 46545.30 0.0000 -2.2613 2.2613 1.0000 1.00
   15 DC C2' 15 DC 2H2' 46711.34 0.0000 31.0643 -31.0643 1.0000 1.00
   16 DG C2' 16 DG 2H2' 46614.62 0.0000 26.2774 -26.2774 1.0000 1.00
   17 DT C2' 17 DT 2H2' 46627.40 0.0000 9.0513 -9.0513 1.0000 1.00
   18 DA C2' 18 DA 2H2' 46565.66 0.0000 -13.8747 13.8747 1.0000 1.00
   19 DC C2' 19 DC 2H2' 46681.01 0.0000 -22.1716 22.1716 1.0000 1.00
   20 DG C2' 20 DG 2H2' 46658.24 0.0000 -13.4434 13.4434 1.0000 1.00
   21 DT C2' 21 DT 2H2' 46625.14 0.0000 -8.2833 8.2833 1.0000 1.00
   22 DG C2' 22 DG 2H2' 46617.89 0.0000 -27.0175 27.0175 1.0000 1.00
   23 DC C2' 23 DC 2H2' 46625.43 0.0000 -6.2558 6.2558 1.0000 1.00
   24 DG C2' 24 DG 2H2' 46678.48 0.0000 -3.6492 3.6492 1.0000 1.00
    1 DC C3' 1 DC H3' 46711.03 0.0000 -27.3501 27.3501 1.0000 1.00
    2 DG C3' 2 DG H3' 46589.89 0.0000 -16.4355 16.4355 1.0000 1.00
    3 DC C3' 3 DC H3' 46630.14 0.0000 -12.8839 12.8839 1.0000 1.00
    4 DA C3' 4 DA H3' 46552.02 0.0000 -1.9470 1.9470 1.0000 1.00
    5 DC C3' 5 DC H3' 46628.75 0.0000 40.4405 -40.4405 1.0000 1.00
    6 DG C3' 6 DG H3' 46671.91 0.0000 49.5637 -49.5637 1.0000 1.00
    7 DT C3' 7 DT H3' 46701.99 0.0000 13.0959 -13.0959 1.0000 1.00
    8 DA C3' 8 DA H3' 46768.04 0.0000 -8.3106 8.3106 1.0000 1.00
    9 DC C3' 9 DC H3' 46680.47 0.0000 -31.3006 31.3006 1.0000 1.00
   10 DG C3' 10 DG H3' 46726.38 0.0000 -3.8781 3.8781 1.0000 1.00
   11 DC C3' 11 DC H3' 46690.12 0.0000 1.0762 -1.0762 1.0000 1.00
   12 DG C3' 12 DG H3' 46620.00 0.0000 8.0789 -8.0789 1.0000 1.00
   13 DC C3' 13 DC H3' 46660.29 0.0000 -6.6952 6.6952 1.0000 1.00
   14 DG C3' 14 DG H3' 46612.28 0.0000 -3.2914 3.2914 1.0000 1.00
   15 DC C3' 15 DC H3' 46706.95 0.0000 16.7559 -16.7559 1.0000 1.00
   16 DG C3' 16 DG H3' 46686.25 0.0000 -11.9232 11.9232 1.0000 1.00
   17 DT C3' 17 DT H3' 46695.06 0.0000 -30.0259 30.0259 1.0000 1.00
   18 DA C3' 18 DA H3' 46639.35 0.0000 -13.0623 13.0623 1.0000 1.00
   19 DC C3' 19 DC H3' 46538.62 0.0000 14.8239 -14.8239 1.0000 1.00
   20 DG C3' 20 DG H3' 46598.48 0.0000 40.6086 -40.6086 1.0000 1.00
   21 DT C3' 21 DT H3' 46666.58 0.0000 39.7183 -39.7183 1.0000 1.00
   22 DG C3' 22 DG H3' 46644.66 0.0000 -7.8843 7.8843 1.0000 1.00
   23 DC C3' 23 DC H3' 46672.36 0.0000 -15.6135 15.6135 1.0000 1.00
   24 DG C3' 24 DG H3' 46643.85 0.0000 15.6607 -15.6607 1.0000 1.00
    1 DC C4' 1 DC H4' 46660.84 0.0000 0.7914 -0.7914 1.0000 1.00
    2 DG C4' 2 DG H4' 46704.86 0.0000 -22.0625 22.0625 1.0000 1.00
    3 DC C4' 3 DC H4' 46596.43 0.0000 7.6047 -7.6047 1.0000 1.00
    4 DA C4' 4 DA H4' 46659.06 0.0000 7.5683 -7.5683 1.0000 1.00
    5 DC C4' 5 DC H4' 46730.51 0.0000 -23.6826 23.6826 1.0000 1.00
    6 DG C4' 6 DG H4' 46699.70 0.0000 -20.2128 20.2128 1.0000 1.00
    7 DT C4' 7 DT H4' 46698.63 0.0000 43.7326 -43.7326 1.0000 1.00
    8 DA C4' 8 DA H4' 46567.85 0.0000 27.3535 -27.3535 1.0000 1.00
    9 DC C4' 9 DC H4' 46708.69 0.0000 24.4165 -24.4165 1.0000 1.00
   10 DG C4' 10 DG H4' 46601.06 0.0000 -29.8615 29.8615 1.0000 1.00
   11 DC C4' 11 DC H4' 46596.84 0.0000 -25.0758 25.0758 1.0000 1.00
   12 DG C4' 12 DG H4' 46644.95 0.0000 1.9614 -1.9614 1.0000 1.00
   13 DC C4' 13 DC H4' 46619.88 0.0000 -23.5206 23.5206 1.0000 1.00
   14 DG C4' 14 DG H4' 46663.60 0.0000 6.1405 -6.1405 1.0000 1.00
   15 DC C4' 15 DC H4' 46601.46 0.0000 6.4856 -6.4856 1.0000 1.00
   16 DG C4' 16 DG H4' 46621.27 0.0000 -7.1985 7.1985 1.0000 1.00
   17 DT C4' 17 DT H4' 46576.48 0.0000 14.1346 -14.1346 1.0000 1.00
   18 DA C4' 18 DA H4' 46672.06 0.0000 -16.4342 16.4342 1.0000 1.00
   19 DC C4' 19 DC H4' 46707.55 0.0000 -26.6735 26.6735 1.0000 1.00
   20 DG C4' 20 DG H4' 46666.92 0.0000 -15.2722 15.2722 1.0000 1.00
   21 DT C4' 21 DT H4' 46605.06 0.0000 9.1372 -9.1372 1.0000 1.00
   22 DG C4' 22 DG H4' 46661.79 0.0000 42.8112 -42.8112 1.0000 1.00
   23 DC C4' 23 DC H4' 46720.48 0.0000 23.1455 -23.1455 1.0000 1.00
   24 DG C4' 24 DG H4' 46703.96 0.0000 -16.2037 16.2037 1.0000 1.00
    1 DC C5' 1 DC 1H5' 46647.08 0.0000 31.9693 -31.9693 1.0000 1.00
    2 DG C5' 2 DG 1H5' 46667.49 0.0000 -16.6545 16.6545 1.0000 1.00
    3 DC C5' 3 DC 1H5' 46590.52 0.0000 -9.7718 9.7718 1.0000 1.00
    4 DA C5' 4 DA 1H5' 46569.33 0.0000 -15.3518 15.3518 1.0000 1.00
    5 DC C5' 5 DC 1H5' 46642.15 0.0000 -5.4502 5.4502 1.0000 1.00
    6 DG C5' 6 DG 1H5' 46573.20 0.0000 -24.3920 24.3920 1.0000 1.00
    7 DT C5' 7 DT 1H5' 46658.29 0.0000 -22.6218 22.6218 1.0000 1.00
    8 DA C5' 8 DA 1H5' 46562.72 0.0000 -16.8916 16.8916 1.0000 1.00
    9 DC C5' 9 DC 1H5' 46634.49 0.0000 -23.5610 23.5610 1.0000 1.00
   10 DG C5' 10 DG 1H5' 46586.50 0.0000 -16.5543 16.5543 1.0000 1.00
   11 DC C5' 11 DC 1H5' 46574.59 0.0000 -6.9404 6.9404 1.0000 1.00
   12 DG C5' 12 DG 1H5' 46770.08 0.0000 -11.6388 11.6388 1.0000 1.00
   13 DC C5' 13 DC 1H5' 46695.15 0.0000 -10.8270 10.8270 1.0000 1.00
   14 DG C5' 14 DG 1H5' 46689.21 0.0000 -26.6802 26.6802 1.0000 1.00
   15 DC C5' 15 DC 1H5' 46710.30 0.0000 -20.5535 20.5535 1.0000 1.00
   16 DG C5' 16 DG 1H5' 46677.35 0.0000 -7.7568 7.7568 1.0000 1.00
   17 DT C5' 17 DT 1H5' 46667.90 0.0000 0.7330 -0.7330 1.0000 1.00
   18 DA C5' 18 DA 1H5' 46713.38 0.0000 2.6656 -2.6656 1.0000 1.00
   19 DC C5' 19 DC 1H5' 46653.14 0.0000 -9.9041 9.9041 1.0000 1.00
   20 DG C5' 20 DG 1H5' 46653.57 0.0000 -5.8476 5.8476 1.0000 1.00
   21 DT C5' 21 DT 1H5' 46524.77 0.0000 -18.7257 18.7257 1.0000 1.00
   22 DG C5' 22 DG 1H5' 46572.84 0.0000 -19.7295 19.7295 1.0000 1.00
   23 DC C5' 23 DC 1H5' 46562.55 0.0000 -24.1350 24.1350 1.0000 1.00
   24 DG C5' 24 DG 1H5' 46616.07 0.0000 -17.9539 17.9539 1.0000 1.00
    1 DC C5' 1 DC 2H5' 46731.02 0.0000 -25.8512 25.8512 1.0000 1.00
    2 DG C5' 2 DG 2H5' 46698.32 0.0000 -11.5298 11.5298 1.0000 1.00
    3 DC C5' 3 DC 2H5' 46656.72 0.0000 40.4805 -40.4805 1.0000 1.00
    4 DA C5' 4 DA 2H5' 46706.19 0.0000 49.8524 -49.8524 1.0000 1.00
    5 DC C5' 5 DC 2H5' 46592.44 0.0000 16.8546 -16.8546 1.0000 1.00
    6 DG C5' 6 DG 2H5' 46781.54 0.0000 -0.2777 0.2777 1.0000 1.00
    7 DT C5' 7 DT 2H5' 46714.99 0.0000 -24.5367 24.5367 1.0000 1.00
    8 DA C5' 8 DA 2H5' 46681.64 0.0000 21.0940 -21.0940 1.0000 1.00
    9 DC C5' 9 DC 2H5' 46620.64 0.0000 32.0182 -32.0182 1.0000 1.00
   10 DG C5' 10 DG 2H5' 46670.44 0.0000 22.6234 -22.6234 1.0000 1.00
   11 DC C5' 11 DC 2H5' 46621.38 0.0000 14.5520 -14.5520 1.0000 1.00
   12 DG C5' 12 DG 2H5' 46662.86 0.0000 -30.4310 30.4310 1.0000 1.00
   13 DC C5' 13 DC 2H5' 46723.88 0.0000 13.8819 -13.8819 1.0000 1.00
   14 DG C5' 14 DG 2H5' 46636.35 0.0000 45.2923 -45.2923 1.0000 1.00
   15 DC C5' 15 DC 2H5' 46616.35 0.0000 -29.0932 29.0932 1.0000 1.00
   16 DG C5' 16 DG 2H5' 46670.20 0.0000 -30.7160 30.7160 1.0000 1.00
   17 DT C5' 17 DT 2H5' 46749.46 0.0000 14.6032 -14.6032 1.0000 1.00
   18 DA C5' 18 DA 2H5' 46629.32 0.0000 36.5291 -36.5291 1.0000 1.00
   19 DC C5' 19 DC 2H5' 46700.12 0.0000 28.1904 -28.1904 1.0000 1.00
   20 DG C5' 20 DG 2H5' 46651.81 0.0000 -14.4819 14.4819 1.0000 1.00
   21 DT C5' 21 DT 2H5' 46711.25 0.0000 -30.1249 30.1249 1.0000 1.00
   22 DG C5' 22 DG 2H5' 46687.96 0.0000 -11.8919 11.8919 1.0000 1.00
   23 DC C5' 23 DC 2H5' 46668.42 0.0000 31.8699 -31.8699 1.0000 1.00
   24 DG C5' 24 DG 2H5' 46613.90 0.0000 38.0481 -38.0481 1.0000 1.00
== See Also ==

 * DocXmlRpcServer -- self-documenting XML-RPC servers
 * CgiScripts -- using invoked CGI scripts, rather than running micro-web servers

= Discussion =

I'd ultimately like to see a BaseHttpServer here that can both handle XML-RPC requests (with ''that'' request handler,) and normal web requests (with a custom handler.)

Yes- I know and love TwistedPython. But I want to make something that works in a single install. -- LionKimbro <<DateTime(2004-05-31T01:13:16Z)>>

I'd also like to add code here showing how to service a POST request.

-- LionKimbro <<DateTime(2004-07-03T23:07:53Z)>>

There exist tools like CherryPy which will create a single-file Python HTTP server (based on BaseHTTPServer). This is a fair amount easier to work with than the raw BaseHTTPServer. For most cases, using a more complete framework will be preferable (see WebProgramming). -- IanBicking

I like the BaseHttpServer because it is in the default Python distributions. I encourage all work towards putting a standard web framework into the default Python distribution. I'm not picky, just as long as something is chosen. -- LionKimbro <<DateTime(2005-01-25T04:53:53Z)>>

What's the matter with server_close()? I can call the method, but it is undocumented (see [[http://docs.python.org/lib/node634.html]]). Could someone knowledgable either remove the calls, or add a comment why they're necessary? Thanks. -- Anonymous Coward, 23 Oct 2007

BaseHTTPServer

You can use this to make a simple HTTP web server.

Official Documentation

Example Code

Responding with an HTML Page

   1 import time
   2 import BaseHTTPServer
   3 
   4 
   5 HOST_NAME = 'example.net' # !!!REMEMBER TO CHANGE THIS!!!
   6 PORT_NUMBER = 80 # Maybe set this to 9000.
   7 
   8 
   9 class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  10     def do_HEAD(s):
  11         s.send_response(200)
  12         s.send_header("Content-type", "text/html")
  13         s.end_headers()
  14     def do_GET(s):
  15         """Respond to a GET request."""
  16         s.send_response(200)
  17         s.send_header("Content-type", "text/html")
  18         s.end_headers()
  19         s.wfile.write("<html><head><title>Title goes here.</title></head>")
  20         s.wfile.write("<body><p>This is a test.</p>")
  21         # If someone went to "http://something.somewhere.net/foo/bar/",
  22         # then s.path equals "/foo/bar/".
  23         s.wfile.write("<p>You accessed path: %s</p>" % s.path)
  24         s.wfile.write("</body></html>")
  25 
  26 if __name__ == '__main__':
  27     server_class = BaseHTTPServer.HTTPServer
  28     httpd = server_class((HOST_NAME, PORT_NUMBER), MyHandler)
  29     print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
  30     try:
  31         httpd.serve_forever()
  32     except KeyboardInterrupt:
  33         pass
  34     httpd.server_close()
  35     print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)

Responding with URL Redirection

This code demonstrates simple URL redirection:

   1 """
   2 URL redirection example.
   3 """
   4 
   5 import BaseHTTPServer
   6 import time
   7 import sys
   8 
   9 
  10 HOST_NAME = 'example.net' # !!!REMEMBER TO CHANGE THIS!!!
  11 PORT_NUMBER = 80 # Maybe set this to 9000.
  12 REDIRECTIONS = {"/slashdot/": "http://slashdot.org/",
  13                 "/freshmeat/": "http://freshmeat.net/"}
  14 LAST_RESORT = "http://google.com/"
  15 
  16 class RedirectHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  17     def do_HEAD(s):
  18         s.send_response(301)
  19         s.send_header("Location", REDIRECTIONS.get(s.path, LAST_RESORT))
  20         s.end_headers()
  21     def do_GET(s):
  22         s.do_HEAD()
  23 
  24 if __name__ == '__main__':
  25     server_class = BaseHTTPServer.HTTPServer
  26     httpd = server_class((HOST_NAME, PORT_NUMBER), RedirectHandler)
  27     print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT_NUMBER)
  28     try:
  29         httpd.serve_forever()
  30     except KeyboardInterrupt:
  31         pass
  32     httpd.server_close()
  33     print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT_NUMBER)

Parameterizing

When you want to make your server respect some parameters, it's easiest to do so via the server, rather than the handler.

That is, make a subclass of the server, that accepts some additional parameters. Have the server record those parameters.

Then, in the handler, use s.server to get to the server, and access the parameters through it.

See Also

  • DocXmlRpcServer -- self-documenting XML-RPC servers

  • CgiScripts -- using invoked CGI scripts, rather than running micro-web servers

Discussion

I'd ultimately like to see a BaseHttpServer here that can both handle XML-RPC requests (with that request handler,) and normal web requests (with a custom handler.)

Yes- I know and love TwistedPython. But I want to make something that works in a single install. -- LionKimbro 2004-05-31 01:13:16

I'd also like to add code here showing how to service a POST request.

-- LionKimbro 2004-07-03 23:07:53

There exist tools like CherryPy which will create a single-file Python HTTP server (based on BaseHTTPServer). This is a fair amount easier to work with than the raw BaseHTTPServer. For most cases, using a more complete framework will be preferable (see WebProgramming). -- IanBicking

I like the BaseHttpServer because it is in the default Python distributions. I encourage all work towards putting a standard web framework into the default Python distribution. I'm not picky, just as long as something is chosen. -- LionKimbro 2005-01-25 04:53:53

What's the matter with server_close()? I can call the method, but it is undocumented (see http://docs.python.org/lib/node634.html). Could someone knowledgable either remove the calls, or add a comment why they're necessary? Thanks. -- Anonymous Coward, 23 Oct 2007

BaseHttpServer (last edited 2012-04-15 19:54:19 by PaulBoddie)

Unable to edit the page? See the FrontPage for instructions.