summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Burrows <mjb@asplake.co.uk>2009-12-29 09:39:18 +0000
committerMike Burrows <mjb@asplake.co.uk>2009-12-29 09:39:18 +0000
commitfc211d252f4b9d93ee9b30fa3d288dce13dc11db (patch)
treec018ec59fd7cc6df97b404f74320a21c94587d97
parent5fb4c0a4dadc5fe2486dee255c3991b78918fa87 (diff)
downloadroutes-fc211d252f4b9d93ee9b30fa3d288dce13dc11db.tar.gz
Code layout changes
--HG-- branch : trunk
-rw-r--r--routes/mapper.py84
-rw-r--r--tests/test_functional/test_submapper.py41
2 files changed, 45 insertions, 80 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index b4d54b7..5c378c2 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -77,17 +77,11 @@ class SubMapperParent(object):
"""
return SubMapper(self, **kargs)
- def collection(
- self,
- collection_name,
- resource_name,
- path_prefix=None,
- member_prefix='/{id}',
- controller=None,
- collection_actions=COLLECTION_ACTIONS,
- member_actions = MEMBER_ACTIONS,
- member_options=None,
- **kwargs):
+ def collection(self, collection_name, resource_name, path_prefix=None,
+ member_prefix='/{id}', controller=None,
+ collection_actions=COLLECTION_ACTIONS,
+ member_actions = MEMBER_ACTIONS, member_options=None,
+ **kwargs):
"""Create a submapper that represents a collection.
This results in a :class:`routes.mapper.SubMapper` object, with a
@@ -119,20 +113,14 @@ class SubMapperParent(object):
if path_prefix is None:
path_prefix = '/' + collection_name
- collection = SubMapper(
- self,
- collection_name=collection_name,
- resource_name=resource_name,
- path_prefix=path_prefix,
- controller=controller,
- actions=collection_actions,
- **kwargs)
-
- collection.member = SubMapper(
- collection,
- path_prefix=member_prefix,
- actions=member_actions,
- **(member_options or {}))
+ collection = SubMapper(self, collection_name=collection_name,
+ resource_name=resource_name,
+ path_prefix=path_prefix, controller=controller,
+ actions=collection_actions, **kwargs)
+
+ collection.member = SubMapper(collection, path_prefix=member_prefix,
+ actions=member_actions,
+ **(member_options or {}))
return collection
@@ -190,11 +178,10 @@ class SubMapper(SubMapperParent):
True
"""
- return self.connect(
- name or (rel + '_' + self.resource_name),
- '/' + (rel or name),
- action=action or rel or name,
- **_kwargs_with_conditions(kwargs, method))
+ return self.connect(name or (rel + '_' + self.resource_name),
+ '/' + (rel or name),
+ action=action or rel or name,
+ **_kwargs_with_conditions(kwargs, method))
def new(self, **kwargs):
"""Generates the "new" link for a collection submapper."""
@@ -220,23 +207,20 @@ class SubMapper(SubMapperParent):
True
"""
- return self.connect(
- name or (action + '_' + self.resource_name),
- '',
- action=action or name,
- **_kwargs_with_conditions(kwargs, method))
+ return self.connect(name or (action + '_' + self.resource_name),
+ '',
+ action=action or name,
+ **_kwargs_with_conditions(kwargs, method))
def index(self, name=None, **kwargs):
"""Generates the "index" action for a collection submapper."""
- return self.action(
- name=name or self.collection_name,
- action='index', method='GET', **kwargs)
+ return self.action(name=name or self.collection_name,
+ action='index', method='GET', **kwargs)
def show(self, name = None, **kwargs):
"""Generates the "show" action for a collection member submapper."""
- return self.action(
- name=name or self.resource_name,
- action='show', method='GET', **kwargs)
+ return self.action(name=name or self.resource_name,
+ action='show', method='GET', **kwargs)
def create(self, **kwargs):
"""Generates the "create" action for a collection submapper."""
@@ -388,20 +372,16 @@ class Mapper(SubMapperParent):
else:
return ''
- table = [('Route name', 'Methods', 'Path')] + [
- (
- r.name or '',
- format_methods(r),
- r.routepath or ''
- )
- for r in self.matchlist]
+ table = [('Route name', 'Methods', 'Path')] + \
+ [(r.name or '', format_methods(r), r.routepath or '')
+ for r in self.matchlist]
- widths = [
- max(len(row[col]) for row in table)
- for col in range(len(table[0]))]
+ widths = [max(len(row[col]) for row in table)
+ for col in range(len(table[0]))]
return '\n'.join(
- ' '.join(row[col].ljust(widths[col]) for col in range(len(widths)))
+ ' '.join(row[col].ljust(widths[col])
+ for col in range(len(widths)))
for row in table)
def _envget(self):
diff --git a/tests/test_functional/test_submapper.py b/tests/test_functional/test_submapper.py
index 44439dd..ad95c80 100644
--- a/tests/test_functional/test_submapper.py
+++ b/tests/test_functional/test_submapper.py
@@ -7,9 +7,7 @@ from routes import *
class TestSubmapper(unittest.TestCase):
def test_submapper(self):
m = Mapper()
- c = m.submapper(
- path_prefix='/entries',
- requirements=dict(id='\d+'))
+ c = m.submapper(path_prefix='/entries', requirements=dict(id='\d+'))
c.connect('entry', '/{id}')
eq_('/entries/1', url_for('entry', id=1))
@@ -17,10 +15,8 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_nesting(self):
m = Mapper()
- c = m.submapper(
- path_prefix='/entries',
- controller='entry',
- requirements=dict(id='\d+'))
+ c = m.submapper(path_prefix='/entries', controller='entry',
+ requirements=dict(id='\d+'))
e = c.submapper(path_prefix='/{id}')
eq_('entry', c.resource_name)
@@ -35,9 +31,7 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_action(self):
m = Mapper(explicit=True)
- c = m.submapper(
- path_prefix='/entries',
- controller='entry')
+ c = m.submapper(path_prefix='/entries', controller='entry')
c.action(name='entries', action='list')
c.action(action='create', method='POST')
@@ -50,9 +44,7 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_link(self):
m = Mapper(explicit=True)
- c = m.submapper(
- path_prefix='/entries',
- controller='entry')
+ c = m.submapper(path_prefix='/entries', controller='entry')
c.link(rel='new')
c.link(rel='ping', method='POST')
@@ -66,10 +58,8 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_standard_actions(self):
m = Mapper()
- c = m.submapper(
- path_prefix='/entries',
- collection_name='entries',
- controller='entry')
+ c = m.submapper(path_prefix='/entries', collection_name='entries',
+ controller='entry')
e = c.submapper(path_prefix='/{id}')
c.index()
@@ -89,9 +79,7 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_standard_links(self):
m = Mapper()
- c = m.submapper(
- path_prefix='/entries',
- controller='entry')
+ c = m.submapper(path_prefix='/entries', controller='entry')
e = c.submapper(path_prefix='/{id}')
c.new()
@@ -105,14 +93,11 @@ class TestSubmapper(unittest.TestCase):
def test_submapper_action_and_link_generation(self):
m = Mapper()
- c = m.submapper(
- path_prefix='/entries',
- controller='entry',
- collection_name='entries',
- actions=['index', 'new', 'create'])
- e = c.submapper(
- path_prefix='/{id}',
- actions=['show', 'edit', 'update', 'delete'])
+ c = m.submapper(path_prefix='/entries', controller='entry',
+ collection_name='entries',
+ actions=['index', 'new', 'create'])
+ e = c.submapper(path_prefix='/{id}',
+ actions=['show', 'edit', 'update', 'delete'])
eq_('/entries', url_for('entries', method='GET'))
eq_('/entries', url_for('create_entry', method='POST'))