summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-02-18 16:53:57 -0500
committerChris McDonough <chrism@plope.com>2012-02-18 16:53:57 -0500
commit8b59f6a32f7851be0152caaa94ffe5e0366b8815 (patch)
tree1827e44c6ae66358107b909950516108dec1abbe
parent4c49ad3306522ce4b1806ac7175447d7e8a3c3a9 (diff)
downloadpyramid-8b59f6a32f7851be0152caaa94ffe5e0366b8815.tar.gz
pyramid-8b59f6a32f7851be0152caaa94ffe5e0366b8815.tar.bz2
pyramid-8b59f6a32f7851be0152caaa94ffe5e0366b8815.zip
dont allow a registration for the request type in add_resource_url_adapter (we can always add it later, but can never take it away); squash an import warning
-rw-r--r--docs/narr/hooks.rst2
-rw-r--r--pyramid/config/adapters.py25
-rw-r--r--pyramid/tests/test_config/test_adapters.py15
-rw-r--r--pyramid/traversal.py5
4 files changed, 16 insertions, 31 deletions
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst
index a782b9ec6..eaccc14a3 100644
--- a/docs/narr/hooks.rst
+++ b/docs/narr/hooks.rst
@@ -495,7 +495,7 @@ For example:
from myapp.traversal import ResourceURLAdapter
from myapp.resources import MyRoot
- config.add_resource_url_adapter(ResourceURLAdapter, resource_iface=MyRoot)
+ config.add_resource_url_adapter(ResourceURLAdapter, MyRoot)
In the above example, the ``myapp.traversal.ResourceURLAdapter`` class will
be used to provide services to :meth:`~pyramid.request.Request.resource_url`
diff --git a/pyramid/config/adapters.py b/pyramid/config/adapters.py
index b6dfdaf41..5f15f2e46 100644
--- a/pyramid/config/adapters.py
+++ b/pyramid/config/adapters.py
@@ -150,8 +150,7 @@ class AdaptersConfiguratorMixin(object):
self.action(discriminator, register, introspectables=(intr,))
@action_method
- def add_resource_url_adapter(self, adapter, resource_iface=None,
- request_iface=None):
+ def add_resource_url_adapter(self, adapter, resource_iface=None):
"""
When you add a traverser as described in
:ref:`changing_the_traverser`, it's convenient to continue to use the
@@ -175,13 +174,7 @@ class AdaptersConfiguratorMixin(object):
the resource should possess for this url adapter to be used when
:meth:`pyramid.request.Request.resource_url` looks up a resource url
adapter. If ``resource_iface`` is not passed, or it is passed as
- ``None``, the adapter will be used for every type of resource.
-
- The ``request_iface`` argument represents a class or interface that
- the request should possess for this url adapter to be used when
- :meth:`pyramid.request.Request.resource_url` looks up a resource url
- adapter. If ``request_iface`` is not epassed, or it is passed as
- ``None``, the adapter will be used for every type of request.
+ ``None``, the url adapter will be used for every type of resource.
See :ref:`changing_resource_url` for more information.
@@ -191,29 +184,23 @@ class AdaptersConfiguratorMixin(object):
"""
adapter = self.maybe_dotted(adapter)
resource_iface = self.maybe_dotted(resource_iface)
- request_iface = self.maybe_dotted(request_iface)
- def register(resource_iface=resource_iface,
- request_iface=request_iface):
+ def register(resource_iface=resource_iface):
if resource_iface is None:
resource_iface = Interface
- if request_iface is None:
- request_iface = Interface
self.registry.registerAdapter(
adapter,
- (resource_iface, request_iface),
+ (resource_iface, Interface),
IResourceURL,
)
- discriminator = ('resource url adapter', resource_iface, request_iface)
+ discriminator = ('resource url adapter', resource_iface)
intr = self.introspectable(
'resource url adapters',
discriminator,
- 'resource url adapter for resource iface %r, request_iface %r' % (
- resource_iface, request_iface),
+ 'resource url adapter for resource iface %r' % resource_iface,
'resource url adapter',
)
intr['adapter'] = adapter
intr['resource_iface'] = resource_iface
- intr['request_iface'] = request_iface
self.action(discriminator, register, introspectables=(intr,))
diff --git a/pyramid/tests/test_config/test_adapters.py b/pyramid/tests/test_config/test_adapters.py
index b89571639..83ea0f05b 100644
--- a/pyramid/tests/test_config/test_adapters.py
+++ b/pyramid/tests/test_config/test_adapters.py
@@ -160,7 +160,6 @@ class AdaptersConfiguratorMixinTests(unittest.TestCase):
config.add_resource_url_adapter(
'pyramid.tests.test_config.test_adapters.DummyResourceURL',
'pyramid.tests.test_config.test_adapters.DummyIface',
- 'pyramid.tests.test_config.test_adapters.DummyIface',
)
iface = DummyIface()
adapter = config.registry.getMultiAdapter((iface, iface),
@@ -169,7 +168,7 @@ class AdaptersConfiguratorMixinTests(unittest.TestCase):
self.assertEqual(adapter.resource, iface)
self.assertEqual(adapter.request, iface)
- def test_add_resource_url_default_interfaces_mean_Interface(self):
+ def test_add_resource_url_default_resource_iface_means_Interface(self):
from pyramid.interfaces import IResourceURL
config = self._makeOne(autocommit=True)
config.add_resource_url_adapter(DummyResourceURL)
@@ -180,12 +179,11 @@ class AdaptersConfiguratorMixinTests(unittest.TestCase):
self.assertEqual(adapter.resource, iface)
self.assertEqual(adapter.request, iface)
- def test_add_resource_url_nodefault_interfaces(self):
+ def test_add_resource_url_nodefault_resource_iface(self):
from zope.interface import Interface
from pyramid.interfaces import IResourceURL
config = self._makeOne(autocommit=True)
- config.add_resource_url_adapter(DummyResourceURL, DummyIface,
- DummyIface)
+ config.add_resource_url_adapter(DummyResourceURL, DummyIface)
iface = DummyIface()
adapter = config.registry.getMultiAdapter((iface, iface),
IResourceURL)
@@ -208,18 +206,15 @@ class AdaptersConfiguratorMixinTests(unittest.TestCase):
intr = intrs[0]
self.assertEqual(intr.type_name, 'resource url adapter')
self.assertEqual(intr.discriminator,
- ('resource url adapter', DummyIface, None))
+ ('resource url adapter', DummyIface))
self.assertEqual(intr.category_name, 'resource url adapters')
self.assertEqual(
intr.title,
"resource url adapter for resource iface "
- "<class 'pyramid.tests.test_config.test_adapters.DummyIface'>, "
- "request_iface None"
+ "<class 'pyramid.tests.test_config.test_adapters.DummyIface'>"
)
self.assertEqual(intr['adapter'], DummyResourceURL)
self.assertEqual(intr['resource_iface'], DummyIface)
- self.assertEqual(intr['request_iface'], None)
-
class DummyTraverser(object):
def __init__(self, root):
diff --git a/pyramid/traversal.py b/pyramid/traversal.py
index 3b2c96021..b514d4c16 100644
--- a/pyramid/traversal.py
+++ b/pyramid/traversal.py
@@ -9,12 +9,15 @@ from repoze.lru import lru_cache
from pyramid.interfaces import (
IResourceURL,
- IContextURL,
IRequestFactory,
ITraverser,
VH_ROOT_KEY,
)
+with warnings.catch_warnings():
+ warnings.filterwarnings('ignore')
+ from pyramid.interfaces import IContextURL
+
from pyramid.compat import (
PY3,
native_,