MCPcopy Index your code
hub / github.com/RustPython/RustPython / translate_path

Method translate_path

Lib/http/server.py:898–926  ·  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

896 return f
897
898 def translate_path(self, path):
899 """Translate a /-separated PATH to the local filename syntax.
900
901 Components that mean special things to the local file system
902 (e.g. drive or directory names) are ignored. (XXX They should
903 probably be diagnosed.)
904
905 """
906 # abandon query parameters
907 path = path.split('#', 1)[0]
908 path = path.split('?', 1)[0]
909 # Don't forget explicit trailing slash when normalizing. Issue17324
910 try:
911 path = urllib.parse.unquote(path, errors='surrogatepass')
912 except UnicodeDecodeError:
913 path = urllib.parse.unquote(path)
914 trailing_slash = path.endswith('/')
915 path = posixpath.normpath(path)
916 words = path.split('/')
917 words = filter(None, words)
918 path = self.directory
919 for word in words:
920 if os.path.dirname(word) or word in (os.curdir, os.pardir):
921 # Ignore components that are not a simple file/directory name
922 continue
923 path = os.path.join(path, word)
924 if trailing_slash:
925 path += '/'
926 return path
927
928 def copyfile(self, source, outputfile):
929 """Copy all data between two file objects.

Callers 2

send_headMethod · 0.95
run_cgiMethod · 0.45

Calls 4

filterFunction · 0.85
splitMethod · 0.45
endswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected