8000 Add `make_wide` · python/cpython@0625bf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0625bf1

Browse files
committed
Add make_wide
1 parent ae2e171 commit 0625bf1

File tree

4 files changed

+286
-290
lines changed

4 files changed

+286
-290
lines changed

Lib/ntpath.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def splitdrive(p):
168168

169169

170170
try:
171-
from nt import _path_splitroot_ex
171+
from nt import _path_splitroot_ex as splitroot
172172
except ImportError:
173173
def splitroot(p):
174174
"""Split a pathname into drive, root and tail. The drive is defined
@@ -220,23 +220,7 @@ def splitroot(p):
220220
else:
221221
# Relative path, e.g. Windows
222222
return empty, empty, p
223-
else:
224-
def splitroot(p):
225-
"""Split a pathname into drive, root and tail. The drive is defined
226-
exactly as in splitdrive(). On Windows, the root may be a single path
227-
separator or an empty string. The tail contains anything after the root.
228-
For example:
229223

230-
splitroot('//server/share/') == ('//server/share', '/', '')
231-
splitroot('C:/Users/Barney') == ('C:', '/', 'Users/Barney')
232-
splitroot('C:///spam///ham') == ('C:', '/', '//spam///ham')
233-
splitroot('Windows/notepad') == ('', '', 'Windows/notepad')
234-
"""
235-
p = os.fspath(p)
236-
if isinstance(p, bytes):
237-
drive, root, tail = _path_splitroot_ex(os.fsdecode(p))
238-
return os.fsencode(drive), os.fsencode(root), os.fsencode(tail)
239-
return _path_splitroot_ex(p)
240224

241225

242226
# Split a path in head (everything up to the last '/') and tail (the
@@ -553,7 +537,7 @@ def expandvars(path):
553537
# Previously, this function also truncated pathnames to 8+3 format,
554538
# but as this module is called "ntpath", that's obviously wrong!
555539
try:
556-
from nt import _path_normpath
540+
from nt import _path_normpath as normpath
557541

558542
except ImportError:
559543
def normpath(path):
@@ -592,14 +576,6 @@ def normpath(path):
592576
comps.append(curdir)
593577
return prefix + sep.join(comps)
594578

595-
else:
596-
def normpath(path):
597-
"""Normalize path, eliminating double slashes, etc."""
598-
path = os.fspath(path)
599-
if isinstance(path, bytes):
600-
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
601-
return _path_normpath(path) or "."
602-
603579

604580
def _abspath_fallback(path):
605581
"""Return the absolute version of a path as a fallback function in case

Lib/posixpath.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def splitdrive(p):
135135

136136

137137
try:
138-
from posix import _path_splitroot_ex
138+
from posix import _path_splitroot_ex as splitroot
139139
except ImportError:
140140
def splitroot(p):
141141
"""Split a pathname into drive, root and tail. On Posix, drive is always
@@ -164,23 +164,7 @@ def splitroot(p):
164164
# Precisely two leading slashes, e.g.: '//foo'. Implementation defined per POSIX, see
165165
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13
166166
return empty, p[:2], p[2:]
167-
else:
168-
def splitroot(p):
169-
"""Split a pathname into drive, root and tail. On Posix, drive is always
170-
empty; the root may be empty, a single slash, or two slashes. The tail
171-
contains anything after the root. For example:
172167

173-
splitroot('foo/bar') == ('', '', 'foo/bar')
174-
splitroot('/foo/bar') == ('', '/', 'foo/bar')
175-
splitroot('//foo/bar') == ('', '//', 'foo/bar')
176-
splitroot('///foo/bar') == ('', '/', '//foo/bar')
177-
"""
178-
p = os.fspath(p)
179-
if isinstance(p, bytes):
180-
# Optimisation: the drive is always empty
181-
_, root, tail = _path_splitroot_ex(os.fsdecode(p))
182-
return b'', os.fsencode(root), os.fsencode(tail)
183-
return _path_splitroot_ex(p)
184168

185169

186170
# Return the tail (basename) part of a path, same as split(path)[1].
@@ -366,7 +350,7 @@ def expandvars(path):
366350
# if it contains symbolic links!
367351

368352
try:
369-
from posix import _path_normpath
353+
from posix import _path_normpath as normpath
370354

371355
except ImportError:
372356
def normpath(path):
@@ -397,14 +381,6 @@ def normpath(path):
397381
path = initial_slashes + sep.join(comps)
398382
return path or dot
399383

400-
else:
401-
def normpath(path):
402-
"""Normalize path, eliminating double slashes, etc."""
403-
path = os.fspath(path)
404-
if isinstance(path, bytes):
405-
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
406-
return _path_normpath(path) or "."
407-
408384

409385
def abspath(path):
410386
"""Return an absolute path."""

0 commit comments

Comments
 (0)
0