Permalink
Browse files

Accomodate shift of 'with_context' from pyramid -> pyramid_zcml.

  • Loading branch information...
1 parent 118b494 commit ae34f38060bff772622019e0ac9e088c7292c3f0 @tseaver tseaver committed Jul 25, 2012
Showing with 13 additions and 2 deletions.
  1. +9 −2 cartouche/pyramidpolicy.py
  2. +4 −0 cartouche/tests/test_pyramidpolicy.py
View
@@ -13,10 +13,17 @@
##############################################################################
import os
-from pyramid.config import Configurator
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.security import Authenticated
from pyramid.security import Everyone
+
+try:
+ from pyramid_zcml import with_context
+except ImportError:
+ from pyramid.config import Configurator
+ def with_context(_context):
+ return Configurator.with_context(_context)
+
from repoze.who.config import make_api_factory_with_config as FactoryFactory
from zope.interface import Interface
from zope.interface import implements
@@ -117,5 +124,5 @@ def cartoucheAuthenticationPolicy(_context, config_file, identifier_name):
policy = PyramidPolicy(config_file, identifier_name)
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
- config = Configurator.with_context(_context)
+ config = with_context(_context)
config._set_authentication_policy(policy)
@@ -415,6 +415,7 @@ def extract_actions(native):
class DummyZCMLContext(object):
def __init__(self, config):
+ from pyramid.config import Configurator
if hasattr(config, '_make_context'): # pragma: no cover
# 1.0, 1.1 b/c
config._ctx = config._make_context()
@@ -427,6 +428,9 @@ def __init__(self, config):
self.info = getattr(config, 'info', '')
self.actions = config._ctx.actions
self._ctx = config._ctx
+ # make pyramid_zcml >= 0.9.2 happy
+ self.config_class = Configurator
+ self.introspection = True
def action(self, *arg, **kw): # pragma: no cover
self._ctx.action(*arg, **kw)

0 comments on commit ae34f38

Please sign in to comment.