Pastebin

Paste #480: translate_path

< previous paste - next paste>

Pasted by Morten

Download View as text

     68     def translate_path(self, path):
     69         """Translate a /-separated PATH to the local filename syntax.
     70
     71         Components that mean special things to the local file system
     72         (e.g. drive or directory names) are ignored.  (XXX They should
     73         probably be diagnosed.)
     74
     75         """
     76         # abandon query parameters
     77         path = urlparse.urlparse(path)[2]
     78
     79         print path
     80
     81
     82         tmp = path.split("cgi-bin/")
     83
     84         if len(tmp) == 2 and self.is_cgi() == False:
     85                 print "CGI-request, setting correct cgi-bin directory"
     86                 print "tmp:"
     87                 print tmp
     88                 path = "home/bonaldo/mig/cgi-bin/".join(tmp[1])
     89                 print path
     90
     91         else:
     92
     93                 path = posixpath.normpath(urllib.unquote(path))
     94                 words = path.split('/')
     95                 words = filter(None, words)
     96                 path = os.getcwd()
     97                 for word in words:
     98                     drive, word = os.path.splitdrive(word)
     99                     head, word = os.path.split(word)
    100                     if word in (os.curdir, os.pardir): continue
    101                     path = os.path.join(path, word)
    102
    103
    104         print "final path:"
    105         print path
    106
    107         return path

New Paste


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

Go to most recent paste.