From e4fae16023ed4975cf3529c6f5e30641c4e2aa1f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 11 Apr 2019 02:41:13 +0000 Subject: [PATCH] There's a simpler way to do it --- devel/devel-server.py | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/devel/devel-server.py b/devel/devel-server.py index 79e1ce3..1a6167d 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -47,32 +47,12 @@ class MothRequestHandler(http.server.SimpleHTTPRequestHandler): # Backport from Python 3.7 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] - # Don't forget explicit trailing slash when normalizing. Issue17324 - trailing_slash = path.rstrip().endswith('/') - try: - path = urllib.parse.unquote(path, errors='surrogatepass') - except UnicodeDecodeError: - path = urllib.parse.unquote(path) - path = posixpath.normpath(path) - words = path.split('/') - words = filter(None, words) - path = self.directory - for word in words: - if os.path.dirname(word) or word in (os.curdir, os.pardir): - # Ignore components that are not a simple file/directory name - continue - path = os.path.join(path, word) - if trailing_slash: - path += '/' - return path + # I guess we just hope that some other thread doesn't call getcwd + getcwd = os.getcwd + os.getcwd = lambda: self.directory + ret = super().translate_path(path) + os.getcwd = getcwd + return ret def get_puzzle(self):