+++ /dev/null
-"""Convert a NT pathname to a file URL and vice versa."""\r
-\r
-def url2pathname(url):\r
- """OS-specific conversion from a relative URL of the 'file' scheme\r
- to a file system path; not recommended for general use."""\r
- # e.g.\r
- # ///C|/foo/bar/spam.foo\r
- # becomes\r
- # C:\foo\bar\spam.foo\r
- import string, urllib\r
- # Windows itself uses ":" even in URLs.\r
- url = url.replace(':', '|')\r
- if not '|' in url:\r
- # No drive specifier, just convert slashes\r
- if url[:4] == '////':\r
- # path is something like ////host/path/on/remote/host\r
- # convert this to \\host\path\on\remote\host\r
- # (notice halving of slashes at the start of the path)\r
- url = url[2:]\r
- components = url.split('/')\r
- # make sure not to convert quoted slashes :-)\r
- return urllib.unquote('\\'.join(components))\r
- comp = url.split('|')\r
- if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:\r
- error = 'Bad URL: ' + url\r
- raise IOError, error\r
- drive = comp[0][-1].upper()\r
- path = drive + ':'\r
- components = comp[1].split('/')\r
- for comp in components:\r
- if comp:\r
- path = path + '\\' + urllib.unquote(comp)\r
- # Issue #11474: url like '/C|/' should convert into 'C:\\'\r
- if path.endswith(':') and url.endswith('/'):\r
- path += '\\'\r
- return path\r
-\r
-def pathname2url(p):\r
- """OS-specific conversion from a file system path to a relative URL\r
- of the 'file' scheme; not recommended for general use."""\r
- # e.g.\r
- # C:\foo\bar\spam.foo\r
- # becomes\r
- # ///C|/foo/bar/spam.foo\r
- import urllib\r
- if not ':' in p:\r
- # No drive specifier, just convert slashes and quote the name\r
- if p[:2] == '\\\\':\r
- # path is something like \\host\path\on\remote\host\r
- # convert this to ////host/path/on/remote/host\r
- # (notice doubling of slashes at the start of the path)\r
- p = '\\\\' + p\r
- components = p.split('\\')\r
- return urllib.quote('/'.join(components))\r
- comp = p.split(':')\r
- if len(comp) != 2 or len(comp[0]) > 1:\r
- error = 'Bad path: ' + p\r
- raise IOError, error\r
-\r
- drive = urllib.quote(comp[0].upper())\r
- components = comp[1].split('\\')\r
- path = '///' + drive + ':'\r
- for comp in components:\r
- if comp:\r
- path = path + '/' + urllib.quote(comp)\r
- return path\r