#59 HTTPRequest serverSidePath does not accept absolute sitepath

closed-fixed
nobody
WebKit (58)
5
2006-07-07
2003-11-04
No

req.serverSidePath accepts relative site paths fine, but
does not work with an absolute site path.

This :
req.serverSidePath('/index.psp')

Will return :
'\index.psp'

Instead of the expected absolute path.

My solution, possibly incorrect for some installations but
works for me, is as follows :

if path:
if path[0]=='/' or path[0]=='\\':
return os.path.normpath
(self._environ['DOCUMENT_ROOT']+path)
else:
return
os.path.normpath(os.path.join(os.path.dirname
(self._serverSidePath), path))
else:
return self._serverSidePath

The 2nd if and it's return statement are the addition.

The whole serverSidePath now looks like this. I have
been using this for months. This functionality is fully
common to web development platforms I depend on.

# ----------------------------------------------------
-----------------

# kaishaku fix
def serverSidePath(self, path=None):
""" Returns the absolute server-side path
of the request. If the optional
path is passed in, then it is joined with the server side
directory to form a path relative to the
object.
"""
if not hasattr(self, '_serverSidePath'):
app = self._transaction.application()
self._serverSidePath,
self._serverSideContextPath, self._contextName =
app.serverSideInfoForRequest(self)
if path:
if path[0]=='/' or path[0]=='\\':
return os.path.normpath
(self._environ['DOCUMENT_ROOT']+path)
else:
return
os.path.normpath(os.path.join(os.path.dirname
(self._serverSidePath), path))
else:
return self._serverSidePath

# ----------------------------------------------------
-----------------

Discussion

  • Logged In: YES
    user_id=559878

    I attached the code so it's easier to read, see the
    attachment instead of trying to decipher the code mutilated
    by sourceforge in the original message.

     
  • Logged In: YES
    user_id=193957

    An absolute path is now treated as if it was a relative one,
    so you will always get a file system path back. This is
    simply the concatentation of the current server side path
    and the passed path and may be different from the server
    side path if the passed path would be evaluated as a URL
    (with adapter, context etc.). Fixed in SVN, will go into
    Webware 0.9.2.

     
    • status: open --> closed-fixed