diff options
author | Guido van Rossum <guido@python.org> | 1996-07-22 15:23:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-07-22 15:23:25 (GMT) |
commit | 5c971677a5433aff7c1150e39bde222c24c26f39 (patch) | |
tree | 64d0b425bebe8c8a74d6ce51bc4a61817ef388f9 /Lib/dos-8x3/nturl2pa.py | |
parent | ad8b3baa919f5ab1201fca0e608905851f24e967 (diff) | |
download | cpython-5c971677a5433aff7c1150e39bde222c24c26f39.zip cpython-5c971677a5433aff7c1150e39bde222c24c26f39.tar.gz cpython-5c971677a5433aff7c1150e39bde222c24c26f39.tar.bz2 |
Fuck. For PC support, this must be in the distribution.
Diffstat (limited to 'Lib/dos-8x3/nturl2pa.py')
-rwxr-xr-x | Lib/dos-8x3/nturl2pa.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/dos-8x3/nturl2pa.py b/Lib/dos-8x3/nturl2pa.py new file mode 100755 index 0000000..17f01f5 --- /dev/null +++ b/Lib/dos-8x3/nturl2pa.py @@ -0,0 +1,52 @@ +# +# nturl2path convert a NT pathname to a file URL and +# vice versa + +def url2pathname(url): + """ Convert a URL to a DOS path... + Currently only works for absolute paths + + ///C|/foo/bar/spam.foo + + becomes + + C:\foo\bar\spam.foo + """ + import string + comp = string.splitfields(url, '|') + if len(comp) != 2 or comp[0][-1] not in string.letters: + error = 'Bad URL: ' + url + raise IOError, error + drive = string.upper(comp[0][-1]) + components = string.splitfields(comp[1], '/') + path = drive + ':' + for comp in components: + if comp: + path = path + '\\' + comp + return path + +def pathname2url(p): + + """ Convert a DOS path name to a file url... + Currently only works for absolute paths + + C:\foo\bar\spam.foo + + becomes + + ///C|/foo/bar/spam.foo + """ + + import string + comp = string.splitfields(p, ':') + if len(comp) != 2 or len(comp[0]) > 1: + error = 'Bad path: ' + p + raise IOError, error + + drive = string.upper(comp[0]) + components = string.splitfields(comp[1], '\\') + path = '///' + drive + '|' + for comp in components: + if comp: + path = path + '/' + comp + return path |