aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Lib/nturl2path.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-12-23 19:39:02 +0300
committershadchin <shadchin@yandex-team.com>2024-12-23 19:54:20 +0300
commit65a5bf9d37a3b29eb394f560b9a09318196c40e8 (patch)
treee5cd68fb0682b2388e52d9806bb87adc348e21a8 /contrib/tools/python3/Lib/nturl2path.py
parenta1dd87a52878ab3e46e5fd2dba5ecbba6113d7e0 (diff)
downloadydb-65a5bf9d37a3b29eb394f560b9a09318196c40e8.tar.gz
Update Python 3 to 3.12.8
commit_hash:c20045b8a987d8720e1f3328270357491d5530f3
Diffstat (limited to 'contrib/tools/python3/Lib/nturl2path.py')
-rw-r--r--contrib/tools/python3/Lib/nturl2path.py54
1 files changed, 21 insertions, 33 deletions
diff --git a/contrib/tools/python3/Lib/nturl2path.py b/contrib/tools/python3/Lib/nturl2path.py
index 61852aff58..757fd01bec 100644
--- a/contrib/tools/python3/Lib/nturl2path.py
+++ b/contrib/tools/python3/Lib/nturl2path.py
@@ -15,32 +15,29 @@ def url2pathname(url):
# become
# C:\foo\bar\spam.foo
import string, urllib.parse
+ if url[:3] == '///':
+ # URL has an empty authority section, so the path begins on the third
+ # character.
+ url = url[2:]
+ elif url[:12] == '//localhost/':
+ # Skip past 'localhost' authority.
+ url = url[11:]
+ if url[:3] == '///':
+ # Skip past extra slash before UNC drive in URL path.
+ url = url[1:]
# Windows itself uses ":" even in URLs.
url = url.replace(':', '|')
if not '|' in url:
# No drive specifier, just convert slashes
- if url[:4] == '////':
- # path is something like ////host/path/on/remote/host
- # convert this to \\host\path\on\remote\host
- # (notice halving of slashes at the start of the path)
- url = url[2:]
- components = url.split('/')
# make sure not to convert quoted slashes :-)
- return urllib.parse.unquote('\\'.join(components))
+ return urllib.parse.unquote(url.replace('/', '\\'))
comp = url.split('|')
if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
error = 'Bad URL: ' + url
raise OSError(error)
drive = comp[0][-1].upper()
- components = comp[1].split('/')
- path = drive + ':'
- for comp in components:
- if comp:
- path = path + '\\' + urllib.parse.unquote(comp)
- # Issue #11474 - handing url such as |c/|
- if path.endswith(':') and url.endswith('/'):
- path += '\\'
- return path
+ tail = urllib.parse.unquote(comp[1].replace('/', '\\'))
+ return drive + ':' + tail
def pathname2url(p):
"""OS-specific conversion from a file system path to a relative URL
@@ -52,30 +49,21 @@ def pathname2url(p):
import urllib.parse
# First, clean up some special forms. We are going to sacrifice
# the additional information anyway
- if p[:4] == '\\\\?\\':
+ p = p.replace('\\', '/')
+ if p[:4] == '//?/':
p = p[4:]
- if p[:4].upper() == 'UNC\\':
- p = '\\' + p[4:]
+ if p[:4].upper() == 'UNC/':
+ p = '//' + p[4:]
elif p[1:2] != ':':
raise OSError('Bad path: ' + p)
if not ':' in p:
- # No drive specifier, just convert slashes and quote the name
- if p[:2] == '\\\\':
- # path is something like \\host\path\on\remote\host
- # convert this to ////host/path/on/remote/host
- # (notice doubling of slashes at the start of the path)
- p = '\\\\' + p
- components = p.split('\\')
- return urllib.parse.quote('/'.join(components))
+ # No DOS drive specified, just quote the pathname
+ return urllib.parse.quote(p)
comp = p.split(':', maxsplit=2)
if len(comp) != 2 or len(comp[0]) > 1:
error = 'Bad path: ' + p
raise OSError(error)
drive = urllib.parse.quote(comp[0].upper())
- components = comp[1].split('\\')
- path = '///' + drive + ':'
- for comp in components:
- if comp:
- path = path + '/' + urllib.parse.quote(comp)
- return path
+ tail = urllib.parse.quote(comp[1])
+ return '///' + drive + ':' + tail