Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow config.action to take arbitrary kw args

  • Loading branch information...
commit 7d109d6522353bf5f5f3ca4f29bc2b27542f2ef2 1 parent d2ed7ed
@mcdonc mcdonc authored
Showing with 53 additions and 40 deletions.
  1. +5 −5 CHANGES.txt
  2. +0 −6 TODO.txt
  3. +48 −29 pyramid/config/__init__.py
View
10 CHANGES.txt
@@ -30,13 +30,13 @@ Features
- An configuration introspection system was added; see the narrative
documentation chapter entitled "Pyramid Configuration Introspection" for
- more information.
-
-- New APIs: ``pyramid.registry.Introspectable``,
+ more information. New APIs: ``pyramid.registry.Introspectable``,
``pyramid.config.Configurator.introspector``,
``pyramid.config.Configurator.introspectable``,
- ``pyramid.registry.Registry.introspector``. See API docs of related
- modules for more info.
+ ``pyramid.registry.Registry.introspector``.
+
+- Allow extra keyword arguments to be passed to the
+ ``pyramid.config.Configurator.action`` method.
Bug Fixes
---------
View
6 TODO.txt
@@ -12,12 +12,6 @@ Must-Have
* ``default view mapper`` category?
- * ActionInfo for ZCML actions (begin/end lineno/cols?)
-
- * Document ActionInfo.
-
- * categorize() return value ordering not right yet.
-
* implement ptweens and proutes based on introspection instead of current
state of affairs.
View
77 pyramid/config/__init__.py
@@ -239,9 +239,10 @@ class Configurator(
prepended to their pattern. This parameter is new in Pyramid 1.2.
If ``introspector`` is passed, it must be an instance implementing the
- :class:`pyramid.interfaces.IIntrospector` interface. If no
- ``introspector`` is passed, the default IIntrospector implementation will
- be used. This parameter is new in Pyramid 1.3.
+ 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.
"""
manager = manager # for testing injection
venusian = venusian # for testing injection
@@ -498,7 +499,7 @@ def action_info(self):
return info
def action(self, discriminator, callable=None, args=(), kw=None, order=0,
- introspectables=()):
+ introspectables=(), **extra):
""" Register an action which will be executed when
:meth:`pyramid.config.Configurator.commit` is called (or executed
immediately if ``autocommit`` is ``True``).
@@ -511,13 +512,24 @@ def action(self, discriminator, callable=None, args=(), kw=None, order=0,
given, but it can be ``None``, to indicate that the action never
conflicts. It must be a hashable value.
- The ``callable`` is a callable object which performs the action. It
- is optional. ``args`` and ``kw`` are tuple and dict objects
- respectively, which are passed to ``callable`` when this action is
- executed.
+ The ``callable`` is a callable object which performs the task
+ associated with the action when the action is executed. It is
+ optional.
- ``order`` is a crude order control mechanism, only rarely used (has
- no effect when autocommit is ``True``).
+ ``args`` and ``kw`` are tuple and dict objects respectively, which
+ are passed to ``callable`` when this action is executed. Both are
+ optional.
+
+ ``order`` is a grouping mechanism; an action with a lower order will
+ be executed before an action with a higher order (has no effect when
+ autocommit is ``True``).
+
+ ``introspectables`` is a sequence of :term:`introspectable` objects
+ (or the empty sequence if no introspectable objects are associated
+ with this action).
+
+ ``extra`` provides a facility for inserting extra keys and values
+ into an action dictionary.
"""
if kw is None:
kw = {}
@@ -534,16 +546,20 @@ def action(self, discriminator, callable=None, args=(), kw=None, order=0,
introspectable.register(introspector, action_info)
else:
- self.action_state.action(
- discriminator=discriminator,
- callable=callable,
- args=args,
- kw=kw,
- order=order,
- info=action_info,
- includepath=self.includepath,
- introspectables=introspectables,
+ action = extra
+ action.update(
+ dict(
+ discriminator=discriminator,
+ callable=callable,
+ args=args,
+ kw=kw,
+ order=order,
+ info=action_info,
+ includepath=self.includepath,
+ introspectables=introspectables,
+ )
)
+ self.action_state.action(**action)
def _get_action_state(self):
registry = self.registry
@@ -921,20 +937,23 @@ def processSpec(self, spec):
return True
def action(self, discriminator, callable=None, args=(), kw=None, order=0,
- includepath=(), info=None, introspectables=()):
+ includepath=(), info=None, introspectables=(), **extra):
"""Add an action with the given discriminator, callable and arguments
"""
if kw is None:
kw = {}
- action = dict(
- discriminator=discriminator,
- callable=callable,
- args=args,
- kw=kw,
- includepath=includepath,
- info=info,
- order=order,
- introspectables=introspectables,
+ action = extra
+ action.update(
+ dict(
+ discriminator=discriminator,
+ callable=callable,
+ args=args,
+ kw=kw,
+ includepath=includepath,
+ info=info,
+ order=order,
+ introspectables=introspectables,
+ )
)
self.actions.append(action)
Please sign in to comment.
Something went wrong with that request. Please try again.