On 07/09/2006, at 2:59 PM, Sébastien Arnaud wrote:
Anyway, please share your comments and feedback to make sure I am headed in the right direction by keeping in mind that my first goal is to be able to publish using a defined regex url grammar a callable class within a module. I believe that once this first step is accomplished the real design of the web framework can begin.

A few comments while I work out what your code actually does.

class Mapper:
        """ This is the object to cache the regex engine """
regex = "(?P<controller>[\w]+)?(\.(?P<extension>[\w]+))?(/(?P<action> [^/]+))?(\?$)?"
        regex_compared = 0

        def __init__(self):
                self.reobj = re.compile(self.regex)

        def __call__(self, uri, cre):
                if(cre!=None and not self.regex_compared and cre!=self.regex):
                        self.regex = cre
                        self.reobj = re.compile(self.regex)
                        self.regex_compared = 1
                m = self.reobj.match(uri)
                if m:
return (m.group('controller'), m.group('extension'), m.group ('action'))
                else:
                        return (None, None, None)
        
mapper_cache = Mapper()

This is not thread safe and use in a multithreaded MPM, ie., winnt and worker, may result in failure. I also suspect if you would have problems where two different parts of the URL namespace use different regex's and they aren't executing in different
Python interpreter instances.

    path,module_name =  os.path.split(req.filename)

    # Trimming the front part of req.uri
    if module_name=='':
        req_url = ''
    else:
        req_url = req.uri[req.uri.index(module_name):]

This is not a very robust way of doing this can technically could fail in certain cases.

    # Now determine the actual Python module code file
    # to load. This will first try looking for the file
    # '/path/<module_name>.py'.
    req.filename = path + '/' + controller + '.py'
    if not exists(req.filename):
        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

I am not really sure why you go to all this trouble. For the way the default regex is written, this could possibly just as easily be achieved using standard mod_python.publisher, using subdirectories in document tree and use of MultiViews matching in an appropriate
way.

In other words, am not convinced that your code is required at all and you may be able to achieve the same thing as default regex using standard mod_python.publisher. At worst case, you might need to use Apache RewriteRule. In mod_python 3.3, you
could probably do all this with a very simple fixup handler as well.

Thus, as already requested, can you actually supply some examples of how this is
used in practice.

BTW, you could also have done this by using a wrapper handler around the
existing mod_python.publisher handler as well, thereby avoiding having to cut and
paste all the code.

Graham

Reply via email to