Skip to content

Commit

Permalink
Merge pull request #48 from w3c/jgraham/filesystem_path_fix
Browse files Browse the repository at this point in the history
Explicitly pass the url_base to filesystem_path so the correct paths can be constructed.
  • Loading branch information
jgraham committed Oct 24, 2014
2 parents b192bc6 + a5388a6 commit ee1b4bc
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions wptserve/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ def guess_content_type(path):



def filesystem_path(base_path, request):
def filesystem_path(base_path, request, url_base="/"):
if base_path is None:
base_path = request.doc_root

if "*" in request.route_match:
path = request.route_match["*"]
else:
path = request.url_parts.path
path = request.url_parts.path

if path.startswith("/"):
path = path[1:]
if path.startswith(url_base):
path = path[len(url_base):]

if ".." in path:
raise HTTPException(500)
Expand All @@ -47,11 +44,12 @@ def filesystem_path(base_path, request):


class DirectoryHandler(object):
def __init__(self, base_path=None):
def __init__(self, base_path=None, url_base="/"):
self.base_path = base_path
self.url_base = url_base

def __call__(self, request, response):
path = filesystem_path(self.base_path, request)
path = filesystem_path(self.base_path, request, self.url_base)

assert os.path.isdir(path)

Expand Down Expand Up @@ -95,12 +93,13 @@ def list_items(self, request, path):


class FileHandler(object):
def __init__(self, base_path=None):
def __init__(self, base_path=None, url_base="/"):
self.base_path = base_path
self.url_base = url_base
self.directory_handler = DirectoryHandler(self.base_path)

def __call__(self, request, response):
path = filesystem_path(self.base_path, request)
path = filesystem_path(self.base_path, request, self.url_base)

if os.path.isdir(path):
return self.directory_handler(request, response)
Expand Down Expand Up @@ -199,11 +198,12 @@ def default_headers(self, path):


class PythonScriptHandler(object):
def __init__(self, base_path=None):
def __init__(self, base_path=None, url_base="/"):
self.base_path = base_path
self.url_base = url_base

def __call__(self, request, response):
path = filesystem_path(self.base_path, request)
path = filesystem_path(self.base_path, request, self.url_base)

try:
environ = {"__file__": path}
Expand Down Expand Up @@ -263,11 +263,12 @@ def inner(request, response):


class AsIsHandler(object):
def __init__(self, base_path=None):
def __init__(self, base_path=None, url_base="/"):
self.base_path = base_path
self.url_base = url_base

def __call__(request, response):
path = filesystem_path(self.base_path, request)
path = filesystem_path(self.base_path, request, self.url_base)

try:
with open(path) as f:
Expand Down

0 comments on commit ee1b4bc

Please sign in to comment.