summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt6
-rw-r--r--docs/narr/MyProject/development.ini1
-rw-r--r--docs/tutorials/wiki/src/authorization/development.ini1
-rw-r--r--docs/tutorials/wiki/src/basiclayout/development.ini1
-rw-r--r--docs/tutorials/wiki/src/models/development.ini1
-rw-r--r--docs/tutorials/wiki/src/viewdecorators/development.ini1
-rw-r--r--docs/tutorials/wiki/src/views/development.ini1
-rw-r--r--docs/tutorials/wiki2/src/authorization/development.ini1
-rw-r--r--docs/tutorials/wiki2/src/basiclayout/development.ini1
-rw-r--r--docs/tutorials/wiki2/src/models/development.ini1
-rw-r--r--docs/tutorials/wiki2/src/views/development.ini1
-rw-r--r--pyramid/paster_templates/alchemy/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/pylons_basic/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/pylons_minimal/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/pylons_sqla/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/routesalchemy/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/starter/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/starter_zcml/development.ini_tmpl1
-rw-r--r--pyramid/paster_templates/zodb/development.ini_tmpl1
-rw-r--r--pyramid/router.py17
-rw-r--r--pyramid/settings.py4
-rw-r--r--pyramid/tests/test_router.py15
-rw-r--r--pyramid/tests/test_settings.py22
23 files changed, 81 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 1cc082a16..5f9cb3d05 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,12 @@
Next release
============
+Features
+--------
+
+- Added ``debug_matched`` configuration setting that logs matched routes
+ (including the matchdict and predicates).
+
Bug Fixes
---------
diff --git a/docs/narr/MyProject/development.ini b/docs/narr/MyProject/development.ini
index 80d89e46a..7a48b5bc5 100644
--- a/docs/narr/MyProject/development.ini
+++ b/docs/narr/MyProject/development.ini
@@ -3,6 +3,7 @@ use = egg:MyProject
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
diff --git a/docs/tutorials/wiki/src/authorization/development.ini b/docs/tutorials/wiki/src/authorization/development.ini
index 21f1c048f..d09da86eb 100644
--- a/docs/tutorials/wiki/src/authorization/development.ini
+++ b/docs/tutorials/wiki/src/authorization/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
[pipeline:main]
diff --git a/docs/tutorials/wiki/src/basiclayout/development.ini b/docs/tutorials/wiki/src/basiclayout/development.ini
index e8d642cde..4fb6f25f8 100644
--- a/docs/tutorials/wiki/src/basiclayout/development.ini
+++ b/docs/tutorials/wiki/src/basiclayout/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
[pipeline:main]
diff --git a/docs/tutorials/wiki/src/models/development.ini b/docs/tutorials/wiki/src/models/development.ini
index e8d642cde..4fb6f25f8 100644
--- a/docs/tutorials/wiki/src/models/development.ini
+++ b/docs/tutorials/wiki/src/models/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
[pipeline:main]
diff --git a/docs/tutorials/wiki/src/viewdecorators/development.ini b/docs/tutorials/wiki/src/viewdecorators/development.ini
index 21f1c048f..d09da86eb 100644
--- a/docs/tutorials/wiki/src/viewdecorators/development.ini
+++ b/docs/tutorials/wiki/src/viewdecorators/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
[pipeline:main]
diff --git a/docs/tutorials/wiki/src/views/development.ini b/docs/tutorials/wiki/src/views/development.ini
index 21f1c048f..d09da86eb 100644
--- a/docs/tutorials/wiki/src/views/development.ini
+++ b/docs/tutorials/wiki/src/views/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
[pipeline:main]
diff --git a/docs/tutorials/wiki2/src/authorization/development.ini b/docs/tutorials/wiki2/src/authorization/development.ini
index 23b01a338..10595b4f5 100644
--- a/docs/tutorials/wiki2/src/authorization/development.ini
+++ b/docs/tutorials/wiki2/src/authorization/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/tutorial.db
diff --git a/docs/tutorials/wiki2/src/basiclayout/development.ini b/docs/tutorials/wiki2/src/basiclayout/development.ini
index 23b01a338..10595b4f5 100644
--- a/docs/tutorials/wiki2/src/basiclayout/development.ini
+++ b/docs/tutorials/wiki2/src/basiclayout/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/tutorial.db
diff --git a/docs/tutorials/wiki2/src/models/development.ini b/docs/tutorials/wiki2/src/models/development.ini
index 23b01a338..10595b4f5 100644
--- a/docs/tutorials/wiki2/src/models/development.ini
+++ b/docs/tutorials/wiki2/src/models/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/tutorial.db
diff --git a/docs/tutorials/wiki2/src/views/development.ini b/docs/tutorials/wiki2/src/views/development.ini
index 23b01a338..10595b4f5 100644
--- a/docs/tutorials/wiki2/src/views/development.ini
+++ b/docs/tutorials/wiki2/src/views/development.ini
@@ -3,6 +3,7 @@ use = egg:tutorial
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/tutorial.db
diff --git a/pyramid/paster_templates/alchemy/development.ini_tmpl b/pyramid/paster_templates/alchemy/development.ini_tmpl
index 4f4b98ac0..6a713bac2 100644
--- a/pyramid/paster_templates/alchemy/development.ini_tmpl
+++ b/pyramid/paster_templates/alchemy/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{package}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/{{project}}.db
diff --git a/pyramid/paster_templates/pylons_basic/development.ini_tmpl b/pyramid/paster_templates/pylons_basic/development.ini_tmpl
index b14ecc7e2..a6f6f77a5 100644
--- a/pyramid/paster_templates/pylons_basic/development.ini_tmpl
+++ b/pyramid/paster_templates/pylons_basic/development.ini_tmpl
@@ -4,6 +4,7 @@ reload_templates = true
mako.directories = {{package}}:templates
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
session.type = file
diff --git a/pyramid/paster_templates/pylons_minimal/development.ini_tmpl b/pyramid/paster_templates/pylons_minimal/development.ini_tmpl
index d31cd1ca2..c66756738 100644
--- a/pyramid/paster_templates/pylons_minimal/development.ini_tmpl
+++ b/pyramid/paster_templates/pylons_minimal/development.ini_tmpl
@@ -4,6 +4,7 @@ reload_templates = true
mako.directories = {{package}}:templates
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
session.type = file
diff --git a/pyramid/paster_templates/pylons_sqla/development.ini_tmpl b/pyramid/paster_templates/pylons_sqla/development.ini_tmpl
index 1cc1a42e4..07768ef93 100644
--- a/pyramid/paster_templates/pylons_sqla/development.ini_tmpl
+++ b/pyramid/paster_templates/pylons_sqla/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
mako.directories = {{package}}:templates
diff --git a/pyramid/paster_templates/routesalchemy/development.ini_tmpl b/pyramid/paster_templates/routesalchemy/development.ini_tmpl
index a1cbff75f..19cedb323 100644
--- a/pyramid/paster_templates/routesalchemy/development.ini_tmpl
+++ b/pyramid/paster_templates/routesalchemy/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/{{project}}.db
diff --git a/pyramid/paster_templates/starter/development.ini_tmpl b/pyramid/paster_templates/starter/development.ini_tmpl
index 328422ef8..0daa76e74 100644
--- a/pyramid/paster_templates/starter/development.ini_tmpl
+++ b/pyramid/paster_templates/starter/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
diff --git a/pyramid/paster_templates/starter_zcml/development.ini_tmpl b/pyramid/paster_templates/starter_zcml/development.ini_tmpl
index 328422ef8..0daa76e74 100644
--- a/pyramid/paster_templates/starter_zcml/development.ini_tmpl
+++ b/pyramid/paster_templates/starter_zcml/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
diff --git a/pyramid/paster_templates/zodb/development.ini_tmpl b/pyramid/paster_templates/zodb/development.ini_tmpl
index 671c8b069..5a95a3186 100644
--- a/pyramid/paster_templates/zodb/development.ini_tmpl
+++ b/pyramid/paster_templates/zodb/development.ini_tmpl
@@ -3,6 +3,7 @@ use = egg:{{project}}
reload_templates = true
debug_authorization = false
debug_notfound = false
+debug_matched = false
debug_templates = true
default_locale_name = en
zodb_uri = file://%(here)s/Data.fs?connection_cache_size=20000
diff --git a/pyramid/router.py b/pyramid/router.py
index ca2f0adc5..9777459f0 100644
--- a/pyramid/router.py
+++ b/pyramid/router.py
@@ -30,6 +30,8 @@ class Router(object):
implements(IRouter)
debug_notfound = False
+ debug_matched = False
+
threadlocal_manager = manager
def __init__(self, registry):
@@ -41,8 +43,10 @@ class Router(object):
self.root_policy = self.root_factory # b/w compat
self.registry = registry
settings = registry.settings
+
if settings is not None:
self.debug_notfound = settings['debug_notfound']
+ self.debug_matched = settings['debug_matched']
def __call__(self, environ, start_response):
"""
@@ -89,6 +93,19 @@ class Router(object):
environ['bfg.routes.matchdict'] = match
attrs['matchdict'] = match
attrs['matched_route'] = route
+
+ if self.debug_matched:
+ msg = (
+ 'debug_matched of url %s; path_info: %r, '
+ 'route_name: %r, pattern: %r, '
+ 'matchdict: %r, '
+ 'predicates: %r' % (
+ request.url, request.path_info,
+ route.name, route.pattern, match,
+ route.predicates)
+ )
+ logger and logger.debug(msg)
+
request_iface = registry.queryUtility(
IRouteRequest,
name=route.name,
diff --git a/pyramid/settings.py b/pyramid/settings.py
index 7cee68926..bd7e2c227 100644
--- a/pyramid/settings.py
+++ b/pyramid/settings.py
@@ -29,6 +29,9 @@ class Settings(dict):
config_debug_notfound = self.get('debug_notfound', '')
eff_debug_notfound = asbool(eget('BFG_DEBUG_NOTFOUND',
config_debug_notfound))
+ config_debug_matched = self.get('debug_matched', '')
+ eff_debug_matched = asbool(eget('BFG_DEBUG_MATCHED',
+ config_debug_matched))
config_debug_templates = self.get('debug_templates', '')
eff_debug_templates = asbool(eget('BFG_DEBUG_TEMPLATES',
config_debug_templates))
@@ -46,6 +49,7 @@ class Settings(dict):
update = {
'debug_authorization': eff_debug_all or eff_debug_auth,
'debug_notfound': eff_debug_all or eff_debug_notfound,
+ 'debug_matched': eff_debug_all or eff_debug_matched,
'debug_templates': eff_debug_all or eff_debug_templates,
'reload_templates': eff_reload_all or eff_reload_templates,
'reload_resources':eff_reload_all or eff_reload_resources,
diff --git a/pyramid/tests/test_router.py b/pyramid/tests/test_router.py
index 0ed3d79cf..299bd89cb 100644
--- a/pyramid/tests/test_router.py
+++ b/pyramid/tests/test_router.py
@@ -34,7 +34,9 @@ class TestRouter(unittest.TestCase):
return logger
def _registerSettings(self, **kw):
- settings = {'debug_authorization':False, 'debug_notfound':False}
+ settings = {'debug_authorization':False,
+ 'debug_notfound':False,
+ 'debug_matched':False}
settings.update(kw)
self.registry.settings = settings
@@ -493,6 +495,8 @@ class TestRouter(unittest.TestCase):
def test_call_route_matches_and_has_factory(self):
from pyramid.interfaces import IViewClassifier
+ logger = self._registerLogger()
+ self._registerSettings(debug_matched=True)
self._registerRouteRequest('foo')
root = object()
def factory(request):
@@ -523,6 +527,15 @@ class TestRouter(unittest.TestCase):
self.assertEqual(request.matchdict, matchdict)
self.assertEqual(request.matched_route.name, 'foo')
+ self.assertEqual(len(logger.messages), 1)
+ self.assertEqual(logger.messages[0],
+ "debug_matched of url http://localhost:8080"
+ "/archives/action1/article1; "
+ "path_info: '/archives/action1/article1', "
+ "route_name: 'foo', pattern: 'archives/:action/:article', "
+ "matchdict: {'action': u'action1', 'article': u'article1'}, "
+ "predicates: ()")
+
def test_call_route_matches_doesnt_overwrite_subscriber_iface(self):
from pyramid.interfaces import INewRequest
from pyramid.interfaces import IViewClassifier
diff --git a/pyramid/tests/test_settings.py b/pyramid/tests/test_settings.py
index cf8fd1119..9df7026a9 100644
--- a/pyramid/tests/test_settings.py
+++ b/pyramid/tests/test_settings.py
@@ -24,6 +24,7 @@ class TestSettings(unittest.TestCase):
settings = self._makeOne()
self.assertEqual(settings['debug_authorization'], False)
self.assertEqual(settings['debug_notfound'], False)
+ self.assertEqual(settings['debug_matched'], False)
self.assertEqual(settings['reload_templates'], False)
self.assertEqual(settings['reload_resources'], False)
self.assertEqual(settings['configure_zcml'], '')
@@ -109,6 +110,21 @@ class TestSettings(unittest.TestCase):
{'BFG_DEBUG_NOTFOUND':'1'})
self.assertEqual(result['debug_notfound'], True)
+ def test_debug_matched(self):
+ result = self._makeOne({})
+ self.assertEqual(result['debug_matched'], False)
+ result = self._makeOne({'debug_matched':'false'})
+ self.assertEqual(result['debug_matched'], False)
+ result = self._makeOne({'debug_matched':'t'})
+ self.assertEqual(result['debug_matched'], True)
+ result = self._makeOne({'debug_matched':'1'})
+ self.assertEqual(result['debug_matched'], True)
+ result = self._makeOne({}, {'BFG_DEBUG_MATCHED':'1'})
+ self.assertEqual(result['debug_matched'], True)
+ result = self._makeOne({'debug_matched':'false'},
+ {'BFG_DEBUG_MATCHED':'1'})
+ self.assertEqual(result['debug_matched'], True)
+
def test_debug_templates(self):
result = self._makeOne({})
self.assertEqual(result['debug_templates'], False)
@@ -127,27 +143,33 @@ class TestSettings(unittest.TestCase):
def test_debug_all(self):
result = self._makeOne({})
self.assertEqual(result['debug_notfound'], False)
+ self.assertEqual(result['debug_matched'], False)
self.assertEqual(result['debug_authorization'], False)
self.assertEqual(result['debug_templates'], False)
result = self._makeOne({'debug_all':'false'})
self.assertEqual(result['debug_notfound'], False)
+ self.assertEqual(result['debug_matched'], False)
self.assertEqual(result['debug_authorization'], False)
self.assertEqual(result['debug_templates'], False)
result = self._makeOne({'debug_all':'t'})
self.assertEqual(result['debug_notfound'], True)
+ self.assertEqual(result['debug_matched'], True)
self.assertEqual(result['debug_authorization'], True)
self.assertEqual(result['debug_templates'], True)
result = self._makeOne({'debug_all':'1'})
self.assertEqual(result['debug_notfound'], True)
+ self.assertEqual(result['debug_matched'], True)
self.assertEqual(result['debug_authorization'], True)
self.assertEqual(result['debug_templates'], True)
result = self._makeOne({}, {'BFG_DEBUG_ALL':'1'})
self.assertEqual(result['debug_notfound'], True)
+ self.assertEqual(result['debug_matched'], True)
self.assertEqual(result['debug_authorization'], True)
self.assertEqual(result['debug_templates'], True)
result = self._makeOne({'debug_all':'false'},
{'BFG_DEBUG_ALL':'1'})
self.assertEqual(result['debug_notfound'], True)
+ self.assertEqual(result['debug_matched'], True)
self.assertEqual(result['debug_authorization'], True)
self.assertEqual(result['debug_templates'], True)