Permalink
Browse files

add hosts setting

  • Loading branch information...
1 parent 2ccca53 commit 42fe2ee045a0f3e5df34b5b08f2bf5076da4c34c @mcdonc mcdonc committed Jul 30, 2011
@@ -1,6 +1,7 @@
from pyramid.encode import url_quote
from pyramid.settings import asbool
from pyramid_debugtoolbar.utils import as_globals_list
+from pyramid_debugtoolbar.utils import as_list
from pyramid_debugtoolbar.utils import SETTINGS_PREFIX
from pyramid_debugtoolbar.utils import STATIC_PATH
from pyramid_debugtoolbar.utils import ROOT_ROUTE_NAME
@@ -17,11 +18,14 @@
'pyramid_debugtoolbar.panels.sqla.SQLADebugPanel',
)
+default_hosts = ('127.0.0.1', '::1')
+
default_settings = (
('enabled', asbool, 'true'),
('intercept_exc', asbool, 'true'),
('intercept_redirects', asbool, 'true'),
('panels', as_globals_list, default_panel_names),
+ ('hosts', as_list, default_hosts),
)
def parse_settings(settings):
@@ -12,13 +12,15 @@ def test_it(self):
settings = {'debugtoolbar.enabled':'false',
'debugtoolbar.intercept_exc':'false',
'debugtoolbar.intercept_redirects': 'false',
- 'debugtoolbar.panels': panels}
+ 'debugtoolbar.panels': panels,
+ 'debugtoolbar.hosts': '127.0.0.1',}
result = self._callFUT(settings)
self.assertEqual(result,
{'debugtoolbar.enabled':False,
'debugtoolbar.intercept_exc': False,
'debugtoolbar.intercept_redirects': False,
'debugtoolbar.panels': [DummyPanel, DummyPanel],
+ 'debugtoolbar.hosts': ['127.0.0.1'],
}
)
@@ -32,8 +34,8 @@ def _callFUT(self, config):
def test_it(self):
self._callFUT(self.config)
-
-
+ self.assertEqual(self.config.registry.settings['debugtoolbar.hosts'],
+ ('127.0.0.1', '::1'))
class DummyPanel(object):
pass
@@ -110,6 +110,7 @@ def setUp(self):
from pyramid_debugtoolbar.utils import STATIC_PATH
self.config = testing.setUp()
self.config.registry.settings['debugtoolbar.enabled'] = True
+ self.config.registry.settings['debugtoolbar.hosts'] = ['127.0.0.1']
self.config.add_route(ROOT_ROUTE_NAME, '/_debug_toolbar')
self.config.add_static_view('_debugtoolbar/static',
STATIC_PATH)
@@ -126,6 +127,7 @@ def handler(request):
def _callFUT(self, request, handler=None):
registry = self.config.registry
+ request.remote_addr = '127.0.0.1'
from pyramid_debugtoolbar.toolbar import toolbar_handler_factory
if handler is None:
handler = self._makeHandler()
@@ -71,6 +71,7 @@ def toolbar_handler_factory(handler, registry):
panel_classes = get_setting(settings, 'panels', [])
intercept_exc = get_setting(settings, 'intercept_exc')
intercept_redirects = get_setting(settings, 'intercept_redirects')
+ hosts = get_setting(settings, 'hosts')
exc_history = None
@@ -80,8 +81,9 @@ def toolbar_handler_factory(handler, registry):
def toolbar_handler(request):
root_path = request.route_path('debugtoolbar.root')
request.exc_history = exc_history
+ remote_addr = request.remote_addr
- if request.path.startswith(root_path):
+ if (request.path.startswith(root_path) or (not remote_addr in hosts)):
return handler(request)
toolbar = DebugToolbar(request, panel_classes)
@@ -92,10 +92,14 @@ def replace_insensitive(string, target, replacement):
resolver = DottedNameResolver(None)
-def as_globals_list(value):
- L = []
+def as_list(value):
if isinstance(value, basestring):
value = filter(None, [x.strip() for x in value.splitlines()])
+ return value
+
+def as_globals_list(value):
+ L = []
+ value = as_list(value)
for dottedname in value:
obj = resolver.resolve(dottedname)
L.append(obj)

0 comments on commit 42fe2ee

Please sign in to comment.