summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-12-07 22:06:51 -0500
committerChris McDonough <chrism@plope.com>2010-12-07 22:06:51 -0500
commit9175e9a5a6f62076a038327a2c9d0fe297d1ba60 (patch)
treeb11ab90c84b3c87de9992131608b8a776de19898
parentd17ecbf8fef39cd41398ab64b3cadeb7aed65f56 (diff)
downloadpyramid-9175e9a5a6f62076a038327a2c9d0fe297d1ba60.tar.gz
pyramid-9175e9a5a6f62076a038327a2c9d0fe297d1ba60.tar.bz2
pyramid-9175e9a5a6f62076a038327a2c9d0fe297d1ba60.zip
reenable autocommit support
-rw-r--r--pyramid/configuration.py55
-rw-r--r--pyramid/tests/test_configuration.py12
2 files changed, 41 insertions, 26 deletions
diff --git a/pyramid/configuration.py b/pyramid/configuration.py
index 8cdb7512b..568d3ede8 100644
--- a/pyramid/configuration.py
+++ b/pyramid/configuration.py
@@ -103,15 +103,15 @@ if chameleon_text:
if chameleon_zpt:
DEFAULT_RENDERERS += (('.txt', chameleon_text.renderer_factory),)
-## def config_method(wrapped):
-## def wrapper(self, *arg, **kw):
-## result = wrapped(self, *arg, **kw)
-## if self.registry.autocommit:
-## self.commit()
-## return result
-## wrapper.__doc__ = wrapped.__doc__
-## wrapper.__name__ = wrapped.__name__
-## return wrapper
+def config_method(wrapped):
+ def wrapper(self, *arg, **kw):
+ result = wrapped(self, *arg, **kw)
+ if self._ctx.autocommit:
+ self.commit()
+ return result
+ wrapper.__doc__ = wrapped.__doc__
+ wrapper.__name__ = wrapped.__name__
+ return wrapper
class Configurator(object):
"""
@@ -239,6 +239,7 @@ class Configurator(object):
renderer_globals_factory=None,
default_permission=None,
session_factory=None,
+ autocommit=False,
):
if package is None:
package = caller_package()
@@ -247,7 +248,7 @@ class Configurator(object):
self.package_name = name_resolver.package_name
self.package = name_resolver.package
self.registry = registry
- self._ctx = self._make_context()
+ self._ctx = self._make_context(autocommit)
if registry is None:
registry = Registry(self.package_name)
self.registry = registry
@@ -283,7 +284,7 @@ class Configurator(object):
self.registry.settings = settings
return settings
- #@config_method
+ @config_method
def _set_root_factory(self, factory):
""" Add a :term:`root factory` to the current configuration
state. If the ``factory`` argument is ``None`` a default root
@@ -296,7 +297,7 @@ class Configurator(object):
self.registry.registerUtility(factory, IDefaultRootFactory) # b/c
self._action(IRootFactory, register)
- #@config_method
+ @config_method
def _set_authentication_policy(self, policy):
""" Add a :app:`Pyramid` :term:`authentication policy` to
the current configuration."""
@@ -304,7 +305,7 @@ class Configurator(object):
self.registry.registerUtility(policy, IAuthenticationPolicy)
self._action(IAuthenticationPolicy)
- #@config_method
+ @config_method
def _set_authorization_policy(self, policy):
""" Add a :app:`Pyramid` :term:`authorization policy` to
the current configuration state (also accepts a :term:`dotted
@@ -386,10 +387,11 @@ class Configurator(object):
if not hasattr(_registry, 'has_listeners'):
_registry.has_listeners = True
- def _make_context(self):
+ def _make_context(self, autocommit=False):
context = PyramidConfigurationMachine()
registerCommonDirectives(context)
context.registry = self.registry
+ context.autocommit = autocommit
return context
# API
@@ -397,7 +399,7 @@ class Configurator(object):
def commit(self):
""" Commit pending configuration actions. """
self._ctx.execute_actions()
- self._ctx = self._make_context()
+ self._ctx = self._make_context(self._ctx.autocommit)
def with_package(self, package, _ctx=None):
""" Return a new Configurator instance with the same registry
@@ -608,7 +610,7 @@ class Configurator(object):
renderer = {'name':renderer, 'package':self.package}
return self._derive_view(view, attr=attr, renderer=renderer)
- #@config_method
+ @config_method
def add_subscriber(self, subscriber, iface=None):
"""Add an event :term:`subscriber` for the event stream
implied by the supplied ``iface`` interface. The
@@ -867,7 +869,7 @@ class Configurator(object):
return route
- #@config_method
+ @config_method
def add_view(self, view=None, name="", for_=None, permission=None,
request_type=None, route_name=None, request_method=None,
request_param=None, containment=None, attr=None,
@@ -1295,7 +1297,7 @@ class Configurator(object):
discriminator = tuple(discriminator)
self._action(discriminator, register)
- #@config_method
+ @config_method
def add_route(self,
name,
pattern=None,
@@ -1692,7 +1694,7 @@ class Configurator(object):
scanner = self.venusian.Scanner(config=self)
scanner.scan(package, categories=categories)
- #@config_method
+ @config_method
def add_renderer(self, name, factory):
"""
Add a :app:`Pyramid` :term:`renderer` factory to the
@@ -1724,7 +1726,7 @@ class Configurator(object):
self.registry.registerUtility(factory, IRendererFactory, name=name)
self._action((IRendererFactory, name), None)
- #@config_method
+ @config_method
def override_resource(self, to_override, override_with, _override=None):
""" Add a :app:`Pyramid` resource override to the current
configuration state.
@@ -1846,7 +1848,7 @@ class Configurator(object):
return view(context, request)
return self.add_view(bwcompat_view, context=NotFound, wrapper=wrapper)
- #@config_method
+ @config_method
def set_request_factory(self, factory):
""" The object passed as ``factory`` should be an object (or a
:term:`dotted Python name` which refers to an object) which
@@ -1865,7 +1867,7 @@ class Configurator(object):
self.registry.registerUtility(factory, IRequestFactory)
self._action(IRequestFactory, register)
- #@config_method
+ @config_method
def set_renderer_globals_factory(self, factory):
""" The object passed as ``factory`` should be an callable (or
a :term:`dotted Python name` which refers to an callable) that
@@ -1889,7 +1891,7 @@ class Configurator(object):
self.registry.registerUtility(factory, IRendererGlobalsFactory)
self._action(IRendererGlobalsFactory, register)
- #@config_method
+ @config_method
def set_locale_negotiator(self, negotiator):
"""
Set the :term:`locale negotiator` for this application. The
@@ -1913,7 +1915,7 @@ class Configurator(object):
self.registry.registerUtility(negotiator, ILocaleNegotiator)
self._action(ILocaleNegotiator, register)
- #@config_method
+ @config_method
def set_default_permission(self, permission):
"""
Set the default permission to be used by all subsequent
@@ -1944,7 +1946,7 @@ class Configurator(object):
self.registry.registerUtility(permission, IDefaultPermission)
self._action(IDefaultPermission, None)
- #@config_method
+ @config_method
def set_session_factory(self, session_factory):
"""
Configure the application with a :term:`session factory`. If
@@ -1955,7 +1957,7 @@ class Configurator(object):
self.registry.registerUtility(session_factory, ISessionFactory)
self._action(ISessionFactory, register)
- #@config_method
+ @config_method
def add_translation_dirs(self, *specs):
""" Add one or more :term:`translation directory` paths to the
current configuration state. The ``specs`` argument is a
@@ -2868,6 +2870,7 @@ class ActionPredicate(object):
return hash(self.action)
class PyramidConfigurationMachine(ConfigurationMachine):
+ autocommit = False
def action(self, discriminator, callable, args=(), kw=None, order=0):
if kw is None:
kw = {}
diff --git a/pyramid/tests/test_configuration.py b/pyramid/tests/test_configuration.py
index 21f6a4f44..3edddb8e9 100644
--- a/pyramid/tests/test_configuration.py
+++ b/pyramid/tests/test_configuration.py
@@ -3484,6 +3484,18 @@ class ConfiguratorTests(unittest.TestCase):
registeredview = self._getViewCallable(config)
self.assertEqual(registeredview.__name__, 'view3')
+ def test_autocommit_no_conflicts(self):
+ config = self._makeOne(autocommit=True)
+ def view1(request): pass
+ def view2(request): pass
+ def view3(request): pass
+ config.add_view(view1)
+ config.add_view(view2)
+ config.add_view(view3)
+ config.commit()
+ registeredview = self._getViewCallable(config)
+ self.assertEqual(registeredview.__name__, 'view3')
+
class Test__map_view(unittest.TestCase):
def setUp(self):
from pyramid.registry import Registry