__all__ = ["url2pathname","pathname2url"]
def url2pathname(pathname):
- "Convert /-delimited pathname to mac pathname"
+ """OS-specific conversion from a relative URL of the 'file' scheme
+ to a file system path; not recommended for general use."""
#
# XXXX The .. handling should be fixed...
#
return urllib.unquote(rv)
def pathname2url(pathname):
- "convert mac pathname to /-delimited pathname"
+ """OS-specific conversion from a file system path to a relative URL
+ of the 'file' scheme; not recommended for general use."""
if '/' in pathname:
raise RuntimeError, "Cannot convert pathname containing slashes"
components = pathname.split(':')
"""Convert a NT pathname to a file URL and vice versa."""
def url2pathname(url):
- r"""Convert a URL to a DOS path.
-
- ///C|/foo/bar/spam.foo
-
- becomes
-
- C:\foo\bar\spam.foo
- """
+ """OS-specific conversion from a relative URL of the 'file' scheme
+ to a file system path; not recommended for general use."""
+ # e.g.
+ # ///C|/foo/bar/spam.foo
+ # becomes
+ # C:\foo\bar\spam.foo
import string, urllib
# Windows itself uses ":" even in URLs.
url = url.replace(':', '|')
return path
def pathname2url(p):
- r"""Convert a DOS path name to a file url.
-
- C:\foo\bar\spam.foo
-
- becomes
-
- ///C|/foo/bar/spam.foo
- """
-
+ """OS-specific conversion from a file system path to a relative URL
+ of the 'file' scheme; not recommended for general use."""
+ # e.g.
+ # C:\foo\bar\spam.foo
+ # becomes
+ # ///C|/foo/bar/spam.foo
import urllib
if not ':' in p:
# No drive specifier, just convert slashes and quote the name
__slash_dot = string.maketrans("/.", "./")
def url2pathname(url):
- "Convert URL to a RISC OS path."
+ """OS-specific conversion from a relative URL of the 'file' scheme
+ to a file system path; not recommended for general use."""
tp = urllib.splittype(url)[0]
if tp and tp <> 'file':
raise RuntimeError, 'Cannot convert non-local URL to pathname'
return '.'.join(components)
def pathname2url(pathname):
- "Convert a RISC OS path name to a file url."
+ """OS-specific conversion from a file system path to a relative URL
+ of the 'file' scheme; not recommended for general use."""
return urllib.quote('///' + pathname.translate(__slash_dot), "/$:")
def test():
from rourl2path import url2pathname, pathname2url
else:
def url2pathname(pathname):
+ """OS-specific conversion from a relative URL of the 'file' scheme
+ to a file system path; not recommended for general use."""
return unquote(pathname)
+
def pathname2url(pathname):
+ """OS-specific conversion from a file system path to a relative URL
+ of the 'file' scheme; not recommended for general use."""
return quote(pathname)
# This really consists of two pieces: