Log:
Make sure server.webpath is either empty or has a slash
at the beginning but not slash at the end. Also make sure
the global startup.webpath and server.webpath setting in the
config are equal (used to be different which was confusing).
Modified:
branches/1.5/turbogears/command/base.py
branches/1.5/turbogears/controllers.py
branches/1.5/turbogears/dispatchers.py
branches/1.5/turbogears/startup.py
branches/1.5/turbogears/view/base.py
branches/1.5/turbogears/widgets/base.py
branches/1.5/turbogears/widgets/i18n.py
branches/1.5/turbogears/widgets/tests/test_request_related_features.py
Modified: branches/1.5/turbogears/command/base.py
==============================================================================
--- branches/1.5/turbogears/command/base.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/command/base.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -313,7 +313,7 @@
# line in order to change port, log methods...
config.update({'global': {
'server.socket_port': self.port,
- 'server.webpath': '/',
+ 'server.webpath': '',
'environment': 'production',
'engine.autoreload.on': False,
'server.package': 'turbogears.toolbox',
Modified: branches/1.5/turbogears/controllers.py
==============================================================================
--- branches/1.5/turbogears/controllers.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/controllers.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -619,6 +619,7 @@
tgpath += '?' + query_string
return tgpath
+
def get_server_name():
"""Return name of the server this application runs on.
@@ -635,6 +636,7 @@
get('server.socket_port', 8080))
return host
+
def absolute_url(tgpath='/', params=None, **kw):
"""Return absolute URL (including schema and host to this server).
Modified: branches/1.5/turbogears/dispatchers.py
==============================================================================
--- branches/1.5/turbogears/dispatchers.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/dispatchers.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -14,10 +14,11 @@
Note that this can not be done by a hook since they are run too late.
"""
+
def __init__(self, next_dispatcher=None, webpath=''):
self.next_dispatcher = next_dispatcher or dispatch.Dispatcher()
- webpath = webpath.rstrip('/')
- if webpath and not webpath.startswith('/'):
+ webpath = webpath.strip('/')
+ if webpath:
webpath = '/' + webpath
self.webpath = webpath
@@ -33,7 +34,7 @@
except (AttributeError, KeyError):
pass
if webpath:
- if path_info.startswith(webpath):
+ if path_info.startswith(webpath + '/'):
request.path_info = path_info = path_info[len(webpath):]
else:
# check for webpath only if not forwarded
Modified: branches/1.5/turbogears/startup.py
==============================================================================
--- branches/1.5/turbogears/startup.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/startup.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -110,12 +110,16 @@
'tools.encode.text_only': False,
'tools.encode.add_charset': False}})
webpath = config.get('server.webpath') or ''
- webpath = webpath.lstrip('/')
- if webpath and not webpath.endswith('/'):
- webpath += '/'
if webpath:
- config.update({'/': {'request.dispatch': VirtualPathDispatcher(
- config.get('request.dispatch'), webpath)}})
+ # sanitize server.webpath setting
+ webpath = webpath.strip('/')
+ if webpath:
+ webpath = '/' + webpath
+ config.update({'server.webpath': webpath})
+ # configure virtual path dispatcher for webpath
+ if webpath:
+ config.update({'/': {'request.dispatch': VirtualPathDispatcher(
+ config.get('request.dispatch'), webpath)}})
def start_turbogears():
@@ -141,8 +145,6 @@
* Starts the TurboGears scheduler if enabled in the configuration.
"""
- global webpath
-
log.info("Starting TurboGears...")
# Initialize template engines and load base templates
Modified: branches/1.5/turbogears/view/base.py
==============================================================================
--- branches/1.5/turbogears/view/base.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/view/base.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -443,13 +443,13 @@
request = cherrypy.request,
selector = selector,
session = session,
- tg_js = '/' + webpath + 'tg_js',
- tg_static = '/' + webpath + 'tg_static',
- tg_toolbox = '/' + webpath + 'tg_toolbox',
+ tg_js = webpath + '/tg_js',
+ tg_static = webpath + '/tg_static',
+ tg_toolbox = webpath + '/tg_toolbox',
tg_version = turbogears.__version__,
url = turbogears.url,
useragent = useragent,
- widgets = '/' + webpath + 'tg_widgets',
+ widgets = webpath + '/tg_widgets',
)
for provider in variable_providers:
provider(tg_vars)
Modified: branches/1.5/turbogears/widgets/base.py
==============================================================================
--- branches/1.5/turbogears/widgets/base.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/widgets/base.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -637,7 +637,7 @@
def update_params(self, d):
super(Link, self).update_params(d)
- d["link"] = "/%stg_widgets/%s/%s" % (startup.webpath,
+ d["link"] = "%s/tg_widgets/%s/%s" % (startup.webpath,
self.mod, self.name)
def __hash__(self):
Modified: branches/1.5/turbogears/widgets/i18n.py
==============================================================================
--- branches/1.5/turbogears/widgets/i18n.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/widgets/i18n.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -111,7 +111,7 @@
file_name += '-' + charset.replace('-', '_')
file_name += '.js'
if os.path.exists(os.path.join(base_dir, file_name)):
- path = "/%stg_widgets/%s" % (startup.webpath, self.mod)
+ path = "%s/tg_widgets/%s" % (startup.webpath, self.mod)
link = "%s/%s" % (path, file_name)
return (link, language, charset)
if charset == default_charset:
Modified: branches/1.5/turbogears/widgets/tests/test_request_related_features.py
==============================================================================
--- branches/1.5/turbogears/widgets/tests/test_request_related_features.py Sat Feb 19 14:57:26 2011 (r7234)
+++ branches/1.5/turbogears/widgets/tests/test_request_related_features.py Sat Feb 19 15:54:23 2011 (r7235)
@@ -136,7 +136,6 @@
assert not response.raw['form2_valid']
value_p = 'value="foo"'
id_p = 'id="form1_age"'
- print output
assert (re.search('.*'.join([value_p, id_p]), output)
or re.search('.*'.join([id_p, value_p]), output))