[Web-SIG] Standardising containment.

Phillip J. Eby pje at telecommunity.com
Mon Sep 6 16:11:02 CEST 2004


At 01:46 PM 9/6/04 +0100, Alan Kennedy wrote:
>[Alan Kennedy]
> >>1. Temporary storage/scratch directory.
>
>On thinking further about the temp directory issue, I see now that it is 
>but one example of a class of problems relating to accessing physical 
>resources on the local machine.
>
>The other main one that springs to mind is how WSGI applications discover 
>the file-system path name that corresponds to an URI.

*boggle*  Why do you think that URIs have anything to do with file 
paths?  In the general case, they are entirely unrelated.


>[snip]
>Therefore I propose that WSGI somehow attempt to standardise access to 
>local resources on the disk. This could be done, perhaps, by providing a 
>function which resolves a logical URI to a physical resource. J2EE has 
>just such a function (surprise ;-), called ServletContext.getRealPath(), 
>which returns a file-system path name which is relative to the 
>CONTEXT_PATH mentioned above.
>
>Without WSGI providing such local mapping functions, I don't see how WSGI 
>applications/middleware can map URIs to files, without undertaking 
>platform specific tricks.

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.

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.



More information about the Web-SIG mailing list