Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I has implemented custom static path, fixed #130 #131

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore 100644 → 100755
@@ -1,2 +1,5 @@
*.pyc
.DS_Store
.DS_Store
build/
dist/
.idea/
25 changes: 25 additions & 0 deletions web/httpserver.py
Expand Up @@ -203,6 +203,31 @@ def __init__(self, environ, start_response):
self.environ = environ
self.start_response = start_response

def translate_path(self, path):
"""Translate a /-separated PATH to the local filename syntax.

Components that mean special things to the local file system
(e.g. drive or directory names) are ignored. (XXX They should
probably be diagnosed.)

"""
# abandon query parameters
path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib.unquote(path))
words = path.split('/')
words = filter(None, words)
if hasattr(web.config, "static_path"):
path = os.path.dirname(web.config.static_path)
else:
path = os.getcwd()
for word in words:
drive, word = os.path.splitdrive(word)
head, word = os.path.split(word)
if word in (os.curdir, os.pardir): continue
path = os.path.join(path, word)
return path

def send_response(self, status, msg=""):
self.status = str(status) + " " + msg

Expand Down
10 changes: 5 additions & 5 deletions web/template.py
Expand Up @@ -1049,11 +1049,11 @@ def _load_template(self, name):

render = Render
# setup render for Google App Engine.
try:
from google import appengine
render = Render = GAE_Render
except ImportError:
pass
# try:
# from google import appengine
# render = Render = GAE_Render
#except ImportError:
# pass

def frender(path, **keywords):
"""Creates a template from the given file path.
Expand Down