Issue Details (XML | Word | Printable)

Key: MODPYTHON-72
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Nicolas Lehuen
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

mod_python.publisher no longer pays attention to result of req.get_addhandler_exts()

Created: 10/Aug/05 09:53 PM   Updated: 05/Mar/06 02:18 PM
Return to search
Component/s: None
Affects Version/s: 3.2.7
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works publisher.txt 2005-08-27 08:49 PM Graham Dumpleton 4 kB

Resolution Date: 28/Aug/05 05:47 AM


 Description  « Hide
Says Graham :

    A final issue, is that latest mod_python.publisher no longer pays
    attention to result of req.get_addhandler_exts(). This means that where
    you used to be able to say:

       # .htaccess

       AddHandler mod_python .html
       PythonHandler mod_python.publisher

       # page.py

       def index():
         return "<html></body><p>XXX</p></body></html>"

    with URL of "/page.html", this no longer appears to work for me. In
    short it appears that one can only use ".py" as an extension or no
    extension at all. Defining another extension to AddHandler or
    PythonHandler seems to have no effect.




 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Nicolas Lehuen made changes - 10/Aug/05 09:53 PM
Field Original Value New Value
Assignee Nicolas Lehuen [ nlehuen ]
Jim Gallacher added a comment - 27/Aug/05 01:00 AM
I can't reproduce this problem, or maybe I don't understand it properly. In the example, is # page.py a typo and should actually be page.html?

ie.

# page.html

       def index():
         return "<html></body><p>XXX</p></body></html>"

works fine for me.

Likewise if I have a file stuff.html:

# stuff.html

def index(req):
    return "<html></body><p>MODPYTHON-72 stuff</p></body></html>"

calling either "/stuff" or "/stuff.html" returns the correct page.

Graham Dumpleton added a comment - 27/Aug/05 07:08 PM
I definitely mean "page.py". I am definitely not suggesting that you have Python code
in an actual physical file called "page.html". I am suggesting you access it though as
"page.html". Accessing "page.html" should return HTML output. Accessing "page.py"
will return Python source code, although because it contains HTML it will not look
correct as markup will disappear.

Not sure why you can't duplicate it. On mod_python 3.1.3 it works for me with whether
or not MultiViews is enabled. On mod_python subversion head though, it doesn't work
at all and thus the basis of the bug report about it.

What happens is that since "page.html" doesn't map to an actual physical file, it gets
passed through in req.filename in total. Eg. dumping out req attributes at start of
publisher you should see:

  [Sat Aug 27 19:53:26 2005] [error] req.uri='/~grahamd/mp32/page.html'
  [Sat Aug 27 19:53:26 2005] [error] req.filename='/Users/grahamd/Sites/mp32/page.html'
  [Sat Aug 27 19:53:26 2005] [error] req.path_info=''

It then fails the "if exists(req.filename)" check and in the "else" case it will check for
"isfile(req.filename+'.py')". Ie., checks for "page.html.py" which also wouldn't exist.
It therefore falls through to sticking "index.py" explicitly in req.filename and when
that doesn't exist raises Python error because of other problem I have highlighted.

The only way it would work is if "index.py" existed and in it it had something that
would resolve if "page.html" were mapped against it as "func_path". This would be
unlikely.

Anyway, I will work on a fix.

Graham Dumpleton added a comment - 27/Aug/05 07:35 PM
Another bug in this new publisher code is that when SetHandler is used, in 3.1.3
it would only pay attention to files matched which had a ".py" extension. Actually
it would match anything returned by imp.get_suffixes(), but then it had some subtle
bugs in that as well, as described in MODPYTHON-22.

This all mean't that if you had "page.py" and "page.html" in a directory together and
you access "page.html" it would return not found. In the new publisher it attempts to
load the "page.html" file as Python code, which yields a syntax error like:

    File "/Users/grahamd/Sites/mp32/page.html", line 1

    
      ^

  SyntaxError: invalid syntax

Repository Revision Date User Message
ASF #240455 Sat Aug 27 20:45:41 UTC 2005 nlehuen Graham's patch for MODPYTHON-72.
Files Changed
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/publisher.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Graham Dumpleton added a comment - 27/Aug/05 08:49 PM
Jim, can you give this patch I have attached a go. What I have done is incorporated
the equivalent publisher code I had from Vampire where I already worked out fixes
for all the original publisher problems. This code also handles correctly the cases
for where the new publisher code has introduced problems as described above
and elsewhere. The code is well commented and I believe it is perhaps a bit easier
to follow anyway.

I haven't checked it against the test suite after having integrated it, just a few cases
covering the problematic areas where current problems are, so if you can run the
test suite other it, would be appreciated. We can then see where we go with this,
whether my alternative is going to be acceptable or whether it is going to be
necessary to try and make what was there work instead.


Graham Dumpleton made changes - 27/Aug/05 08:49 PM
Attachment publisher.txt [ 12312037 ]
Nicolas Lehuen added a comment - 28/Aug/05 05:47 AM
Integrated Graham's patch, ran the unit test suite, everything is OK. Graham, I need a confirmation for your particular test case, though.

Nicolas Lehuen made changes - 28/Aug/05 05:47 AM
Assignee Nicolas Lehuen [ nlehuen ]
Fix Version/s 3.2.0 [ 11060 ]
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Graham Dumpleton made changes - 05/Mar/06 02:18 PM
Status Resolved [ 5 ] Closed [ 6 ]