Chris McDonough
2011-07-06 fca1efe07ac46b2817f30299bbebbc2031cce339
- The ``config.scan`` method has grown a ``**kw`` argument.  ``kw`` argument
represents a set of keyword arguments to pass to the Venusian ``Scanner``
object created by Pyramid. (See the Venusian documentation for more
information about ``Scanner``).
1 files added
4 files modified
49 ■■■■■ changed files
CHANGES.txt 5 ●●●●● patch | view | raw | blame | history
docs/whatsnew-1.1.rst 5 ●●●●● patch | view | raw | blame | history
pyramid/config.py 20 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_config.py 5 ●●●●● patch | view | raw | blame | history
pyramid/tests/venusianapp/__init__.py 14 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -4,6 +4,11 @@
Features
--------
- The ``config.scan`` method has grown a ``**kw`` argument.  ``kw`` argument
  represents a set of keyword arguments to pass to the Venusian ``Scanner``
  object created by Pyramid.  (See the Venusian documentation for more
  information about ``Scanner``).
- New request attribute: ``json``. If the request's ``content_type`` is
  ``application/json``, this attribute will contain the JSON-decoded
  variant of the request body.  If the request's ``content_type`` is not
docs/whatsnew-1.1.rst
@@ -94,6 +94,11 @@
Minor Feature Additions
-----------------------
- The :meth:`pyramid.config.Configurator.scan` method has grown a ``**kw``
  argument.  ``kw`` argument represents a set of keyword arguments to pass to
  the Venusian ``Scanner`` object created by Pyramid.  (See the
  :term:`Venusian` documentation for more information about ``Scanner``).
- New request attribute: ``json``. If the request's ``content_type`` is
  ``application/json``, this attribute will contain the JSON-decoded
  variant of the request body.  If the request's ``content_type`` is not
pyramid/config.py
@@ -1950,7 +1950,7 @@
        return mapper
    # this is *not* an action method (uses caller_package)
    def scan(self, package=None, categories=None):
    def scan(self, package=None, categories=None, **kw):
        """Scan a Python package and any of its subpackages for objects
        marked with :term:`configuration decoration` such as
        :class:`pyramid.view.view_config`.  Any decorated object found will
@@ -1970,12 +1970,28 @@
        :class:`pyramid.view.view_config`.  See the :term:`Venusian`
        documentation for more information about limiting a scan by using an
        explicit set of categories.
        To perform a ``scan``, Pyramid creates a Venusian ``Scanner`` object.
        The ``kw`` argument represents a set of keyword arguments to pass to
        the Venusian ``Scanner`` object's constructor.  See the
        :term:`venusian` documentation (its ``Scanner`` class) for more
        information.  By default, the only keyword arguments passed to the
        Scanner constructor are ``{'config':self}`` where ``self`` is this
        configurator object.  This services the requirement of all built-in
        Pyramid decorators, but extension systems may require additional
        arguments.  Providing this argument is not often necessary; it's an
        advanced usage.
        .. note:: the ``**kw`` argument is new in Pyramid 1.1
        """
        package = self.maybe_dotted(package)
        if package is None: # pragma: no cover
            package = caller_package()
        scanner = self.venusian.Scanner(config=self)
        scankw = {'config':self}
        scankw.update(kw)
        scanner = self.venusian.Scanner(**scankw)
        scanner.scan(package, categories=categories)
    @action_method
pyramid/tests/test_config.py
@@ -2848,6 +2848,11 @@
        result = render_view_to_response(ctx, req, '')
        self.assertEqual(result, 'grokked')
    def test_scan_integration_with_extra_kw(self):
        config = self._makeOne(autocommit=True)
        config.scan('pyramid.tests.venusianapp', a=1)
        self.assertEqual(config.a, 1)
    def test_testing_securitypolicy(self):
        from pyramid.testing import DummySecurityPolicy
        config = self._makeOne(autocommit=True)
pyramid/tests/venusianapp/__init__.py
New file
@@ -0,0 +1,14 @@
import venusian
def foo(wrapped):
    def bar(scanner, name, wrapped):
        scanner.config.a = scanner.a
    venusian.attach(wrapped, bar)
    return wrapped
@foo
def hello():
    pass
hello() # appease coverage