Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-126

PythonHandler in <Files> directive sets req.hlist.directory to useless value.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.7
    • Fix Version/s: 3.3.1
    • Component/s: core
    • Labels:
      None

      Description

      When you have Apache ".htaccess" configuration like:

      SetHandler mod_python
      #PythonPath "['/Users/grahamd/Sites/auth']+sys.path"

      <Files "page1.txt">
      PythonHandler page1::handler_txt
      </Files>
      <Files "page2.txt">
      PythonHandler page2::handler_txt
      </Files>

      and "page1.txt" is accessed, the req.hlist.directory attribute, which is supposed to list the name of the directory the PythonHandler directive was used in, gets set to "page1.txt/" instead.

      This value then gets added into "sys.path". Because it doesn't actually identify the directory, the module "page1" cannot actually be found when the import is performed.

      [Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: Traceback (most recent call last):
      [Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 288, in HandlerDispatch\n log=debug)
      [Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 508, in import_module\n f, p, d = imp.find_module(parts[i], path)
      [Fri Feb 10 09:08:40 2006] [error] [client 127.0.0.1] PythonHandler page1::handler_txt: ImportError: No module named page1

      The only workaround at this point is to explicitly define the PythonPath directive to include the directory the modules and ".htaccess" file are in. Not sure yet whether there is a way in Apache of determining the directory the "Files" directive is used in and set "req.hlist.directory" correctly.

        Activity

        Hide
        grahamd Graham Dumpleton added a comment -

        It is impossible to fix this in a way that wouldn't require additional configuration directives to be added to the example.

        The only way to get access to the directory associated with the explicit/implicit "Directory" directive enclosing the "Files" directive is for there to exist some other Python directive outside of the "Files" directive so as to trigger the creation of a per_dir_config which would then hold the config_dir. This would still require the code which merges the per_dir_config's to give precedence to a config_dir in a parent context when it is an absolute pathname and the current isn't. Determining if a directory on Win32 is an absolute pathname can be hard and can't find a Apache routine which does it. Either way, it still would require another mod_python directive to have been used, meaning a dummy one may need to be added to fake things so it works properly.

        Overall, what might be better is that support for using "Python*Handler" inside of "Files" directives be accomodated using other means based on future changes to be made to the module importer. Thus, need to revisit this problem when importer is fixed.

        Show
        grahamd Graham Dumpleton added a comment - It is impossible to fix this in a way that wouldn't require additional configuration directives to be added to the example. The only way to get access to the directory associated with the explicit/implicit "Directory" directive enclosing the "Files" directive is for there to exist some other Python directive outside of the "Files" directive so as to trigger the creation of a per_dir_config which would then hold the config_dir. This would still require the code which merges the per_dir_config's to give precedence to a config_dir in a parent context when it is an absolute pathname and the current isn't. Determining if a directory on Win32 is an absolute pathname can be hard and can't find a Apache routine which does it. Either way, it still would require another mod_python directive to have been used, meaning a dummy one may need to be added to fake things so it works properly. Overall, what might be better is that support for using "Python*Handler" inside of "Files" directives be accomodated using other means based on future changes to be made to the module importer. Thus, need to revisit this problem when importer is fixed.
        Hide
        grahamd Graham Dumpleton added a comment -

        FWIW, I think I know how to fix the above so it works. This time I stumbled onto the fact that in Apache one can programmatically query back through the contexts of directives defined in a configuration. This will allow the code which deals with Python*Handler directives to query back looking for the Directory or DirectoryMatch directive it was used in.

        If it can't find either, then it would have been a Location directive and it now will know the URL should not be used as the handler directory. If it did find Directory, it could work out the argument to it and use that as the basis for working out the directory. Ie., it would skip past any File directives and go direct to the Directory context.

        The only trick to solve is the best way of dealing with wildcards or regexes for directory. One probably has to leave it until the very point that request is being handled, which means that Apache wildcard/regex matching routines may need to be exposed in mod_python Python APIs to ensure same matching scheme can be used against the req.filename member.

        Thus, my whole idea of being able to mark base directories as discussed on mailing list is no longer relevant to solving this particular issue.

        Show
        grahamd Graham Dumpleton added a comment - FWIW, I think I know how to fix the above so it works. This time I stumbled onto the fact that in Apache one can programmatically query back through the contexts of directives defined in a configuration. This will allow the code which deals with Python*Handler directives to query back looking for the Directory or DirectoryMatch directive it was used in. If it can't find either, then it would have been a Location directive and it now will know the URL should not be used as the handler directory. If it did find Directory, it could work out the argument to it and use that as the basis for working out the directory. Ie., it would skip past any File directives and go direct to the Directory context. The only trick to solve is the best way of dealing with wildcards or regexes for directory. One probably has to leave it until the very point that request is being handled, which means that Apache wildcard/regex matching routines may need to be exposed in mod_python Python APIs to ensure same matching scheme can be used against the req.filename member. Thus, my whole idea of being able to mark base directories as discussed on mailing list is no longer relevant to solving this particular issue.
        Hide
        grahamd Graham Dumpleton added a comment -

        Whoops, reopened wrong issue was supposed to be MODPYTHON-103.

        Show
        grahamd Graham Dumpleton added a comment - Whoops, reopened wrong issue was supposed to be MODPYTHON-103 .

          People

          • Assignee:
            grahamd Graham Dumpleton
            Reporter:
            grahamd Graham Dumpleton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development