MCPcopy Index your code
hub / github.com/python/cpython / translate_path

Method translate_path

Lib/http/server.py:870–898  ·  view source on GitHub ↗

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.)

(self, path)

Source from the content-addressed store, hash-verified

868 return f
869
870 def translate_path(self, path):
871 """Translate a /-separated PATH to the local filename syntax.
872
873 Components that mean special things to the local file system
874 (e.g. drive or directory names) are ignored. (XXX They should
875 probably be diagnosed.)
876
877 """
878 # abandon query parameters
879 path = path.split('#', 1)[0]
880 path = path.split('?', 1)[0]
881 # Don't forget explicit trailing slash when normalizing. Issue17324
882 try:
883 path = urllib.parse.unquote(path, errors='surrogatepass')
884 except UnicodeDecodeError:
885 path = urllib.parse.unquote(path)
886 trailing_slash = path.endswith('/')
887 path = posixpath.normpath(path)
888 words = path.split('/')
889 words = filter(None, words)
890 path = self.directory
891 for word in words:
892 if os.path.dirname(word) or word in (os.curdir, os.pardir):
893 # Ignore components that are not a simple file/directory name
894 continue
895 path = os.path.join(path, word)
896 if trailing_slash:
897 path += '/'
898 return path
899
900 def copyfile(self, source, outputfile):
901 """Copy all data between two file objects.

Callers 1

send_headMethod · 0.95

Calls 5

filterFunction · 0.50
splitMethod · 0.45
endswithMethod · 0.45
dirnameMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected