modpython_gateway.py を mod_python.publisher っぽく

modpython_gateway.py で PythonAutoReload が効かなかったのは __import__() してたせいで、apache.import_module() にすりゃ効くようだ。wsgi_handler.py は environ['PATH_INFO'] がなんかおかしいみたい。ソース見たら 「これで合ってるはず。。。」とかコメントあったが。

"http://host.domain/somedir/script.py/func" でmod_python.publisher だと script.py の def func(): が走って、req.path_info は '/func' になる。CGI だと script.py が走って、PATH_INFO は /func になる。wsgiref だと script.py で CGIHandler().run(hoge) なんで、func は指定できる。PEP 333 ではファイル名/関数名*1をどう指定するかってのは決まってないようだ。

This specification does not define how a server selects or obtains an application to invoke. These and other configuration options are highly server-specific matters. It is expected that server/gateway authors will document how to configure the server to execute a particular application object, and with what options (such as threading options).

うーん、決まってないのか。Zope とかはどーやってんだろ。


とりあえず httpd.conf 指定じゃめんどいんでどーにかする。
よくわかってないが、modpython_gateway.py とかは mod_python の handler で、 environ と start_response() 作って PythonOption で module::func と指定したのから module を __import__ してその中の func を実行してるだけっぽいんでごにょごにょ。
req.filename と req.path_info から読み込むファイル名と呼び出す関数名ゲットして、req.get_config() で PythonAutoReload とってきて apache.import_module() するように。関数名は指定無かったら 'index' にしといた。

mod_python.publisher.py と比べると modpython_gateway.py とかはてきとーだなぁとか思ったり。てめーに言われたかねーよ。

*1:別に関数に限らんようだ