Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: nturl2path.py
"""Convert a NT pathname to a file URL and vice versa."""
[0] Fix | Delete
[1] Fix | Delete
def url2pathname(url):
[2] Fix | Delete
"""OS-specific conversion from a relative URL of the 'file' scheme
[3] Fix | Delete
to a file system path; not recommended for general use."""
[4] Fix | Delete
# e.g.
[5] Fix | Delete
# ///C|/foo/bar/spam.foo
[6] Fix | Delete
# and
[7] Fix | Delete
# ///C:/foo/bar/spam.foo
[8] Fix | Delete
# become
[9] Fix | Delete
# C:\foo\bar\spam.foo
[10] Fix | Delete
import string, urllib.parse
[11] Fix | Delete
# Windows itself uses ":" even in URLs.
[12] Fix | Delete
url = url.replace(':', '|')
[13] Fix | Delete
if not '|' in url:
[14] Fix | Delete
# No drive specifier, just convert slashes
[15] Fix | Delete
if url[:4] == '////':
[16] Fix | Delete
# path is something like ////host/path/on/remote/host
[17] Fix | Delete
# convert this to \\host\path\on\remote\host
[18] Fix | Delete
# (notice halving of slashes at the start of the path)
[19] Fix | Delete
url = url[2:]
[20] Fix | Delete
components = url.split('/')
[21] Fix | Delete
# make sure not to convert quoted slashes :-)
[22] Fix | Delete
return urllib.parse.unquote('\\'.join(components))
[23] Fix | Delete
comp = url.split('|')
[24] Fix | Delete
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
[25] Fix | Delete
error = 'Bad URL: ' + url
[26] Fix | Delete
raise OSError(error)
[27] Fix | Delete
drive = comp[0][-1].upper()
[28] Fix | Delete
components = comp[1].split('/')
[29] Fix | Delete
path = drive + ':'
[30] Fix | Delete
for comp in components:
[31] Fix | Delete
if comp:
[32] Fix | Delete
path = path + '\\' + urllib.parse.unquote(comp)
[33] Fix | Delete
# Issue #11474 - handing url such as |c/|
[34] Fix | Delete
if path.endswith(':') and url.endswith('/'):
[35] Fix | Delete
path += '\\'
[36] Fix | Delete
return path
[37] Fix | Delete
[38] Fix | Delete
def pathname2url(p):
[39] Fix | Delete
"""OS-specific conversion from a file system path to a relative URL
[40] Fix | Delete
of the 'file' scheme; not recommended for general use."""
[41] Fix | Delete
# e.g.
[42] Fix | Delete
# C:\foo\bar\spam.foo
[43] Fix | Delete
# becomes
[44] Fix | Delete
# ///C:/foo/bar/spam.foo
[45] Fix | Delete
import urllib.parse
[46] Fix | Delete
if not ':' in p:
[47] Fix | Delete
# No drive specifier, just convert slashes and quote the name
[48] Fix | Delete
if p[:2] == '\\\\':
[49] Fix | Delete
# path is something like \\host\path\on\remote\host
[50] Fix | Delete
# convert this to ////host/path/on/remote/host
[51] Fix | Delete
# (notice doubling of slashes at the start of the path)
[52] Fix | Delete
p = '\\\\' + p
[53] Fix | Delete
components = p.split('\\')
[54] Fix | Delete
return urllib.parse.quote('/'.join(components))
[55] Fix | Delete
comp = p.split(':')
[56] Fix | Delete
if len(comp) != 2 or len(comp[0]) > 1:
[57] Fix | Delete
error = 'Bad path: ' + p
[58] Fix | Delete
raise OSError(error)
[59] Fix | Delete
[60] Fix | Delete
drive = urllib.parse.quote(comp[0].upper())
[61] Fix | Delete
components = comp[1].split('\\')
[62] Fix | Delete
path = '///' + drive + ':'
[63] Fix | Delete
for comp in components:
[64] Fix | Delete
if comp:
[65] Fix | Delete
path = path + '/' + urllib.parse.quote(comp)
[66] Fix | Delete
return path
[67] Fix | Delete
[68] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function