summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-12-08 02:06:06 -0500
committerChris McDonough <chrism@plope.com>2010-12-08 02:06:06 -0500
commite16ab0ed58eb6675e457a2f57ed4d4d5030cc41a (patch)
tree5a3498d3cec28b75226a3abc37b5b7ac29920fbb
parentbf162ef8a0c9d4267e4a30ea73ef3d90426a90f4 (diff)
downloadpyramid-e16ab0ed58eb6675e457a2f57ed4d4d5030cc41a.tar.gz
pyramid-e16ab0ed58eb6675e457a2f57ed4d4d5030cc41a.tar.bz2
pyramid-e16ab0ed58eb6675e457a2f57ed4d4d5030cc41a.zip
deprecate Configurator, add Config
-rw-r--r--CHANGES.txt19
-rw-r--r--pyramid/configuration.py51
-rw-r--r--pyramid/testing.py20
-rw-r--r--pyramid/tests/test_chameleon_text.py4
-rw-r--r--pyramid/tests/test_chameleon_zpt.py4
-rw-r--r--pyramid/tests/test_configuration.py26
-rw-r--r--pyramid/tests/test_events.py4
-rw-r--r--pyramid/tests/test_integration.py12
-rw-r--r--pyramid/tests/test_mako_templating.py7
-rw-r--r--pyramid/tests/test_request.py4
-rw-r--r--pyramid/tests/test_settings.py4
-rw-r--r--pyramid/tests/test_zcml.py48
-rw-r--r--pyramid/zcml.py38
13 files changed, 150 insertions, 91 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6f8ec355b..dddfecaf7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,22 @@
+Twophase branch
+===============
+
+- ``pyramid.configuration.Config`` was added. It has the same API as the old
+ ``Configurator`` which it means to replace, except by default it is a
+ *non-autocommitting* configurator. It also has a new API method named
+ ``with_context`` (a classmethod).
+
+- ``pyramid.configuration.Configurator`` is now deprecated. Use
+ ``pyramid.configuration.Config`` passing its constructor
+ ``autocommit=True`` instead. The ``pyramid.configuration.Configurator``
+ alias will live for a long time, as every application uses it.
+
+- The ``pyramid.testing.setUp`` function now accepts an ``autocommit``
+ keyword argument, which defaults to ``True``. If it is passed ``False``,
+ the Config object returned by ``setUp`` will be a non-autocommiting Config
+ object.
+
+
Next release
============
diff --git a/pyramid/configuration.py b/pyramid/configuration.py
index 540fa597e..597b23a3e 100644
--- a/pyramid/configuration.py
+++ b/pyramid/configuration.py
@@ -13,6 +13,7 @@ from zope.configuration import xmlconfig
from zope.configuration.config import GroupingContextDecorator
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
+from zope.deprecation import deprecated
from zope.interface import Interface
from zope.interface import implementedBy
@@ -130,7 +131,7 @@ def config_method(wrapped):
wrapper.__name__ = wrapped.__name__
return wrapper
-class Configurator(object):
+class Config(object):
"""
A Configurator is used to configure a :app:`Pyramid`
:term:`application registry`.
@@ -429,7 +430,7 @@ class Configurator(object):
representing a package."""
context = GroupingContextDecorator(self._ctx)
context.package = package
- return Configurator.with_context(context)
+ return self.__class__.with_context(context)
def maybe_dotted(self, dotted):
""" Resolve the :term:`dotted Python name` ``dotted`` to a
@@ -775,7 +776,7 @@ class Configurator(object):
context.basepath = os.path.dirname(filename)
context.includepath = _context.includepath + (spec,)
context.package = package_of(module)
- config = Configurator.with_context(context)
+ config = self.__class__.with_context(context)
func(config)
def add_handler(self, route_name, pattern, handler, action=None, **kw):
@@ -2262,6 +2263,48 @@ class Configurator(object):
testing_add_template = testing_add_renderer
+class Configurator(Config):
+ def __init__(self,
+ registry=None,
+ package=None,
+ settings=None,
+ root_factory=None,
+ authentication_policy=None,
+ authorization_policy=None,
+ renderers=DEFAULT_RENDERERS,
+ debug_logger=None,
+ locale_negotiator=None,
+ request_factory=None,
+ renderer_globals_factory=None,
+ default_permission=None,
+ session_factory=None,
+ autocommit=True,
+ ):
+ if package is None:
+ package = caller_package()
+ Config.__init__(
+ self,
+ registry=registry,
+ package=package,
+ settings=settings,
+ root_factory=root_factory,
+ authentication_policy=authentication_policy,
+ authorization_policy=authorization_policy,
+ renderers=renderers,
+ debug_logger=debug_logger,
+ locale_negotiator=locale_negotiator,
+ request_factory=request_factory,
+ renderer_globals_factory=renderer_globals_factory,
+ default_permission=default_permission,
+ session_factory=session_factory,
+ autocommit=autocommit
+ )
+
+deprecated(
+ 'Configurator',
+ '(pyramid.configuration.Configurator is deprecated as of Pyramid 1.0. Use'
+ '``pyramid.configuration.Config`` with ``autocommit=True`` instead.) ')
+
def _make_predicates(xhr=None, request_method=None, path_info=None,
request_param=None, header=None, accept=None,
containment=None, request_type=None,
@@ -2816,7 +2859,7 @@ def isexception(o):
# note that ``options`` is a b/w compat alias for ``settings`` and
# ``Configurator`` is a testing dep inj
def make_app(root_factory, package=None, filename='configure.zcml',
- settings=None, options=None, Configurator=Configurator):
+ settings=None, options=None, Configurator=Config):
""" Return a Router object, representing a fully configured
:app:`Pyramid` WSGI application.
diff --git a/pyramid/testing.py b/pyramid/testing.py
index 8f4d777db..e6f6c5cab 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -12,7 +12,7 @@ from pyramid.interfaces import ISecuredView
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
-from pyramid.configuration import Configurator
+from pyramid.configuration import Config
from pyramid.exceptions import Forbidden
from pyramid.response import Response
from pyramid.registry import Registry
@@ -56,7 +56,7 @@ def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True):
method in your unit and integration tests.
"""
registry = get_current_registry()
- config = Configurator(registry=registry)
+ config = Config(registry=registry)
result = config.testing_securitypolicy(userid=userid, groupids=groupids,
permissive=permissive)
config.commit()
@@ -80,7 +80,7 @@ def registerModels(models):
method in your unit and integration tests.
"""
registry = get_current_registry()
- config = Configurator(registry=registry)
+ config = Config(registry=registry)
result = config.testing_models(models)
config.commit()
return result
@@ -108,7 +108,7 @@ def registerEventListener(event_iface=None):
method in your unit and integration tests.
"""
registry = get_current_registry()
- config = Configurator(registry=registry)
+ config = Config(registry=registry)
result = config.testing_add_subscriber(event_iface)
config.commit()
return result
@@ -130,7 +130,7 @@ def registerTemplateRenderer(path, renderer=None):
"""
registry = get_current_registry()
- config = Configurator(registry=registry)
+ config = Config(registry=registry)
result = config.testing_add_template(path, renderer)
config.commit()
return result
@@ -256,7 +256,7 @@ def registerSubscriber(subscriber, iface=Interface):
method in your unit and integration tests.
"""
registry = get_current_registry()
- config = Configurator(registry)
+ config = Config(registry)
result = config.add_subscriber(subscriber, iface=iface)
config.commit()
return result
@@ -279,7 +279,7 @@ def registerRoute(pattern, name, factory=None):
method in your unit and integration tests.
"""
reg = get_current_registry()
- config = Configurator(registry=reg)
+ config = Config(registry=reg)
result = config.add_route(name, pattern, factory=factory)
config.commit()
return result
@@ -307,7 +307,7 @@ def registerSettings(dictarg=None, **kw):
method in your unit and integration tests.
"""
registry = get_current_registry()
- config = Configurator(registry=registry)
+ config = Config(registry=registry)
config.add_settings(dictarg, **kw)
class DummyRootFactory(object):
@@ -562,7 +562,7 @@ class DummyRequest(object):
self.response_callbacks = []
self.response_callbacks.append(callback)
-def setUp(registry=None, request=None, hook_zca=True):
+def setUp(registry=None, request=None, hook_zca=True, autocommit=True):
"""
Set :app:`Pyramid` registry and request thread locals for the
duration of a single unit test.
@@ -630,7 +630,7 @@ def setUp(registry=None, request=None, hook_zca=True):
manager.clear()
if registry is None:
registry = Registry('testing')
- config = Configurator(registry=registry)
+ config = Config(registry=registry, autocommit=autocommit)
if hasattr(registry, 'registerUtility'):
# Sometimes nose calls us with a non-registry object because
# it thinks this function is module test setup. Likewise,
diff --git a/pyramid/tests/test_chameleon_text.py b/pyramid/tests/test_chameleon_text.py
index 9486bbc88..79bc7984c 100644
--- a/pyramid/tests/test_chameleon_text.py
+++ b/pyramid/tests/test_chameleon_text.py
@@ -2,6 +2,7 @@ import unittest
from pyramid.testing import cleanUp
from pyramid.testing import skip_on
+from pyramid import testing
class Base:
def setUp(self):
@@ -34,10 +35,9 @@ class Base:
class TextTemplateRendererTests(Base, unittest.TestCase):
def setUp(self):
- from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry()
- self.config = Configurator(registry=registry)
+ self.config = testing.setUp(registry=registry)
self.config.begin()
def tearDown(self):
diff --git a/pyramid/tests/test_chameleon_zpt.py b/pyramid/tests/test_chameleon_zpt.py
index 802f4460f..4601c2f12 100644
--- a/pyramid/tests/test_chameleon_zpt.py
+++ b/pyramid/tests/test_chameleon_zpt.py
@@ -2,6 +2,7 @@ import unittest
from pyramid.testing import cleanUp
from pyramid.testing import skip_on
+from pyramid import testing
class Base(object):
def setUp(self):
@@ -27,10 +28,9 @@ class Base(object):
class ZPTTemplateRendererTests(Base, unittest.TestCase):
def setUp(self):
- from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry()
- self.config = Configurator(registry=registry)
+ self.config = testing.setUp(registry=registry)
self.config.begin()
def tearDown(self):
diff --git a/pyramid/tests/test_configuration.py b/pyramid/tests/test_configuration.py
index aae0faffe..3bdf4a831 100644
--- a/pyramid/tests/test_configuration.py
+++ b/pyramid/tests/test_configuration.py
@@ -7,10 +7,10 @@ try:
except:
__pypy__ = None
-class ConfiguratorTests(unittest.TestCase):
+class ConfigTests(unittest.TestCase):
def _makeOne(self, *arg, **kw):
- from pyramid.configuration import Configurator
- return Configurator(*arg, **kw)
+ from pyramid.configuration import Config
+ return Config(*arg, **kw)
def _registerRenderer(self, config, name='.txt'):
from pyramid.interfaces import IRendererFactory
@@ -87,9 +87,9 @@ class ConfiguratorTests(unittest.TestCase):
def test_ctor_no_registry(self):
import sys
from pyramid.interfaces import ISettings
- from pyramid.configuration import Configurator
+ from pyramid.configuration import Config
from pyramid.interfaces import IRendererFactory
- config = Configurator()
+ config = Config()
this_pkg = sys.modules['pyramid.tests']
self.failUnless(config.registry.getUtility(ISettings))
self.assertEqual(config.package, this_pkg)
@@ -102,8 +102,8 @@ class ConfiguratorTests(unittest.TestCase):
self.failUnless(config.registry.getUtility(IRendererFactory, '.mako'))
def test_begin(self):
- from pyramid.configuration import Configurator
- config = Configurator()
+ from pyramid.configuration import Config
+ config = Config()
manager = DummyThreadLocalManager()
config.manager = manager
config.begin()
@@ -112,8 +112,8 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(manager.popped, False)
def test_begin_with_request(self):
- from pyramid.configuration import Configurator
- config = Configurator()
+ from pyramid.configuration import Config
+ config = Config()
request = object()
manager = DummyThreadLocalManager()
config.manager = manager
@@ -123,8 +123,8 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(manager.popped, False)
def test_end(self):
- from pyramid.configuration import Configurator
- config = Configurator()
+ from pyramid.configuration import Config
+ config = Config()
manager = DummyThreadLocalManager()
config.manager = manager
config.end()
@@ -133,9 +133,9 @@ class ConfiguratorTests(unittest.TestCase):
def test_ctor_with_package_registry(self):
import sys
- from pyramid.configuration import Configurator
+ from pyramid.configuration import Config
pkg = sys.modules['pyramid']
- config = Configurator(package=pkg)
+ config = Config(package=pkg)
self.assertEqual(config.package, pkg)
def test_ctor_noreg_custom_settings(self):
diff --git a/pyramid/tests/test_events.py b/pyramid/tests/test_events.py
index 0cf0cc6dd..9f655959d 100644
--- a/pyramid/tests/test_events.py
+++ b/pyramid/tests/test_events.py
@@ -1,4 +1,5 @@
import unittest
+from pyramid import testing
class NewRequestEventTests(unittest.TestCase):
def _getTargetClass(self):
@@ -122,8 +123,7 @@ class ContextFoundEventTests(unittest.TestCase):
class TestSubscriber(unittest.TestCase):
def setUp(self):
registry = DummyRegistry()
- from pyramid.configuration import Configurator
- self.config = Configurator(registry)
+ self.config = testing.setUp(registry=registry)
self.config.begin()
def tearDown(self):
diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py
index 7dc74aaf8..f7654de78 100644
--- a/pyramid/tests/test_integration.py
+++ b/pyramid/tests/test_integration.py
@@ -31,9 +31,9 @@ class WGSIAppPlusViewConfigTests(unittest.TestCase):
from pyramid.interfaces import IRequest
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
- from pyramid.configuration import Configurator
+ from pyramid.configuration import Config
from pyramid.tests import test_integration
- config = Configurator()
+ config = Config()
config.scan(test_integration)
config.commit()
reg = config.registry
@@ -67,8 +67,8 @@ class TestStaticApp(unittest.TestCase):
class IntegrationBase(unittest.TestCase):
root_factory = None
def setUp(self):
- from pyramid.configuration import Configurator
- config = Configurator(root_factory=self.root_factory)
+ from pyramid.configuration import Config
+ config = Config(root_factory=self.root_factory)
config.begin()
config.load_zcml(self.config)
config.commit()
@@ -243,8 +243,8 @@ class TestExceptionViewsApp(IntegrationBase):
class ImperativeIncludeConfigurationTest(unittest.TestCase):
def setUp(self):
- from pyramid.configuration import Configurator
- config = Configurator()
+ from pyramid.configuration import Config
+ config = Config()
from pyramid.tests.includeapp1.root import configure
configure(config)
app = config.make_wsgi_app()
diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py
index 506dc18cd..4d1c49863 100644
--- a/pyramid/tests/test_mako_templating.py
+++ b/pyramid/tests/test_mako_templating.py
@@ -1,11 +1,11 @@
## come on python gimme some of that sweet, sweet -*- coding: utf-8 -*-
import unittest
+from pyramid import testing
class Base(object):
def setUp(self):
- from pyramid.configuration import Configurator
- self.config = Configurator()
+ self.config = testing.setUp()
self.config.begin()
import os
here = os.path.abspath(os.path.dirname(__file__))
@@ -290,8 +290,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase):
class TestIntegration(unittest.TestCase):
def setUp(self):
import pyramid.mako_templating
- from pyramid.configuration import Configurator
- self.config = Configurator()
+ self.config = testing.setUp()
self.config.begin()
self.config.add_settings({'mako.directories':
'pyramid.tests:fixtures'})
diff --git a/pyramid/tests/test_request.py b/pyramid/tests/test_request.py
index ab985694b..7c6b9f2da 100644
--- a/pyramid/tests/test_request.py
+++ b/pyramid/tests/test_request.py
@@ -1,9 +1,9 @@
import unittest
+from pyramid import testing
class TestRequest(unittest.TestCase):
def setUp(self):
- from pyramid.configuration import Configurator
- self.config = Configurator()
+ self.config = testing.setUp()
self.config.begin()
def tearDown(self):
diff --git a/pyramid/tests/test_settings.py b/pyramid/tests/test_settings.py
index 49c1e928f..cf8fd1119 100644
--- a/pyramid/tests/test_settings.py
+++ b/pyramid/tests/test_settings.py
@@ -1,4 +1,5 @@
import unittest
+from pyramid import testing
class TestSettings(unittest.TestCase):
def _getTargetClass(self):
@@ -179,10 +180,9 @@ class TestSettings(unittest.TestCase):
class TestGetSettings(unittest.TestCase):
def setUp(self):
- from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry('testing')
- self.config = Configurator(registry=registry)
+ self.config = testing.setUp(registry=registry)
self.config.begin()
from zope.deprecation import __show__
__show__.off()
diff --git a/pyramid/tests/test_zcml.py b/pyramid/tests/test_zcml.py
index 2ba6589b5..f66f9f96c 100644
--- a/pyramid/tests/test_zcml.py
+++ b/pyramid/tests/test_zcml.py
@@ -11,7 +11,7 @@ from zope.interface import implements
class TestViewDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -117,7 +117,7 @@ class TestViewDirective(unittest.TestCase):
class TestNotFoundDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -161,9 +161,9 @@ class TestNotFoundDirective(unittest.TestCase):
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.exceptions import NotFound
- from pyramid.configuration import Configurator
+ from pyramid.configuration import Config
reg = self.config.registry
- config = Configurator(reg)
+ config = Config(reg)
def dummy_renderer_factory(*arg, **kw):
return lambda *arg, **kw: 'OK'
config.add_renderer('.pt', dummy_renderer_factory)
@@ -185,7 +185,7 @@ class TestNotFoundDirective(unittest.TestCase):
class TestForbiddenDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -229,9 +229,9 @@ class TestForbiddenDirective(unittest.TestCase):
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.exceptions import Forbidden
- from pyramid.configuration import Configurator
+ from pyramid.configuration import Config
reg = self.config.registry
- config = Configurator(reg)
+ config = Config(reg)
def dummy_renderer_factory(*arg, **kw):
return lambda *arg, **kw: 'OK'
config.add_renderer('.pt', dummy_renderer_factory)
@@ -253,7 +253,7 @@ class TestForbiddenDirective(unittest.TestCase):
class TestRepozeWho1AuthenticationPolicyDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -296,7 +296,7 @@ class TestRepozeWho1AuthenticationPolicyDirective(unittest.TestCase):
class TestRemoteUserAuthenticationPolicyDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -341,7 +341,7 @@ class TestRemoteUserAuthenticationPolicyDirective(unittest.TestCase):
class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -402,7 +402,7 @@ class TestAuthTktAuthenticationPolicyDirective(unittest.TestCase):
class TestACLAuthorizationPolicyDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -430,7 +430,7 @@ class TestACLAuthorizationPolicyDirective(unittest.TestCase):
class TestRouteDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -633,7 +633,7 @@ class TestRouteDirective(unittest.TestCase):
class TestStaticDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -728,7 +728,7 @@ class TestStaticDirective(unittest.TestCase):
class TestResourceDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -757,7 +757,7 @@ class TestResourceDirective(unittest.TestCase):
class TestRendererDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -787,7 +787,7 @@ class TestZCMLConfigure(unittest.TestCase):
def setUp(self):
from zope.deprecation import __show__
__show__.off()
- testing.setUp()
+ testing.setUp(autocommit=False)
self.tempdir = None
import sys
import os
@@ -830,7 +830,7 @@ class TestZCMLConfigure(unittest.TestCase):
class TestZCMLScanDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -853,7 +853,7 @@ class TestZCMLScanDirective(unittest.TestCase):
class TestAdapterDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -944,7 +944,7 @@ class TestAdapterDirective(unittest.TestCase):
class TestSubscriberDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -1022,7 +1022,7 @@ class TestSubscriberDirective(unittest.TestCase):
class TestUtilityDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -1069,7 +1069,7 @@ class TestUtilityDirective(unittest.TestCase):
class TestTranslationDirDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -1091,7 +1091,7 @@ class TestTranslationDirDirective(unittest.TestCase):
class TestLocaleNegotiatorDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -1116,7 +1116,7 @@ class TestLocaleNegotiatorDirective(unittest.TestCase):
class TestDefaultPermissionDirective(unittest.TestCase):
def setUp(self):
- self.config = testing.setUp()
+ self.config = testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
@@ -1139,7 +1139,7 @@ class TestDefaultPermissionDirective(unittest.TestCase):
class TestLoadZCML(unittest.TestCase):
def setUp(self):
- testing.setUp()
+ testing.setUp(autocommit=False)
def tearDown(self):
testing.tearDown()
diff --git a/pyramid/zcml.py b/pyramid/zcml.py
index 3c385742e..6f2fa30e2 100644
--- a/pyramid/zcml.py
+++ b/pyramid/zcml.py
@@ -1,7 +1,5 @@
import os
-from zope.configuration import xmlconfig
-from zope.configuration.config import ConfigurationMachine
from zope.configuration.fields import GlobalInterface
from zope.configuration.fields import GlobalObject
from zope.configuration.fields import Tokens
@@ -21,7 +19,7 @@ from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authentication import RemoteUserAuthenticationPolicy
from pyramid.authentication import RepozeWho1AuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
-from pyramid.configuration import Configurator
+from pyramid.configuration import Config
from pyramid.exceptions import ConfigurationError
from pyramid.resource import resource_spec_from_abspath
from pyramid.threadlocal import get_current_registry
@@ -169,7 +167,7 @@ def view(
context = context or for_
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.add_view(
permission=permission, context=context, view=view, name=name,
request_type=request_type, route_name=route_name,
@@ -268,7 +266,7 @@ def route(_context,
if pattern is None:
raise ConfigurationError('route directive must include a "pattern"')
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.add_route(
name,
pattern,
@@ -317,7 +315,7 @@ def notfound(_context,
renderer=None,
wrapper=None):
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.set_notfound_view(view=view, attr=attr, renderer=renderer,
wrapper=wrapper)
@@ -328,7 +326,7 @@ def forbidden(_context,
renderer=None,
wrapper=None):
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.set_forbidden_view(view=view, attr=attr, renderer=renderer,
wrapper=wrapper)
@@ -348,7 +346,7 @@ class IResourceDirective(Interface):
required=True)
def resource(_context, to_override, override_with, _override=None):
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.override_resource(to_override, override_with, _override=_override)
class IRepozeWho1AuthenticationPolicyDirective(Interface):
@@ -362,7 +360,7 @@ def repozewho1authenticationpolicy(_context, identifier_name='auth_tkt',
callback=callback)
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config._set_authentication_policy(policy)
class IRemoteUserAuthenticationPolicyDirective(Interface):
@@ -376,7 +374,7 @@ def remoteuserauthenticationpolicy(_context, environ_key='REMOTE_USER',
callback=callback)
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config._set_authentication_policy(policy)
class IAuthTktAuthenticationPolicyDirective(Interface):
@@ -418,7 +416,7 @@ def authtktauthenticationpolicy(_context,
raise ConfigurationError(str(why))
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config._set_authentication_policy(policy)
class IACLAuthorizationPolicyDirective(Interface):
@@ -428,7 +426,7 @@ def aclauthorizationpolicy(_context):
policy = ACLAuthorizationPolicy()
# authorization policies must be registered eagerly so they can be
# found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config._set_authorization_policy(policy)
class IRendererDirective(Interface):
@@ -443,7 +441,7 @@ class IRendererDirective(Interface):
def renderer(_context, factory, name=''):
# renderer factories must be registered eagerly so they can be
# found by the view machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.add_renderer(name, factory)
class IStaticDirective(Interface):
@@ -474,7 +472,7 @@ def static(_context, name, path, cache_max_age=3600,
permission='__no_permission_required__'):
""" Handle ``static`` ZCML directives
"""
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.add_static_view(name, path, cache_max_age=cache_max_age,
permission=permission)
@@ -485,7 +483,7 @@ class IScanDirective(Interface):
)
def scan(_context, package):
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.scan(package)
class ITranslationDirDirective(Interface):
@@ -497,7 +495,7 @@ class ITranslationDirDirective(Interface):
def translationdir(_context, dir):
path = path_spec(_context, dir)
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.add_translation_dirs(path)
class ILocaleNegotiatorDirective(Interface):
@@ -508,7 +506,7 @@ class ILocaleNegotiatorDirective(Interface):
)
def localenegotiator(_context, negotiator):
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.set_locale_negotiator(negotiator)
class IAdapterDirective(Interface):
@@ -647,7 +645,7 @@ def subscriber(_context, for_=None, factory=None, handler=None, provides=None):
for_ = tuple(for_)
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
if handler is not None:
config.add_subscriber(handler, for_)
@@ -734,7 +732,7 @@ def default_permission(_context, name):
""" Register a default permission name """
# the default permission must be registered eagerly so it can
# be found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = Config.with_context(_context)
config.set_default_permission(name)
def path_spec(context, path):
@@ -755,7 +753,7 @@ def zcml_configure(name, package):
"""
registry = get_current_registry()
- configurator = Configurator(registry=registry, package=package)
+ configurator = Config(registry=registry, package=package)
configurator.load_zcml(name)
actions = configurator._ctx.actions[:]
configurator.commit()