"""This URL scheme is based on ``PATH_INFO``."""
__docformat__ = "restructuredtext"
# Created: Wed Feb 25 11:59:15 PST 2004
# Author: Shannon -jj Behrens
# Email: jjinux@users.sourceforge.net
#
# Copyright (c) Shannon -jj Behrens. All rights reserved.
import re
from QueryParameters import QueryParameters
class PathInfo(QueryParameters):
"""This URL scheme is based on ``PATH_INFO``.
``PATH_INFO`` is used to the set the screen in the URL's. Otherwise, this
class is just like aquarium.urlscheme.QueryParameters_, which this class
derives from.
See aquarium.urlscheme.UrlSchemeAPI_.
Hiding the ``index.cgi`` or ``index.fcgi`` in Apache with mod_rewrite
=====================================================================
To change URLs such as ``http://www.example.com/index.fcgi/fancy_page``
into URLs such as ``http://www.example.com/fancy_page`` under Apache,
use mod_rewrite::
<Directory "/var/www/html">
...
# This rewrites the URL so that everything that isn't a static file
# goes through index.fcgi. Change the .fcgi to .cgi if you're not
# using FastCGI.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.fcgi/$1 [L]
</Directory>
.. _aquarium.urlscheme.QueryParameters:
aquarium.urlscheme.QueryParameters.QueryParameters-class.html
.. _aquarium.urlscheme.UrlSchemeAPI:
aquarium.urlscheme.UrlSchemeAPI-module.html
"""
def screen(self, screen, vars=None, secure=-1):
"""Return a dynamic URL for the given screen."""
if vars is None:
vars = {}
ctx = self._ctx
cgiEnv = self._ctx.wsa.getCgiEnv()
scriptName = cgiEnv["SCRIPT_NAME"]
if scriptName == "" or scriptName == "/":
scriptFile = ""
else:
scriptFile = scriptName[scriptName.rindex("/") + 1:] + "/"
url = "".join([self.getRootUrl(secure), scriptFile,
re.sub(r"\.", "/", screen)])
return self.addVars(url, vars)
def whichScreen(self):
"""Which screen does the user want to view?"""
screen = self._ctx.wsa.getCgiEnv().get("PATH_INFO", None)
if not screen:
return None
if screen.startswith("/"):
screen = screen[1:]
return re.sub("/", ".", screen)
|