[Web-SIG] [proposal] wsgiref.util.abs_url

Phillip J. Eby pje at telecommunity.com
Mon May 5 19:39:50 CEST 2008

At 06:27 PM 5/5/2008 +0200, Manlio Perillo wrote:
>Phillip J. Eby ha scritto:
>>I think that it doesn't accept a relative URL, it accepts an absolute path.
>What do you mean?
>  environ = {}
>  setup_testing_defaults(environ)
>  url = '/a/b/'

That's a relative URL that's also an absolute path.  Try a relative 
URL like './a/b', or just plain 'a/b'.

>    self.failUnlessEqual(
>       util.abs_url(environ, url), '')
>>I also think that using urlparse.urljoin() with either 
>>request_uri() or application_uri() would be a clearer (and tested) 
>>way to obtain an absolute URL, and more generally useful.
>But application_uri also includes SCRIPT_NAME.

Yes, and you might want to use it as the base against which a 
relative URL will be resolved -- i.e. an application-relative URL, 
vs. a request-relative URL.  In fact, application_uri() would 
probably be *more* useful, since if you want a request-relative URL, 
there's no need to turn it into an absolute URL, since you could just 
use it in its relative form.

Note, however, that in either case, using a relative URL that's an 
absolute path (e.g. '/a/b'), will still produce the same result as 
your function would.  It's just that urljoin also works properly for 
all kinds of relative urls, not just the absolute-path subset.

More information about the Web-SIG mailing list