summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2000-08-01 21:55:52 +0000
committerbwarsaw2000-08-01 21:55:52 +0000
commitdac71163d82b6d990152adc7038b21e013071c92 (patch)
treefd9ecb74bca674026b001d0f35169b09e3847931
parentb20df5635aaa0d1740b9f827d3b018685c46e699 (diff)
downloadmailman-dac71163d82b6d990152adc7038b21e013071c92.tar.gz
mailman-dac71163d82b6d990152adc7038b21e013071c92.tar.zst
mailman-dac71163d82b6d990152adc7038b21e013071c92.zip
Massive cleanup to fix relative/absolute script url calculation in
response to SF Bug #110753. Specifically, GetNestingLevel(): removed ScriptURL(): New utility function to calculate relative and absolute urls. The basic approach is this: 1. figure out where we are by using REQUEST_URI or SCRIPTNAME+PATH_INFO if that isn't defined in our environment. 2. figure out what the Mailman base url is by taking the `path' component of a urlparse() of the list's web_page_url configvar or DEFAULT_URL if that isn't provided in the arguments. 3. calculate what the relative path is from where we are to baseurl; express this as a string of ../'s 4. tack on the relative url to where we want to go, i.e. the target Elaborations: Optional `absolute' if set always calculates the absolute url as web_page_url/DEFAULT_URL + target. absolute should only be set when generating urls for emails. mm_cfg.CGIEXT is always tacked onto the end, meaning target is supposed to be just the script name and nothing else (anything else should be concatenated onto the return value of this function).
-rw-r--r--Mailman/Utils.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index b762a4422..321609293 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -32,6 +32,7 @@ from types import StringType
# XXX: obsolete, should use re module
import regsub
import random
+import urlparse
from Mailman import mm_cfg
from Mailman import Errors
@@ -219,18 +220,28 @@ def GetPathPieces(path):
return l
-_nesting_level = None
-def GetNestingLevel():
- global _nesting_level
- if _nesting_level == None:
- try:
- path = os.environ['PATH_INFO']
- if path[0] <> '/':
- path= '/' + path
- _nesting_level = string.count(path, '/')
- except KeyError:
- _nesting_level = 0
- return _nesting_level
+def ScriptURL(target, web_page_url=mm_cfg.DEFAULT_URL, absolute=0):
+ """target - scriptname only, nothing extra
+ web_page_url - the list's configvar of the same name
+ absolute - a flag which if set, generates an absolute url
+ """
+ fullpath = os.environ.get('REQUEST_URI')
+ if fullpath is None:
+ fullpath = os.environ.get('SCRIPT_NAME', '') + \
+ os.environ.get('PATH_INFO', '')
+ baseurl = urlparse.urlparse(web_page_url)[2]
+ if not absolute and fullpath[:len(baseurl)] == baseurl:
+ # Use relative addressing
+ fullpath = fullpath[len(baseurl):]
+ i = string.find(fullpath, '?')
+ if i > 0:
+ count = string.count(fullpath, '/', 0, i)
+ else:
+ count = string.count(fullpath, '/')
+ path = ('../' * count) + target
+ else:
+ path = web_page_url + target
+ return path + mm_cfg.CGIEXT