Pastebin

Paste #540: translate_path()

< previous paste - next paste>

Pasted by tdn

Download View as text

  1     def translate_path(self, path):
  2         """Translate a /-separated PATH to the local filename syntax.
  3
  4         Components that mean special things to the local file system
  5         (e.g. drive or directory names) are ignored.  (XXX They should
  6         probably be diagnosed.)
  7
  8         """
  9         # abandon query parameters
 10         path = urlparse.urlparse(path)[2]
 11
 12         #The method below limits the number of possible CGI-directories to 1,
 13         #since it is only looking at the first entry in cgi_directories
 14         tmp = path.split(self.cgi_directories[0])
 15
 16         if len(tmp) > 1 and tmp[0]=='':
 17             # CGI-request, setting correct cgi-bin directory
 18             path = tmp[1]
 19             path = cgi_root + path
 20             return path
 21
 22         path = posixpath.normpath(urllib.unquote(path))
 23         words = path.split('/')
 24         words = filter(None, words)
 25         # Make sure we serve documents from document_root
 26         path = document_root
 27         for word in words:
 28             drive, word = os.path.splitdrive(word)
 29             head, word = os.path.split(word)
 30             if word in (os.curdir, os.pardir): continue
 31             path = os.path.join(path, word)
 32         return path
 33

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.