Skip to content

Commit

Permalink
Remove website.list_directories & .ours_or_theirs
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Oct 3, 2014
1 parent 5e6ac6d commit 78c72c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
23 changes: 17 additions & 6 deletions aspen/algorithms/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,30 @@ def raise_200_for_OPTIONS(request):


def dispatch_request_to_filesystem(website, request):

def handle_directory(result):
if not website.list_directories:
raise Response(404)
result.extra['autoindexdir'] = result.match
result.match = website.ours_or_theirs('autoindex.html.spt')
assert result.match is not None # sanity check
return result

result = dispatcher.dispatch( website
, indices=website.indices
, media_type_default=website.media_type_default
, pathparts=request.line.uri.path.parts
, uripath=request.line.uri.path.raw
, querystring=request.line.uri.querystring.raw
, startdir=website.www_root
, indices = website.indices
, media_type_default = website.media_type_default
, pathparts = request.line.uri.path.parts
, uripath = request.line.uri.path.raw
, querystring = request.line.uri.querystring.raw
, startdir = website.www_root
, handle_directory = handle_directory
)
request.fs = result.match
for k, v in result.wildcards.iteritems():
request.line.uri.path[k] = v
return {'dispatch_result': result}


def apply_typecasters_to_path(website, request):
typecasting.apply_typecasters(website.typecasters, request.line.uri.path)

Expand Down
9 changes: 2 additions & 7 deletions aspen/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def update_neg_type(media_type_default, capture_accept, filename):


def dispatch(website, indices, media_type_default, pathparts, uripath, querystring,
startdir, pure_dispatch=False):
startdir, handle_directory, pure_dispatch=False):
"""Concretize dispatch_abstract.
"""

Expand Down Expand Up @@ -342,12 +342,7 @@ def dispatch(website, indices, media_type_default, pathparts, uripath, querystri

if result.status == DispatchStatus.okay:
if result.match.endswith('/'): # autoindex
if not website.list_directories:
raise Response(404)
result.extra['autoindexdir'] = result.match
result.match = website.ours_or_theirs('autoindex.html.spt')
assert result.match is not None # sanity check
return result # return so we skip the no-escape check
return handle_directory(result) # return so we skip the no-escape check

elif result.status == DispatchStatus.non_leaf: # trailing-slash redirect
location = uripath + '/'
Expand Down
13 changes: 10 additions & 3 deletions tests/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

import os
from pytest import raises
from StringIO import StringIO

import aspen
from aspen import dispatcher, Response
from aspen.http.request import Request


# Helpers
Expand Down Expand Up @@ -58,6 +56,7 @@ def test_dispatcher_returns_a_result(harness):
, '/'
, ''
, harness.fs.www.root
, lambda result: result
)
assert result.status == dispatcher.DispatchStatus.okay
assert result.match == os.path.join(harness.fs.www.root, 'index.html')
Expand All @@ -72,6 +71,7 @@ def test_dispatcher_returns_a_result_for_favicon(harness):
, '/favicon.ico'
, ''
, harness.fs.www.root
, lambda result: result
)
assert result.status == dispatcher.DispatchStatus.okay
assert result.match == harness.client.website.find_ours('favicon.ico')
Expand All @@ -80,14 +80,21 @@ def test_dispatcher_returns_a_result_for_favicon(harness):

def test_dispatcher_returns_a_result_for_autoindex(harness):
harness.client.website.list_directories = True
result = dispatcher.dispatch( harness.client.website
tracer = object()
actual = dispatcher.dispatch( harness.client.website
, []
, ''
, ['']
, '/'
, ''
, harness.fs.www.root
, lambda result: tracer
)
assert actual is tracer

def test_dispatcher_in_algorithm_returns_a_better_result_for_autoindex(harness):
harness.client.website.list_directories = True
result = harness.simple(filepath=None, uripath='/', want='dispatch_result')
assert result.status == dispatcher.DispatchStatus.okay
assert result.match == harness.client.website.find_ours('autoindex.html.spt')
assert result.wildcards == {}
Expand Down

0 comments on commit 78c72c5

Please sign in to comment.