[Web-SIG] Standardising containment.
Alan Kennedy
py-web-sig at xhaus.com
Mon Sep 6 16:56:33 CEST 2004
[Alan Kennedy]
>> The other main one that springs to mind is how WSGI applications
>> discover the file-system path name that corresponds to an URI.
[Phillip J. Eby]
> *boggle* Why do you think that URIs have anything to do with file
> paths? In the general case, they are entirely unrelated.
Well, perhaps it's just that pretty much every web
server/harness/framework I ever used has support for mapping URIs to
files. How silly of me to try to apply my experience of other web
systems to WSGI.
In the *general* case, yes, such a mapping has no meaning.
But there are specific cases, e.g. static file serving, where it is
required.
[Phillip J. Eby]
> Well-written Python applications make this sort of thing part of their
> configuration today already, because in the general case (e.g.
> mod_rewrite) this stuff just plain isn't guessable.
It doesn't even have to be guessable: it could be standardised.
[Phillip J. Eby]
> Also, if you need access to local resources, relative to some Python
> module, just grab the '__file__' attribute/variable of that module, and
> then use 'os.path' functions to portably manipulate it. E.g.:
>
> my_dir = os.path.dirname(__file__)
> target = os.path.join(os.path.join(my_dir,"images"),"stars.jpg")
>
> This is simple and portable. If you need something more complex, you
> should probably have configuration specific to the application that
> spells out what it needs to know.
And that is a nice (python-specific) solution to the problem.
Perhaps it's worth adding something to the Q&A about how to map URIs to
files in the local file system, based on the above pythonic, i.e.
module.__file__, approach?
Alan.
More information about the Web-SIG
mailing list