Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: nturl2path.py
"""Convert a NT pathname to a file URL and vice versa.
[0] Fix | Delete
[1] Fix | Delete
This module only exists to provide OS-specific code
[2] Fix | Delete
for urllib.requests, thus do not use directly.
[3] Fix | Delete
"""
[4] Fix | Delete
# Testing is done through test_urllib.
[5] Fix | Delete
[6] Fix | Delete
def url2pathname(url):
[7] Fix | Delete
"""OS-specific conversion from a relative URL of the 'file' scheme
[8] Fix | Delete
to a file system path; not recommended for general use."""
[9] Fix | Delete
# e.g.
[10] Fix | Delete
# ///C|/foo/bar/spam.foo
[11] Fix | Delete
# and
[12] Fix | Delete
# ///C:/foo/bar/spam.foo
[13] Fix | Delete
# become
[14] Fix | Delete
# C:\foo\bar\spam.foo
[15] Fix | Delete
import string, urllib.parse
[16] Fix | Delete
# Windows itself uses ":" even in URLs.
[17] Fix | Delete
url = url.replace(':', '|')
[18] Fix | Delete
if not '|' in url:
[19] Fix | Delete
# No drive specifier, just convert slashes
[20] Fix | Delete
if url[:4] == '////':
[21] Fix | Delete
# path is something like ////host/path/on/remote/host
[22] Fix | Delete
# convert this to \\host\path\on\remote\host
[23] Fix | Delete
# (notice halving of slashes at the start of the path)
[24] Fix | Delete
url = url[2:]
[25] Fix | Delete
components = url.split('/')
[26] Fix | Delete
# make sure not to convert quoted slashes :-)
[27] Fix | Delete
return urllib.parse.unquote('\\'.join(components))
[28] Fix | Delete
comp = url.split('|')
[29] Fix | Delete
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
[30] Fix | Delete
error = 'Bad URL: ' + url
[31] Fix | Delete
raise OSError(error)
[32] Fix | Delete
drive = comp[0][-1].upper()
[33] Fix | Delete
components = comp[1].split('/')
[34] Fix | Delete
path = drive + ':'
[35] Fix | Delete
for comp in components:
[36] Fix | Delete
if comp:
[37] Fix | Delete
path = path + '\\' + urllib.parse.unquote(comp)
[38] Fix | Delete
# Issue #11474 - handing url such as |c/|
[39] Fix | Delete
if path.endswith(':') and url.endswith('/'):
[40] Fix | Delete
path += '\\'
[41] Fix | Delete
return path
[42] Fix | Delete
[43] Fix | Delete
def pathname2url(p):
[44] Fix | Delete
"""OS-specific conversion from a file system path to a relative URL
[45] Fix | Delete
of the 'file' scheme; not recommended for general use."""
[46] Fix | Delete
# e.g.
[47] Fix | Delete
# C:\foo\bar\spam.foo
[48] Fix | Delete
# becomes
[49] Fix | Delete
# ///C:/foo/bar/spam.foo
[50] Fix | Delete
import urllib.parse
[51] Fix | Delete
# First, clean up some special forms. We are going to sacrifice
[52] Fix | Delete
# the additional information anyway
[53] Fix | Delete
if p[:4] == '\\\\?\\':
[54] Fix | Delete
p = p[4:]
[55] Fix | Delete
if p[:4].upper() == 'UNC\\':
[56] Fix | Delete
p = '\\' + p[4:]
[57] Fix | Delete
elif p[1:2] != ':':
[58] Fix | Delete
raise OSError('Bad path: ' + p)
[59] Fix | Delete
if not ':' in p:
[60] Fix | Delete
# No drive specifier, just convert slashes and quote the name
[61] Fix | Delete
if p[:2] == '\\\\':
[62] Fix | Delete
# path is something like \\host\path\on\remote\host
[63] Fix | Delete
# convert this to ////host/path/on/remote/host
[64] Fix | Delete
# (notice doubling of slashes at the start of the path)
[65] Fix | Delete
p = '\\\\' + p
[66] Fix | Delete
components = p.split('\\')
[67] Fix | Delete
return urllib.parse.quote('/'.join(components))
[68] Fix | Delete
comp = p.split(':', maxsplit=2)
[69] Fix | Delete
if len(comp) != 2 or len(comp[0]) > 1:
[70] Fix | Delete
error = 'Bad path: ' + p
[71] Fix | Delete
raise OSError(error)
[72] Fix | Delete
[73] Fix | Delete
drive = urllib.parse.quote(comp[0].upper())
[74] Fix | Delete
components = comp[1].split('\\')
[75] Fix | Delete
path = '///' + drive + ':'
[76] Fix | Delete
for comp in components:
[77] Fix | Delete
if comp:
[78] Fix | Delete
path = path + '/' + urllib.parse.quote(comp)
[79] Fix | Delete
return path
[80] Fix | Delete
[81] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function