そういえば SimpleHTTPServer.test() ってどんななんだろう?
と、SimpleHTTPServer を使った後にふと疑問に思ってしまったので調べてみようかと思った。
とりあえず http://www.python.jp/doc/release/lib/lib.html に当たってみることにした。すると、
使用例については関数 test() の実装を参照してください。
http://www.python.jp/doc/release/lib/module-SimpleHTTPServer.html
For example usage, see the implementation of the test() function. New in version 2.5: The 'Last-Modified' header.
http://docs.python.org/lib/module-SimpleHTTPServer.html
などと、つれないお言葉。てゆーか、意味が分からん。プログラムのコードを見ろってこと?New in version 2.5: The 'Last-Modified' header.
って何?
取り乱していても仕方が無いので、一先ずコード(/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/SimpleHTTPServer.py)を見てみることにした。
test で検索したところ、それっぽいものが212行目に見つかった。
def test(HandlerClass = SimpleHTTPRequestHandler, ServerClass = BaseHTTPServer.HTTPServer): BaseHTTPServer.test(HandlerClass, ServerClass)
これまで本などから得た知識を総動員して考えたところ、SimpleHTTPServer.test()
というのは結局のところ BaseHTTPServer.test()
を呼び出している(?)ということなんではないだろうか、という結論に達した。ので、今度は 同BaseHTTPServer.py を見てみることにした。同様に検索し、554行目。
def test(HandlerClass = BaseHTTPRequestHandler, ServerClass = HTTPServer, protocol="HTTP/1.0"): """Test the HTTP request handler class. This runs an HTTP server on port 8000 (or the first command line argument). """ if sys.argv[1:]: port = int(sys.argv[1]) else: port = 8000 server_address = ('', port) HandlerClass.protocol_version = protocol httpd = ServerClass(server_address, HandlerClass) sa = httpd.socket.getsockname() print "Serving HTTP on", sa[0], "port", sa[1], "..." httpd.serve_forever()
…えー、途端に追いかけるのが大変になってしまったので詳細はまたの機会に譲るとして、とりあえずは port8000 で webサーバを起てる、とかそんな感じでいいのだろうか。まぁ、いいか。いいのか?
分かったのは、簡単に使えるものでも仕組みまで簡単とは限らない、ということ。それと、python への基本的な理解が不足しているということも。「Python チュートリアル」などを適宜見返すようにしよう。
http://www.python.jp/doc/release/lib/module-BaseHTTPServer.html も後で読む。