summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-02-16 22:17:42 +0000
committerChris McDonough <chrism@agendaless.com>2009-02-16 22:17:42 +0000
commitb1de627f08e4504a804a49cecacfdd306217f908 (patch)
tree4b17aec2e4577705678d7494a0eac7b9c2aaa319
parent42dd67d04c17a87bebd94bc7d8faca8ea1da9ac0 (diff)
downloadpyramid-b1de627f08e4504a804a49cecacfdd306217f908.tar.gz
pyramid-b1de627f08e4504a804a49cecacfdd306217f908.tar.bz2
pyramid-b1de627f08e4504a804a49cecacfdd306217f908.zip
- Using ``model_url`` or ``model_path`` against a broken model graph
(one with models that had a non-root model with a ``__name__`` of ``None``) caused an inscrutable error to be thrown: ( if not ``_must_quote[cachekey].search(s): TypeError: expected string or buffer``). Now URLs and paths generated against graphs that have None names in intermediate nodes will replace the None with the empty string, and, as a result, the error won't be raised. Of course the URL or path will still be bogus.
-rw-r--r--CHANGES.txt12
-rw-r--r--repoze/bfg/tests/test_traversal.py30
-rw-r--r--repoze/bfg/traversal.py2
3 files changed, 39 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 7e83b1335..85b0a8054 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,15 @@
+Next release
+============
+
+- Using ``model_url`` or ``model_path`` against a broken model graph
+ (one with models that had a non-root model with a ``__name__`` of
+ ``None``) caused an inscrutable error to be thrown: ( if not
+ ``_must_quote[cachekey].search(s): TypeError: expected string or
+ buffer``). Now URLs and paths generated against graphs that have
+ None names in intermediate nodes will replace the None with the
+ empty string, and, as a result, the error won't be raised. Of
+ course the URL or path will still be bogus.
+
0.6.9 (2009-02-16)
==================
diff --git a/repoze/bfg/tests/test_traversal.py b/repoze/bfg/tests/test_traversal.py
index c911ebfed..9cdf04910 100644
--- a/repoze/bfg/tests/test_traversal.py
+++ b/repoze/bfg/tests/test_traversal.py
@@ -418,7 +418,6 @@ class ModelPathTests(unittest.TestCase):
root = DummyContext()
root.__parent__ = None
root.__name__ = None
- request = DummyRequest()
result = self._callFUT(root)
self.assertEqual(result, '/')
@@ -429,10 +428,22 @@ class ModelPathTests(unittest.TestCase):
other = DummyContext()
other.__parent__ = root
other.__name__ = 'other'
- request = DummyRequest()
result = self._callFUT(other)
self.assertEqual(result, '/other')
+ def test_path_with_None_itermediate_names(self):
+ root = DummyContext()
+ root.__parent__ = None
+ root.__name__ = None
+ other = DummyContext()
+ other.__parent__ = root
+ other.__name__ = None
+ other2 = DummyContext()
+ other2.__parent__ = other
+ other2.__name__ = 'other2'
+ result = self._callFUT(other2)
+ self.assertEqual(result, '//other2')
+
class ModelPathTupleTests(unittest.TestCase):
def _callFUT(self, model, *elements):
from repoze.bfg.traversal import model_path_tuple
@@ -459,7 +470,6 @@ class ModelPathTupleTests(unittest.TestCase):
root = DummyContext()
root.__parent__ = None
root.__name__ = None
- request = DummyRequest()
result = self._callFUT(root)
self.assertEqual(result, ('',))
@@ -470,10 +480,22 @@ class ModelPathTupleTests(unittest.TestCase):
other = DummyContext()
other.__parent__ = root
other.__name__ = 'other'
- request = DummyRequest()
result = self._callFUT(other)
self.assertEqual(result, ('', 'other'))
+ def test_path_with_None_itermediate_names(self):
+ root = DummyContext()
+ root.__parent__ = None
+ root.__name__ = None
+ other = DummyContext()
+ other.__parent__ = root
+ other.__name__ = None
+ other2 = DummyContext()
+ other2.__parent__ = other
+ other2.__name__ = 'other2'
+ result = self._callFUT(other2)
+ self.assertEqual(result, ('', '', 'other2'))
+
class QuotePathSegmentTests(unittest.TestCase):
def _callFUT(self, s):
from repoze.bfg.traversal import quote_path_segment
diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py
index 02b6589ac..47ac5fa7f 100644
--- a/repoze/bfg/traversal.py
+++ b/repoze/bfg/traversal.py
@@ -213,7 +213,7 @@ def model_path_tuple(model, *elements):
def _model_path_list(model, *elements):
""" Implementation detail shared by model_path and model_path_tuple """
lpath = reversed(list(lineage(model))[:-1])
- path = [ location.__name__ for location in lpath ]
+ path = [ location.__name__ or '' for location in lpath ]
if elements:
path = path + list(elements)