Skip to content

Commit

Permalink
don't call build_dispatch_tree in __init__ (#84)
Browse files Browse the repository at this point in the history
This commit removes the call to `build_dispatch_tree()` from `Dispatcher.__init__()`, so that it can easily be delayed if desired.
  • Loading branch information
Changaco committed Sep 13, 2019
1 parent b0c2c10 commit 71788da
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions aspen/request_processor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def safe_getcwd(errorstr):
self.www_root, self.is_dynamic, self.indices, self.typecasters,
**kwargs.get('dispatcher_options', {})
)
self.dispatcher.build_dispatch_tree()

# mime.types
# ==========
Expand Down
3 changes: 1 addition & 2 deletions aspen/request_processor/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,9 @@ def __init__(
self.typecasters = typecasters
self.file_skipper = file_skipper
self.collision_handler = collision_handler
self.build_dispatch_tree()

def build_dispatch_tree(self):
"""Called by :meth:`.__init__` to build the dispatch tree.
"""Called to build the dispatch tree.
Subclasses **must** implement this method.
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_dispatcher_returns_a_result(dispatcher_class):
indices = ['index.html'],
typecasters = {},
)
dispatcher.build_dispatch_tree()
result = dispatcher.dispatch('/', [''])
assert result.status == DispatchStatus.okay
assert result.match == os.path.join(www.root, 'index.html')
Expand All @@ -83,6 +84,7 @@ def test_dispatcher_returns_unindexed_for_unindexed_directory(dispatcher_class):
indices = [],
typecasters = {},
)
dispatcher.build_dispatch_tree()
r = dispatcher.dispatch('/', [''])
assert r.status == DispatchStatus.unindexed
assert r.match == www.root + os.path.sep
Expand All @@ -102,6 +104,7 @@ def test_dispatch_when_filesystem_has_been_modified():
indices = ['index.html'],
typecasters = {},
))
dispatchers[-1].build_dispatch_tree()
# Now add an index file and try to dispatch
www.mk(('index.html', 'Greetings, program!'))
for dispatcher in dispatchers:
Expand Down

0 comments on commit 71788da

Please sign in to comment.