summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-02-20 12:41:47 -0500
committerChris McDonough <chrism@plope.com>2012-02-20 12:41:47 -0500
commit844ed90133f051d013330cb0ed4c95dbb29eecc1 (patch)
tree0ae7eb619b2ec3192a0a50caaffaacc9c59c0702
parent51919e05d9c251f7f80a4736be2b822eafc5d189 (diff)
downloadpyramid-844ed90133f051d013330cb0ed4c95dbb29eecc1.tar.gz
pyramid-844ed90133f051d013330cb0ed4c95dbb29eecc1.tar.bz2
pyramid-844ed90133f051d013330cb0ed4c95dbb29eecc1.zip
Features
-------- - Add an ``introspection`` boolean to the Configurator constructor. If this is ``True``, actions registered using the Configurator will be registered with the introspector. If it is ``False``, they won't. The default is ``True``. Setting it to ``False`` during action processing will prevent introspection for any following registration statements, and setting it to ``True`` will start them up again. This addition is to service a requirement that the debug toolbar's own views and methods not show up in the introspector. Backwards Incompatibilities --------------------------- - Remove ``pyramid.config.Configurator.with_context`` class method. It was never an API, it is only used by ``pyramid_zcml`` and its functionality has been moved to that package's latest release. This means that you'll need to use the latest release of ``pyramid_zcml`` with this release of Pyramid. - The ``introspector`` argument to the ``pyramid.config.Configurator`` constructor API has been removed. It has been replaced by the boolean ``introspection`` flag. - The ``pyramid.registry.noop_introspector`` API object has been removed.
-rw-r--r--CHANGES.txt29
-rw-r--r--docs/api/registry.rst7
-rw-r--r--docs/narr/introspector.rst15
-rw-r--r--pyramid/config/__init__.py51
-rw-r--r--pyramid/registry.py22
-rw-r--r--pyramid/tests/test_config/test_init.py48
-rw-r--r--pyramid/tests/test_registry.py46
7 files changed, 59 insertions, 159 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 1df924b4c..239e1326f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,32 @@
+Next release
+============
+
+Features
+--------
+
+- Add an ``introspection`` boolean to the Configurator constructor. If this
+ is ``True``, actions registered using the Configurator will be registered
+ with the introspector. If it is ``False``, they won't. The default is
+ ``True``. Setting it to ``False`` during action processing will prevent
+ introspection for any following registration statements, and setting it to
+ ``True`` will start them up again. This addition is to service a
+ requirement that the debug toolbar's own views and methods not show up in
+ the introspector.
+
+Backwards Incompatibilities
+---------------------------
+
+- Remove ``pyramid.config.Configurator.with_context`` class method. It was
+ never an API, it is only used by ``pyramid_zcml`` and its functionality has
+ been moved to that package's latest release. This means that you'll need
+ to use the latest release of ``pyramid_zcml`` with this release of Pyramid.
+
+- The ``introspector`` argument to the ``pyramid.config.Configurator``
+ constructor API has been removed. It has been replaced by the boolean
+ ``introspection`` flag.
+
+- The ``pyramid.registry.noop_introspector`` API object has been removed.
+
1.3a8 (2012-02-19)
==================
diff --git a/docs/api/registry.rst b/docs/api/registry.rst
index e18d1b6c2..e62e2ba6f 100644
--- a/docs/api/registry.rst
+++ b/docs/api/registry.rst
@@ -38,10 +38,3 @@
This class is new as of :app:`Pyramid` 1.3.
-.. class:: noop_introspector
-
- An introspector which throws away all registrations, useful for disabling
- introspection altogether (pass as ``introspector`` to the
- :term:`Configurator` constructor).
-
- This class is new as of :app:`Pyramid` 1.3.
diff --git a/docs/narr/introspector.rst b/docs/narr/introspector.rst
index d465c47d9..74595cac8 100644
--- a/docs/narr/introspector.rst
+++ b/docs/narr/introspector.rst
@@ -576,17 +576,14 @@ relationships. It looks something like this:
Disabling Introspection
-----------------------
-You can disable Pyramid introspection by passing the object
-:attr:`pyramid.registry.noop_introspector` to the :term:`Configurator`
-constructor in your application setup:
+You can disable Pyramid introspection by passing the flag
+``introspection=False`` to the :term:`Configurator` constructor in your
+application setup:
.. code-block:: python
from pyramid.config import Configurator
- from pyramid.registry import noop_introspector
- config = Configurator(..., introspector=noop_introspector)
+ config = Configurator(..., introspection=False)
-When the noop introspector is active, all introspectables generated by
-configuration directives are thrown away. A noop introspector behaves just
-like a "real" introspector, but the methods of a noop introspector do nothing
-and return null values.
+When ``introspection`` is ``False``, all introspectables generated by
+configuration directives are thrown away.
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index 06d3c6abf..52d7aca83 100644
--- a/pyramid/config/__init__.py
+++ b/pyramid/config/__init__.py
@@ -239,11 +239,11 @@ class Configurator(
:meth:`pyramid.config.Configurator.add_route` will have the specified path
prepended to their pattern. This parameter is new in Pyramid 1.2.
- If ``introspector`` is passed, it must be an instance implementing the
- attributes and methods of :class:`pyramid.interfaces.IIntrospector`. If
- ``introspector`` is not passed (or is passed as ``None``), the default
- introspector implementation will be used. This parameter is new in
- Pyramid 1.3.
+ If ``introspection`` is passed, it must be a boolean value. If it's
+ ``True``, introspection values during actions will be kept for for use
+ for tools like the debug toolbar. If it's ``False``, introspection
+ values provided by registrations will be ignored. By default, it is
+ ``True``. This parameter is new as of Pyramid 1.3.
"""
manager = manager # for testing injection
venusian = venusian # for testing injection
@@ -273,7 +273,7 @@ class Configurator(
autocommit=False,
exceptionresponse_view=default_exceptionresponse_view,
route_prefix=None,
- introspector=None,
+ introspection=True,
):
if package is None:
package = caller_package()
@@ -284,6 +284,7 @@ class Configurator(
self.registry = registry
self.autocommit = autocommit
self.route_prefix = route_prefix
+ self.introspection = introspection
if registry is None:
registry = Registry(self.package_name)
self.registry = registry
@@ -301,7 +302,6 @@ class Configurator(
session_factory=session_factory,
default_view_mapper=default_view_mapper,
exceptionresponse_view=exceptionresponse_view,
- introspector=introspector,
)
def setup_registry(self,
@@ -318,7 +318,7 @@ class Configurator(
session_factory=None,
default_view_mapper=None,
exceptionresponse_view=default_exceptionresponse_view,
- introspector=None):
+ ):
""" When you pass a non-``None`` ``registry`` argument to the
:term:`Configurator` constructor, no initial setup is performed
against the registry. This is because the registry you pass in may
@@ -339,10 +339,6 @@ class Configurator(
self._fix_registry()
- if introspector is not None:
- # use nondefault introspector
- self.introspector = introspector
-
self._set_settings(settings)
self._register_response_adapters()
@@ -529,7 +525,8 @@ class Configurator(
``introspectables`` is a sequence of :term:`introspectable` objects
(or the empty sequence if no introspectable objects are associated
- with this action).
+ with this action). If this configurator's ``introspection``
+ attribute is ``False``, these introspectables will be ignored.
``extra`` provides a facility for inserting extra keys and values
into an action dictionary.
@@ -543,14 +540,17 @@ class Configurator(
autocommit = self.autocommit
action_info = self.action_info
- introspector = self.introspector
+
+ if not self.introspection:
+ # if we're not introspecting, ignore any introspectables passed
+ # to us
+ introspectables = ()
if autocommit:
if callable is not None:
callable(*args, **kw)
- if introspector is not None:
- for introspectable in introspectables:
- introspectable.register(introspector, action_info)
+ for introspectable in introspectables:
+ introspectable.register(self.introspector, action_info)
else:
action = extra
@@ -782,22 +782,6 @@ class Configurator(
m = types.MethodType(c, self, self.__class__)
return m
- @classmethod
- def with_context(cls, context):
- """A classmethod used by ``pyramid_zcml`` directives to obtain a
- configurator with 'the right' context. Returns a new Configurator
- instance."""
- configurator = cls(
- registry=context.registry,
- package=context.package,
- autocommit=context.autocommit,
- route_prefix=context.route_prefix
- )
- configurator.basepath = context.basepath
- configurator.includepath = context.includepath
- configurator.info = context.info
- return configurator
-
def with_package(self, package):
""" Return a new Configurator instance with the same registry
as this configurator using the package supplied as the
@@ -809,6 +793,7 @@ class Configurator(
package=package,
autocommit=self.autocommit,
route_prefix=self.route_prefix,
+ introspection=self.introspection,
)
configurator.basepath = self.basepath
configurator.includepath = self.includepath
diff --git a/pyramid/registry.py b/pyramid/registry.py
index 7e373b58a..f0f9c83ea 100644
--- a/pyramid/registry.py
+++ b/pyramid/registry.py
@@ -172,28 +172,6 @@ class Introspector(object):
raise KeyError((category_name, discriminator))
return self._refs.get(intr, [])
-@implementer(IIntrospector)
-class _NoopIntrospector(object):
- def add(self, intr):
- pass
- def get(self, category_name, discriminator, default=None):
- return default
- def get_category(self, category_name, default=None, sort_key=None):
- return default
- def categorized(self, sort_key=None):
- return []
- def categories(self):
- return []
- def remove(self, category_name, discriminator):
- return
- def relate(self, *pairs):
- return
- unrelate = relate
- def related(self, intr):
- return []
-
-noop_introspector = _NoopIntrospector()
-
@implementer(IIntrospectable)
class Introspectable(dict):
diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py
index 283800e1e..f872b9df9 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -228,11 +228,9 @@ class ConfiguratorTests(unittest.TestCase):
request_iface=IRequest)
self.assertTrue(view.__wraps__ is exceptionresponse_view)
- def test_ctor_with_introspector(self):
- introspector = DummyIntrospector()
- config = self._makeOne(introspector=introspector)
- self.assertEqual(config.introspector, introspector)
- self.assertEqual(config.registry.introspector, introspector)
+ def test_ctor_with_introspection(self):
+ config = self._makeOne(introspection=False)
+ self.assertEqual(config.introspection, False)
def test_with_package_module(self):
from pyramid.tests.test_config import test_init
@@ -648,7 +646,7 @@ pyramid.tests.test_config.dummy_include2""",
default = inst.introspector
self.assertTrue(hasattr(default, 'add'))
self.assertEqual(inst.introspector, inst.registry.introspector)
- introspector = DummyIntrospector()
+ introspector = object()
inst.introspector = introspector
new = inst.introspector
self.assertTrue(new is introspector)
@@ -759,25 +757,6 @@ pyramid.tests.test_config.dummy_include2""",
else: # pragma: no cover
raise AssertionError
- def test_with_context(self):
- config = self._makeOne()
- context = DummyZCMLContext()
- context.basepath = 'basepath'
- context.includepath = ('spec',)
- context.package = 'pyramid'
- context.autocommit = True
- context.registry = 'abc'
- context.route_prefix = 'buz'
- context.info = 'info'
- newconfig = config.with_context(context)
- self.assertEqual(newconfig.package_name, 'pyramid')
- self.assertEqual(newconfig.autocommit, True)
- self.assertEqual(newconfig.registry, 'abc')
- self.assertEqual(newconfig.route_prefix, 'buz')
- self.assertEqual(newconfig.basepath, 'basepath')
- self.assertEqual(newconfig.includepath, ('spec',))
- self.assertEqual(newconfig.info, 'info')
-
def test_action_branching_kw_is_None(self):
config = self._makeOne(autocommit=True)
self.assertEqual(config.action('discrim'), None)
@@ -1638,7 +1617,7 @@ class TestActionState(unittest.TestCase):
'order':0, 'includepath':(), 'info':None,
'introspectables':(intr,)},
]
- introspector = DummyIntrospector()
+ introspector = object()
c.execute_actions(introspector=introspector)
self.assertEqual(output, [((1,), {})])
self.assertEqual(intr.registered, [(introspector, None)])
@@ -1651,7 +1630,7 @@ class TestActionState(unittest.TestCase):
'order':0, 'includepath':(), 'info':None,
'introspectables':(intr,)},
]
- introspector = DummyIntrospector()
+ introspector = object()
c.execute_actions(introspector=introspector)
self.assertEqual(intr.registered, [(introspector, None)])
@@ -1982,21 +1961,6 @@ class DummyActionState(object):
def action(self, *arg, **kw):
self.actions.append((arg, kw))
-class DummyZCMLContext(object):
- package = None
- registry = None
- autocommit = False
- route_prefix = None
- basepath = None
- includepath = ()
- info = ''
-
-class DummyIntrospector(object):
- def __init__(self):
- self.intrs = []
- def add(self, intr):
- self.intrs.append(intr)
-
class DummyIntrospectable(object):
def __init__(self):
self.registered = []
diff --git a/pyramid/tests/test_registry.py b/pyramid/tests/test_registry.py
index 29803346a..11019b852 100644
--- a/pyramid/tests/test_registry.py
+++ b/pyramid/tests/test_registry.py
@@ -254,52 +254,6 @@ class TestIntrospector(unittest.TestCase):
del inst._categories['category']
self.assertRaises(KeyError, inst.related, intr)
-class Test_noop_introspector(unittest.TestCase):
- def _makeOne(self):
- from pyramid.registry import noop_introspector
- return noop_introspector
-
- def test_conformance(self):
- from zope.interface.verify import verifyObject
- from pyramid.interfaces import IIntrospector
- verifyObject(IIntrospector, self._makeOne())
-
- def test_add(self):
- inst = self._makeOne()
- self.assertEqual(inst.add('a'), None)
-
- def test_get(self):
- inst = self._makeOne()
- self.assertEqual(inst.get('category', 'd', default='123'), '123')
-
- def test_get_category(self):
- inst = self._makeOne()
- self.assertEqual(inst.get_category('category', default='123'), '123')
-
- def test_categorized(self):
- inst = self._makeOne()
- self.assertEqual(inst.categorized(), [])
-
- def test_categories(self):
- inst = self._makeOne()
- self.assertEqual(inst.categories(), [])
-
- def test_remove(self):
- inst = self._makeOne()
- self.assertEqual(inst.remove('cat', 'discrim'), None)
-
- def test_relate(self):
- inst = self._makeOne()
- self.assertEqual(inst.relate(), None)
-
- def test_unrelate(self):
- inst = self._makeOne()
- self.assertEqual(inst.unrelate(), None)
-
- def test_related(self):
- inst = self._makeOne()
- self.assertEqual(inst.related('a'), [])
-
class TestIntrospectable(unittest.TestCase):
def _getTargetClass(slf):
from pyramid.registry import Introspectable