diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-07-12 13:37:51 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-07-12 13:37:51 +0000 |
| commit | 9336d44d79232b021cc5f871aa43a384958e1920 (patch) | |
| tree | e601ad3e09d6cbc0833767dc83022e94b271da46 | |
| parent | 8139c97cbea01dc4e4f3ce2840e7359389775621 (diff) | |
| download | pyramid-9336d44d79232b021cc5f871aa43a384958e1920.tar.gz pyramid-9336d44d79232b021cc5f871aa43a384958e1920.tar.bz2 pyramid-9336d44d79232b021cc5f871aa43a384958e1920.zip | |
- Fix regression in
``repoze.bfg.configuration.Configurator.add_static_view``. Before
1.3a4, view names that contained a slash were supported as route
prefixes. 1.3a4 broke this by trying to treat them as full URLs.
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | repoze/bfg/static.py | 11 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_static.py | 14 |
3 files changed, 24 insertions, 12 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 53b857314..04f1f0726 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,14 @@ +Next release +============ + +Bug Fixes +--------- + +- Fix regression in + ``repoze.bfg.configuration.Configurator.add_static_view``. Before + 1.3a4, view names that contained a slash were supported as route + prefixes. 1.3a4 broke this by trying to treat them as full URLs. + 1.3a4 (2010-07-03) ================== diff --git a/repoze/bfg/static.py b/repoze/bfg/static.py index f2dfa7897..36a855dfb 100644 --- a/repoze/bfg/static.py +++ b/repoze/bfg/static.py @@ -1,6 +1,7 @@ import os import pkg_resources from urlparse import urljoin +from urlparse import urlparse from paste import httpexceptions from paste import request @@ -94,10 +95,10 @@ class StaticURLInfo(object): self.registrations = [] def generate(self, path, request, **kw): - for (name, spec) in self.registrations: + for (name, spec, is_url) in self.registrations: if path.startswith(spec): subpath = path[len(spec):] - if '/' in name: + if is_url: return urljoin(name, subpath[1:]) else: kw['subpath'] = subpath @@ -111,11 +112,12 @@ class StaticURLInfo(object): idx = names.index(name) self.registrations.pop(idx) - if '/' in name: + if urlparse(name)[0]: # it's a URL if not name.endswith('/'): # make sure it ends with a slash name = name + '/' + self.registrations.append((name, spec, True)) else: # it's a view name _info = extra.pop('_info', None) @@ -130,8 +132,7 @@ class StaticURLInfo(object): factory=lambda *x: self, _info=_info ) - - self.registrations.append((name, spec)) + self.registrations.append((name, spec, False)) class static_view(object): """ An instance of this class is a callable which can act as a diff --git a/repoze/bfg/tests/test_static.py b/repoze/bfg/tests/test_static.py index f857f63a8..508db0d90 100644 --- a/repoze/bfg/tests/test_static.py +++ b/repoze/bfg/tests/test_static.py @@ -256,21 +256,21 @@ class TestStaticURLInfo(unittest.TestCase): def test_generate_slash_in_name1(self): inst = self._makeOne(None) - inst.registrations = [('http://example.com/foo/', 'package:path')] + inst.registrations = [('http://example.com/foo/', 'package:path', True)] request = DummyRequest() result = inst.generate('package:path/abc', request) self.assertEqual(result, 'http://example.com/foo/abc') def test_generate_slash_in_name2(self): inst = self._makeOne(None) - inst.registrations = [('http://example.com/foo/', 'package:path')] + inst.registrations = [('http://example.com/foo/', 'package:path', True)] request = DummyRequest() result = inst.generate('package:path', request) self.assertEqual(result, 'http://example.com/foo/') def test_generate_route_url(self): inst = self._makeOne(None) - inst.registrations = [('viewname', 'package:path')] + inst.registrations = [('viewname', 'package:path', False)] def route_url(n, r, **kw): self.assertEqual(n, 'viewname') self.assertEqual(r, request) @@ -285,19 +285,19 @@ class TestStaticURLInfo(unittest.TestCase): inst = self._makeOne(None) inst.registrations = [('http://example.com/', 'package:path')] inst.add('http://example.com/', 'anotherpackage:path') - expected = [('http://example.com/', 'anotherpackage:path')] + expected = [('http://example.com/', 'anotherpackage:path', True)] self.assertEqual(inst.registrations, expected) def test_add_url_withendslash(self): inst = self._makeOne(None) inst.add('http://example.com/', 'anotherpackage:path') - expected = [('http://example.com/', 'anotherpackage:path')] + expected = [('http://example.com/', 'anotherpackage:path', True)] self.assertEqual(inst.registrations, expected) def test_add_url_noendslash(self): inst = self._makeOne(None) inst.add('http://example.com', 'anotherpackage:path') - expected = [('http://example.com/', 'anotherpackage:path')] + expected = [('http://example.com/', 'anotherpackage:path', True)] self.assertEqual(inst.registrations, expected) def test_add_viewname(self): @@ -309,7 +309,7 @@ class TestStaticURLInfo(unittest.TestCase): config = Config() inst = self._makeOne(config) inst.add('view', 'anotherpackage:path', cache_max_age=1) - expected = [('view', 'anotherpackage:path')] + expected = [('view', 'anotherpackage:path', False)] self.assertEqual(inst.registrations, expected) self.assertEqual(config.arg, ('view', 'view*subpath')) self.assertEqual(config.kw['_info'], None) |
