summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-12-04 17:01:04 -0500
committerChris McDonough <chrism@plope.com>2011-12-04 17:01:04 -0500
commit7d109d6522353bf5f5f3ca4f29bc2b27542f2ef2 (patch)
tree8832cb859529825f64c177d93f9de937c9a0aaf4
parentd2ed7edee5991a795597a4d8e14a7bcf84113748 (diff)
downloadpyramid-7d109d6522353bf5f5f3ca4f29bc2b27542f2ef2.tar.gz
pyramid-7d109d6522353bf5f5f3ca4f29bc2b27542f2ef2.tar.bz2
pyramid-7d109d6522353bf5f5f3ca4f29bc2b27542f2ef2.zip
allow config.action to take arbitrary kw args
-rw-r--r--CHANGES.txt10
-rw-r--r--TODO.txt6
-rw-r--r--pyramid/config/__init__.py77
3 files changed, 53 insertions, 40 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6ba72fc06..44f948180 100644
--- a/CHANGES.txt
+++ b/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
---------
diff --git a/TODO.txt b/TODO.txt
index 4692b073b..1253b9b16 100644
--- a/TODO.txt
+++ b/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.
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index 3b15e8ef2..315cdef07 100644
--- a/pyramid/config/__init__.py
+++ b/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 @@ class Configurator(
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 @@ class Configurator(
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 @@ class Configurator(
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 @@ class ActionState(object):
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)