[albatross-users] AppContext.redirect_url() question

Dave Cole djc at object-craft.com.au
Wed Jul 9 21:45:01 EST 2003


> I'm probably being really stupid and missing something obvious but
> this is the bit from redirect_url() I'm confused about:

Not stupid, just not able to read my mind...

>         this_path = urlparse.urlparse(self.request.get_uri())[2]
>         base_path = urlparse.urlparse(self.app.base_url())[2]
>         pos = this_path.find(base_path)
>         new_base = this_path[:pos + len(base_path)]

The idea here is that the URI for a request might be something like
this:

        http://blah.com/path/to/app/app.py/page/here

When you call the application constructor you might have specified a
base_url of 'app.py'.  The toolkit needs to be able to find the
page/here part of the request URI.

The first step is to isolate the path component of both request URI
and the base_url.  That is done by the first two lines.

    this_path = urlparse.urlparse(self.request.get_uri())[2]
    base_path = urlparse.urlparse(self.app.base_url())[2]

For the example above this leads to the following paths

    this_path path/to/app/app.py/page/here and 
    base_path app.py

Then the following lines get executed:

    pos = this_path.find(base_path)
    new_base = this_path[:pos + len(base_path)]

So new_base is

    new_base = path/to/app/app.py

> Firstly, this_path and base_path are normally the same up to the
> name of the script and so pos will be 0. The only time pos can be
> non-zero is when the URLs don't match at all or this_path contains
> an extra path at the start. I can't think of a situation where
> this_path has the extra path.

You already answered this in a later email :-)

I had to go out tonight so did not get to finish this message until
now.

> Anyway, that is just me trying to figure out what's going on. More
> importantly, at least for me, when I put a mod_python app behind a
> mod_rewrite rule redirect_url() fails since mod_python's
> Request.get_uri() returns the *rewritten* path which may have no
> relationship to the application's base_url. That causes
> this_path.find() to return -1 and after that things get a little
> messy ;-).

I have been thinking that there should be enough information in the
request to remove the need to specify base_url.  The base_url is only
there for the following reasons:

* To allow the application to generate URLs to itself.

* To allow the application to work out the above (split base from
  page).

> I have been playing around with using PATH_INFO (in CGI speak) as an
> alternative to decoding the URLs. A set of patches follow, I would
> be interested in your thoughts.

I will have a look.  I would be interested to know if you think we can
eliminate the need to specify a base_url to the application
constructor.  This would probably make URI parsing a lot more easy.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list