Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented custom static path, such as, 'web.config.static_path = "/…

…data/my_static" '.
  • Loading branch information...
commit 55d7d1987d71091e4bbdc9ba07dd0b050b2ea71a 1 parent d6a1b87
@shuge shuge authored
Showing with 25 additions and 0 deletions.
  1. +25 −0 web/httpserver.py
View
25 web/httpserver.py
@@ -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 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
Please sign in to comment.
Something went wrong with that request. Please try again.