summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/narr/urldispatch.rst23
-rw-r--r--repoze/bfg/tests/routesapp/configure.zcml2
-rw-r--r--repoze/bfg/tests/test_urldispatch.py21
-rw-r--r--repoze/bfg/tests/test_zcml.py10
-rw-r--r--repoze/bfg/urldispatch.py32
-rw-r--r--repoze/bfg/zcml.py22
6 files changed, 53 insertions, 57 deletions
diff --git a/docs/narr/urldispatch.rst b/docs/narr/urldispatch.rst
index e6e5287c1..ef445427c 100644
--- a/docs/narr/urldispatch.rst
+++ b/docs/narr/urldispatch.rst
@@ -104,16 +104,16 @@ name.
The context object passed to a view found as the result of URL
dispatch will be an instance of the
``repoze.bfg.urldispatch.RoutesContext`` object. You can override
-this behavior by passing in a ``context_factory`` argument to the ZCML
-directive for a particular route. The ``context_factory`` should be a
+this behavior by passing in a ``factory`` argument to the ZCML
+directive for a particular route. The ``factory`` should be a
callable that accepts arbitrary keyword arguments and returns an
instance of a class that will be the context used by the view.
The context object will be decorated by default with the
``repoze.bfg.interfaces.IRoutesContext`` interface. To decorate a
context found via a route with other interfaces, you can use a
-``context_interfaces`` attribute on the ZCML statement. It should be
-a space-separated list of dotted Python names that point at interfaces.
+``provides`` attribute on the ZCML statement. It should be a
+space-separated list of dotted Python names that point at interfaces.
If no route matches in the above configuration, :mod:`repoze.bfg` will
call the "fallback" ``get_root`` callable provided to it during
@@ -139,8 +139,8 @@ function is as follows:
<route
path="archives/:article"
view_name="articles"
- context_factory=".models.Article"
- context_interfaces=".interfaces.ISomeContext"
+ factory=".models.Article"
+ provides=".interfaces.ISomeContext"
/>
All context objects found via Routes URL dispatch will provide the
@@ -178,11 +178,11 @@ called. This framework operates in terms of ACLs (Access Control
Lists, see :ref:`security_chapter` for more information about the
:mod:`repoze.bfg` security subsystem). A common thing to want to do
is to attach an ``__acl__`` to the context object dynamically for
-declarative security purposes. You can use the ``context_factory``
+declarative security purposes. You can use the ``factory``
argument that points at a context factory which attaches a custom
``__acl__`` to an object at its creation time.
-Such a ``context_factory`` might look like so:
+Such a ``factory`` might look like so:
.. code-block:: python
:linenos:
@@ -191,7 +191,7 @@ Such a ``context_factory`` might look like so:
def __init__(self, **kw):
self.__dict__.update(kw)
- def article_context_factory(**kw):
+ def article_factory(**kw):
model = Article(**kw)
article = kw.get('article', None)
if article == '1':
@@ -203,8 +203,9 @@ is ``1``, :mod:`repoze.bfg` will generate an ``Article``
:term:`context` with an ACL on it that allows the ``editor`` principal
the ``view`` permission. Obviously you can do more generic things
that inspect the routes match dict to see if the ``article`` argument
-matches a particular string; our sample ``article_context_factory``
-function is not very ambitious.
+matches a particular string; our sample ``article_factory`` function
+is not very ambitious. It could have just as well been done in the
+class' constructor, too.
.. note:: See :ref:`security_chapter` for more information about
:mod:`repoze.bfg` security and ACLs.
diff --git a/repoze/bfg/tests/routesapp/configure.zcml b/repoze/bfg/tests/routesapp/configure.zcml
index 388fc2330..acd1d9d9e 100644
--- a/repoze/bfg/tests/routesapp/configure.zcml
+++ b/repoze/bfg/tests/routesapp/configure.zcml
@@ -4,7 +4,7 @@
<route
path=":id/:view_name"
- context_interfaces=".models.IFixture"/>
+ provides=".models.IFixture"/>
<view
name="default"
diff --git a/repoze/bfg/tests/test_urldispatch.py b/repoze/bfg/tests/test_urldispatch.py
index 82d4af991..e332351a7 100644
--- a/repoze/bfg/tests/test_urldispatch.py
+++ b/repoze/bfg/tests/test_urldispatch.py
@@ -49,11 +49,7 @@ class RoutesMapperTests(unittest.TestCase):
marker = ()
get_root = make_get_root(marker)
mapper = self._makeOne(get_root)
- from zope.interface import implements, Interface
- class IDummy(Interface):
- pass
class Dummy(object):
- implements(IDummy)
def __init__(self, **kw):
self.__dict__.update(kw)
mapper.connect('archives/:action/:article', controller='foo',
@@ -66,7 +62,6 @@ class RoutesMapperTests(unittest.TestCase):
from repoze.bfg.interfaces import IRoutesContext
self.failUnless(IRoutesContext.providedBy(result))
self.failUnless(isinstance(result, Dummy))
- self.failUnless(IDummy.providedBy(result))
self.failIf(hasattr(result, 'context_factory'))
def test_url_for(self):
@@ -123,8 +118,8 @@ class RoutesRootFactoryTests(unittest.TestCase):
mapper = self._makeOne(get_root)
class DummyRoute:
routepath = ':id'
- context_factory = None
- context_interfaces = ()
+ _factory = None
+ _provides = ()
la = unicode('\xc3\xb1a', 'utf-8')
mapper.routematch = lambda *arg: ({la:'id'}, DummyRoute)
mapper.connect(':la')
@@ -143,7 +138,7 @@ class RoutesRootFactoryTests(unittest.TestCase):
from repoze.bfg.urldispatch import RoutesContextNotFound
self.failUnless(isinstance(result, RoutesContextNotFound))
- def test_custom_context_factory(self):
+ def test_custom_factory(self):
marker = ()
get_root = make_get_root(marker)
mapper = self._makeOne(get_root)
@@ -155,7 +150,7 @@ class RoutesRootFactoryTests(unittest.TestCase):
def __init__(self, **kw):
self.__dict__.update(kw)
mapper.connect('archives/:action/:article', view_name='foo',
- context_factory=Dummy)
+ _factory=Dummy)
environ = self._getEnviron(PATH_INFO='/archives/action1/article1')
result = mapper(environ)
self.assertEqual(result.view_name, 'foo')
@@ -165,9 +160,9 @@ class RoutesRootFactoryTests(unittest.TestCase):
self.failUnless(IRoutesContext.providedBy(result))
self.failUnless(isinstance(result, Dummy))
self.failUnless(IDummy.providedBy(result))
- self.failIf(hasattr(result, 'context_factory'))
+ self.failIf(hasattr(result, '_factory'))
- def test_custom_context_interfaces(self):
+ def test_custom_provides(self):
marker = ()
get_root = make_get_root(marker)
mapper = self._makeOne(get_root)
@@ -175,7 +170,7 @@ class RoutesRootFactoryTests(unittest.TestCase):
class IDummy(Interface):
pass
mapper.connect('archives/:action/:article', view_name='foo',
- context_interfaces = [IDummy])
+ _provides = [IDummy])
environ = self._getEnviron(PATH_INFO='/archives/action1/article1')
result = mapper(environ)
self.assertEqual(result.view_name, 'foo')
@@ -184,7 +179,7 @@ class RoutesRootFactoryTests(unittest.TestCase):
from repoze.bfg.interfaces import IRoutesContext
self.failUnless(IRoutesContext.providedBy(result))
self.failUnless(IDummy.providedBy(result))
- self.failIf(hasattr(result, 'context_interfaces'))
+ self.failIf(hasattr(result, '_provides'))
def test_has_routes(self):
mapper = self._makeOne(None)
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index 26de9481a..a2653f262 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -290,7 +290,7 @@ class TestConnectRouteFunction(unittest.TestCase):
parent_member_name='p', parent_collection_name='c',
condition_method='GET', condition_subdomain=True,
condition_function=foo, subdomains=['a'],
- context_factory=foo, context_interfaces=[IDummy])
+ factory=foo, provides=[IDummy])
self._callFUT(directive)
self.assertEqual(len(mapper.connections), 1)
self.assertEqual(mapper.connections[0][0], ('a/b/c',))
@@ -308,8 +308,8 @@ class TestConnectRouteFunction(unittest.TestCase):
'_collection_name':'c',
'_parent_resource':pr,
'conditions':c,
- 'context_factory':foo,
- 'context_interfaces':[IDummy],
+ '_factory':foo,
+ '_provides':[IDummy],
})
def test_condition_subdomain_true(self):
@@ -760,8 +760,8 @@ class DummyRouteDirective:
subdomains = None
path = 'a/b/c'
name = None
- context_factory = None
- context_interfaces = ()
+ factory = None
+ provides = ()
def __init__(self, **kw):
if not 'requirements' in kw:
kw['requirements'] = {}
diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py
index 1881ebb07..f1470cd25 100644
--- a/repoze/bfg/urldispatch.py
+++ b/repoze/bfg/urldispatch.py
@@ -85,7 +85,7 @@ class RoutesMapper(object):
def connect(self, *arg, **kw):
""" Add a route to the Routes mapper associated with this
request. This method accepts the same arguments as a Routes
- *Mapper* object. One difference exists: if the
+ *Mapper* object. One differences exists: if the
``context_factory`` is passed in with a value as a keyword
argument, this callable will be called when a model object
representing the ``context`` for the request needs to be
@@ -117,7 +117,7 @@ class RoutesRootFactory(Mapper):
Any view that claims it is 'for' the interface
``repoze.bfg.interfaces.IRoutesContext`` will be called if its
*name* matches the Routes ``view_name`` name for the match and any
- of the interfaces named in ``context_interfaces``. It will be
+ of the interfaces named in ``_provides``. It will be
passed a context object that has attributes that match the Routes
match arguments dictionary keys. If no Routes route matches the
current request, the 'fallback' get_root is called."""
@@ -135,15 +135,15 @@ class RoutesRootFactory(Mapper):
def connect(self, *arg, **kw):
# we need to deal with our custom attributes specially :-(
- context_factory = None
- context_interfaces = ()
- if 'context_interfaces' in kw:
- context_interfaces = kw.pop('context_interfaces')
- if 'context_factory' in kw:
- context_factory = kw.pop('context_factory')
+ factory = None
+ provides = ()
+ if '_provides' in kw:
+ provides = kw.pop('_provides')
+ if '_factory' in kw:
+ factory = kw.pop('_factory')
result = Mapper.connect(self, *arg, **kw)
- self.matchlist[-1].context_factory = context_factory
- self.matchlist[-1].context_interfaces = context_interfaces
+ self.matchlist[-1]._factory = factory
+ self.matchlist[-1]._provides = provides
return result
def __call__(self, environ):
@@ -160,9 +160,9 @@ class RoutesRootFactory(Mapper):
if args:
args = args.copy()
routepath = route.routepath
- context_factory = route.context_factory
- if not context_factory:
- context_factory = DefaultRoutesContext
+ factory = route._factory
+ if not factory:
+ factory = DefaultRoutesContext
config = request_config()
config.mapper = self
config.mapper_dict = args
@@ -176,9 +176,9 @@ class RoutesRootFactory(Mapper):
if k.__class__ is unicode:
k = k.encode('utf-8')
kw[k] = v
- context = context_factory(**kw)
- context_interfaces = route.context_interfaces
- for iface in context_interfaces:
+ context = factory(**kw)
+ provides = route._provides
+ for iface in provides:
alsoProvides(context, iface)
alsoProvides(context, IRoutesContext)
return context
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index 72839495d..463090146 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -273,9 +273,9 @@ class IRouteDirective(Interface):
"""
path = TextLine(title=u'path', required=True)
name = TextLine(title=u'name', required=False)
- context_factory = GlobalObject(title=u'context_factory', required=False)
- context_interfaces = Tokens(title=u'context_interfaces', required=False,
- value_type=GlobalObject())
+ factory = GlobalObject(title=u'context factory', required=False)
+ provides = Tokens(title=u'context interfaces', required=False,
+ value_type=GlobalObject())
minimize = Bool(title=u'minimize', required=False)
encoding = TextLine(title=u'path', required=False)
static = Bool(title=u'static', required=False)
@@ -336,10 +336,10 @@ def connect_route(directive):
if conditions:
kw['conditions'] = conditions
- if directive.context_factory:
- kw['context_factory'] = directive.context_factory
- if directive.context_interfaces:
- kw['context_interfaces'] = directive.context_interfaces
+ if directive.factory:
+ kw['_factory'] = directive.factory
+ if directive.provides:
+ kw['_provides'] = directive.provides
return mapper.connect(*args, **kw)
@@ -349,8 +349,8 @@ class Route(zope.configuration.config.GroupingContextDecorator):
implements(zope.configuration.config.IConfigurationContext,IRouteDirective)
- def __init__(self, context, path, name=None, context_factory=None,
- context_interfaces=(), minimize=True, encoding=None,
+ def __init__(self, context, path, name=None, factory=None,
+ provides=(), minimize=True, encoding=None,
static=False, filter=None, absolute=False,
member_name=None, collection_name=None, condition_method=None,
condition_subdomain=None, condition_function=None,
@@ -359,8 +359,8 @@ class Route(zope.configuration.config.GroupingContextDecorator):
self.context = context
self.path = path
self.name = name
- self.context_factory = context_factory
- self.context_interfaces = context_interfaces
+ self.factory = factory
+ self.provides = provides
self.minimize = minimize
self.encoding = encoding
self.static = static