diff options
| author | John Anderson <sontek@gmail.com> | 2014-12-26 05:06:33 -0800 |
|---|---|---|
| committer | John Anderson <sontek@gmail.com> | 2014-12-26 05:06:33 -0800 |
| commit | 582c2ed180120d07c825e4897350f5d1a6285afa (patch) | |
| tree | a82aab3c080805accfff5f5f5bc26057cfde3601 | |
| parent | a99d2d7e17f4c87d9307215a2ad8d583e74c3a50 (diff) | |
| download | pyramid-582c2ed180120d07c825e4897350f5d1a6285afa.tar.gz pyramid-582c2ed180120d07c825e4897350f5d1a6285afa.tar.bz2 pyramid-582c2ed180120d07c825e4897350f5d1a6285afa.zip | |
Add support for static routes
| -rw-r--r-- | pyramid/config/routes.py | 6 | ||||
| -rw-r--r-- | pyramid/scripts/proutes.py | 9 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/dummy.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_proutes.py | 20 | ||||
| -rw-r--r-- | pyramid/urldispatch.py | 11 |
5 files changed, 44 insertions, 4 deletions
diff --git a/pyramid/config/routes.py b/pyramid/config/routes.py index f1463b50b..509955cdd 100644 --- a/pyramid/config/routes.py +++ b/pyramid/config/routes.py @@ -303,6 +303,8 @@ class RoutesConfiguratorMixin(object): # check for an external route; an external route is one which is # is a full url (e.g. 'http://example.com/{id}') parsed = urlparse.urlparse(pattern) + external_url = pattern + if parsed.hostname: pattern = parsed.path @@ -357,6 +359,10 @@ class RoutesConfiguratorMixin(object): intr['pregenerator'] = pregenerator intr['static'] = static intr['use_global_views'] = use_global_views + + if static is True: + intr['external_url'] = external_url + introspectables.append(intr) if factory: diff --git a/pyramid/scripts/proutes.py b/pyramid/scripts/proutes.py index 917d9af71..2155b4983 100644 --- a/pyramid/scripts/proutes.py +++ b/pyramid/scripts/proutes.py @@ -172,8 +172,13 @@ def get_route_data(route, registry): view_request_methods[view_module] = [] view_request_methods_order.append(view_module) else: - route_request_methods = route_intr['request_methods'] + if route_intr.get('static', False) is True: + return [ + (route.name, route_intr['external_url'], UNKNOWN_KEY, ANY_KEY) + ] + + route_request_methods = route_intr['request_methods'] view_intr = registry.introspector.related(route_intr) if view_intr: @@ -328,7 +333,7 @@ class PRoutesCommand(object): max_view = len('View') max_method = len('Method') - routes = mapper.get_routes() + routes = mapper.get_routes(include_static=True) if len(routes) == 0: return 0 diff --git a/pyramid/tests/test_scripts/dummy.py b/pyramid/tests/test_scripts/dummy.py index 366aa00b5..930b9ed64 100644 --- a/pyramid/tests/test_scripts/dummy.py +++ b/pyramid/tests/test_scripts/dummy.py @@ -60,7 +60,7 @@ class DummyMapper(object): def __init__(self, *routes): self.routes = routes - def get_routes(self): + def get_routes(self, include_static=False): return self.routes class DummyRoute(object): diff --git a/pyramid/tests/test_scripts/test_proutes.py b/pyramid/tests/test_scripts/test_proutes.py index d51baaa01..446d772ff 100644 --- a/pyramid/tests/test_scripts/test_proutes.py +++ b/pyramid/tests/test_scripts/test_proutes.py @@ -666,6 +666,26 @@ class TestPRoutesCommand(unittest.TestCase): self.assertEqual(compare_to, expected) self.assertEqual(L[0].split(), ['Method', 'Name']) + def test_static_routes_included_in_list(self): + from pyramid.renderers import null_renderer as nr + + config = self._makeConfig(autocommit=True) + config.add_route('foo', 'http://example.com/bar.aspx', static=True) + + command = self._makeOne() + L = [] + command.out = L.append + command.bootstrap = (dummy.DummyBootstrap(registry=config.registry),) + result = command.run() + self.assertEqual(result, 0) + self.assertEqual(len(L), 3) + compare_to = L[-1].split() + expected = [ + 'foo', 'http://example.com/bar.aspx', + '<unknown>', '*', + ] + self.assertEqual(compare_to, expected) + class Test_main(unittest.TestCase): def _callFUT(self, argv): from pyramid.scripts.proutes import main diff --git a/pyramid/urldispatch.py b/pyramid/urldispatch.py index fe4d433c3..349742c4a 100644 --- a/pyramid/urldispatch.py +++ b/pyramid/urldispatch.py @@ -42,12 +42,17 @@ class Route(object): class RoutesMapper(object): def __init__(self): self.routelist = [] + self.static_routes = [] + self.routes = {} def has_routes(self): return bool(self.routelist) - def get_routes(self): + def get_routes(self, include_static=False): + if include_static is True: + return self.routelist + self.static_routes + return self.routelist def get_route(self, name): @@ -59,9 +64,13 @@ class RoutesMapper(object): oldroute = self.routes[name] if oldroute in self.routelist: self.routelist.remove(oldroute) + route = Route(name, pattern, factory, predicates, pregenerator) if not static: self.routelist.append(route) + else: + self.static_routes.append(route) + self.routes[name] = route return route |
