MCPcopy Index your code
hub / github.com/RustPython/RustPython / url2pathname

Function url2pathname

Lib/urllib/request.py:1659–1695  ·  view source on GitHub ↗

Convert the given file URL to a local file system path. The 'file:' scheme prefix must be omitted unless *require_scheme* is set to true. The URL authority may be resolved with gethostbyname() if *resolve_host* is set to true.

(url, *, require_scheme=False, resolve_host=False)

Source from the content-addressed store, hash-verified

1657# Code moved from the old urllib module
1658
1659def url2pathname(url, *, require_scheme=False, resolve_host=False):
1660 """Convert the given file URL to a local file system path.
1661
1662 The 'file:' scheme prefix must be omitted unless *require_scheme*
1663 is set to true.
1664
1665 The URL authority may be resolved with gethostbyname() if
1666 *resolve_host* is set to true.
1667 """
1668 if not require_scheme:
1669 url = 'file:' + url
1670 scheme, authority, url = urlsplit(url)[:3] # Discard query and fragment.
1671 if scheme != 'file':
1672 raise URLError("URL is missing a 'file:' scheme")
1673 if os.name == 'nt':
1674 if authority[1:2] == ':':
1675 # e.g. file://c:/file.txt
1676 url = authority + url
1677 elif not _is_local_authority(authority, resolve_host):
1678 # e.g. file://server/share/file.txt
1679 url = '//' + authority + url
1680 elif url[:3] == '///':
1681 # e.g. file://///server/share/file.txt
1682 url = url[1:]
1683 else:
1684 if url[:1] == '/' and url[2:3] in (':', '|'):
1685 # Skip past extra slash before DOS drive in URL path.
1686 url = url[1:]
1687 if url[1:2] == '|':
1688 # Older URLs use a pipe after a drive letter
1689 url = url[:1] + ':' + url[2:]
1690 url = url.replace('/', '\\')
1691 elif not _is_local_authority(authority, resolve_host):
1692 raise URLError("file:// scheme is supported only on localhost")
1693 encoding = sys.getfilesystemencoding()
1694 errors = sys.getfilesystemencodeerrors()
1695 return unquote(url, encoding=encoding, errors=errors)
1696
1697
1698def pathname2url(pathname, *, add_scheme=False):

Callers 2

from_uriMethod · 0.90
open_local_fileMethod · 0.70

Calls 5

urlsplitFunction · 0.90
URLErrorClass · 0.90
unquoteFunction · 0.90
_is_local_authorityFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected