Clodoaldo Pinto Neto
clodoaldo.pinto.neto at gmail.com
Wed Dec 31 11:35:20 EST 2008
2008/12/31 Clodoaldo Pinto Neto <clodoaldo.pinto.neto at gmail.com>: > 2008/12/31 Graham Dumpleton <graham.dumpleton at gmail.com>: >> Log values of: >> >> req.filename >> req.uri >> req.path_info >> req.args >> >> In the handler and post so can see better what you are saying is >> getting passed to it. > > When _publisher.py is this: > > from mod_python import publisher, apache > from os.path import basename > > def handler(req): > req.add_output_filter('DEFLATE') > req.write(""" > req.filename: %s > req.uri: %s > req.path_info: %s > req.args: %s > """ % (req.filename, req.uri, req.path_info, req.args) > ) > if basename(req.filename) == 'index.py': > req.uri = '/' > req.write('basename: "%s" req.uri: "%s"' % (basename(req.filename), req.uri)) > return apache.OK > return publisher.handler(req) > > calling it like this: > http://example.com/carro/Fiat/DF/Sao_Paulo/2 > > I get this: > > req.filename: /var/www/html/example.com/index.py > req.uri: /carro/Fiat/DF/Sao_Paulo/2 > req.path_info: > req.args: > marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=2 > basename: "index.py" req.uri: "/" > > I will write it to the log later. I'm leaving now. The log with this _publisher.py: from mod_python import publisher, apache from os.path import basename def handler(req): req.add_output_filter('DEFLATE') log_message = (""" req.filename: %s req.uri: %s req.path_info: %s req.args: %s """ % (req.filename, req.uri, req.path_info, req.args) ) req.log_error(log_message) if basename(req.filename) == 'index.py': req.uri = '/' return publisher.handler(req) [Wed Dec 31 14:31:22 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/2\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=2\n [Wed Dec 31 14:31:22 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:22 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:22 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:22 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:23 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:24 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:24 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:24 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n [Wed Dec 31 14:31:24 2008] [error] [client 10.1.1.101] \n req.filename: /var/www/html/carroarodo.com/index.py\n req.uri: /carro/Fiat/DF/Sao_Paulo/\n req.path_info: \n req.args: marca=Fiat&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=carro&pagina=\n Clodoaldo > Regards, Clodoaldo >> >> Unless you are saying publisher isn't getting the request at all. >> >> Graham >> >> 2008/12/31 Clodoaldo Pinto Neto <clodoaldo.pinto.neto at gmail.com>: >>> I'm working on an old mod_python-publisher site. I'm changing the >>> current query string parameters to dynamic urls using mod_rewrite >>> inside a virtual host. >>> >>> <Directory /var/www/html/example.com> >>> SetHandler mod_python >>> PythonHandler /home/example/mod/_publisher.py >>> PythonOption mod_python.importer.path "['/home/example/mod']" >>> PythonFixupHandler /home/example/mod/_upload_limit.py >>> </Directory> >>> >>> RewriteLog /var/log/httpd/example.com-rewrite.log >>> RewriteLogLevel 9 >>> RewriteEngine on >>> RewriteRule ^/pub/.* - [L] >>> RewriteRule ^/$ /index.py [L] >>> RewriteRule ^/(.*?)/?$ /$1/ >>> RewriteRule ^(/(a|b|c))?([/\w]+?)(/(\d+))?/$ $3/?tv=$2&pagina=$5 [NC] >>> RewriteRule ^([/\w]*?)(/(x|y|z))?(/(\w+?))?(/(\w+?))?/$ \ >>> $1/?uf=$3&localidade=$5&bairro=$7 [QSA,NC] >>> RewriteRule ^(/(\w+))?(/(\w+))?/$ /?marca=$2&modelo=$4 [QSA] >>> RewriteRule ^/$ /index.py [QSA,L] >>> >>> >>> The rewrite is working as expected. The problem i have is the >>> publisher doing its own rewrite (is it?) after the one above using the >>> original uri not the rewrote one. >>> >>> rewrite log: >>> >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (3) split >>> uri=/?marca=&modelo= -> uri=/, >>> args=marca=&modelo=&uf=DF&localidade=Sao_Paulo&bairro=&tv=a&pagina=2 >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (3) applying pattern >>> '^/$' to uri '/' >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (2) rewrite '/' -> >>> '/index.py' >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (2) local path >>> result: /index.py >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (2) prefixed with >>> document_root to /var/www/html/example.com/index.py >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#bedec338/initial] (1) go-ahead with >>> /var/www/html/example.com/index.py [OK] >>> >>> Then the publisher gets from there with the original uri: >>> >>> 10.1.1.101 - - [30/Dec/2008:23:28:45 --0200] >>> [example.dkt/sid#b94e66e0][rid#beac0170/initial] (2) init rewrite >>> engine with requested uri /a/DF/Sao_Paulo/ >>> >>> How to make the publisher use the rewrote uri? Or what am i missing >>> and should be doing? >>> >>> _publisher.py: >>> >>> from mod_python import publisher >>> from os.path import basename >>> >>> def handler(req): >>> req.add_output_filter('DEFLATE') >>> if basename(req.filename) == 'index.py': >>> req.uri = '/' >>> return publisher.handler(req) >>> >>> Regards, Clodoaldo >>> _______________________________________________ >>> Mod_python mailing list >>> Mod_python at modpython.org >>> http://mailman.modpython.org/mailman/listinfo/mod_python >>> >> >
|