Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-117201: Handle leading// forposixpath.commonpath#117202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
nineteendo wants to merge14 commits intopython:mainfromnineteendo:fix-commonpath
Closed
Changes from1 commit
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
247c9af
Handle leading `//` for `posixpath.commonpath`
nineteendoMar 24, 2024
0c38276
raise TypeError for non-sequences
nineteendoMar 24, 2024
a9b0832
📜🤖 Added by blurb_it.
blurb-it[bot]Mar 26, 2024
a521282
Remove `break` & `else`
nineteendoMar 26, 2024
b467e7e
Merge branch 'fix-commonpath' of https://github.com/nineteendo/cpytho…
nineteendoMar 26, 2024
26eac21
Handle errors for iterable
nineteendoMar 26, 2024
d83743d
Remove redundant check
nineteendoMar 27, 2024
1ae0c43
raise TypeError for non-sequences
nineteendoMar 28, 2024
e6de234
Update NEWS.d
nineteendoMar 28, 2024
012c12e
Add newline
nineteendoMar 28, 2024
fb1c91a
Speed up `posixpath.ismount`
nineteendoMar 28, 2024
ca90fde
unnest `posixpath.expanduser`
nineteendoMar 28, 2024
758e0d6
Speed up `posixpath.expanduser` & `posixpath.normpath`
nineteendoMar 28, 2024
218e43e
Move refactoring to new branch
nineteendoMar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
Move refactoring to new branch
  • Loading branch information
@nineteendo
nineteendo committedMar 28, 2024
commit218e43e75130eb0f15446374765cd307c58ab198
123 changes: 73 additions & 50 deletionsLib/posixpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -217,19 +217,31 @@ def ismount(path):
except (OSError, ValueError):
# It doesn't exist -- so not a mount point. :-)
return False
else:
# A symlink can never be a mount point
if stat.S_ISLNK(s1.st_mode):
return False

# A symlink can never be a mount point
if stat.S_ISLNK(s1.st_mode):
return False

parent = realpath(dirname(path))
path = os.fspath(path)
if isinstance(path, bytes):
parent = join(path, b'..')
else:
parent = join(path, '..')
parent = realpath(parent)
try:
s2 = os.lstat(parent)
except (OSError, ValueError):
return False

# path/.. on a different device as path or the same i-node as path
return s1.st_dev != s2.st_dev or s1.st_ino == s2.st_ino
dev1 = s1.st_dev
dev2 = s2.st_dev
if dev1 != dev2:
return True # path/.. on a different device as path
ino1 = s1.st_ino
ino2 = s2.st_ino
if ino1 == ino2:
return True # path/.. is the same i-node as path
return False


# Expand paths beginning with '~' or '~user'.
Expand All@@ -255,31 +267,37 @@ def expanduser(path):
i = path.find(sep, 1)
if i < 0:
i = len(path)
if i != 1:
if i == 1:
if 'HOME' not in os.environ:
try:
import pwd
except ImportError:
# pwd module unavailable, return path unchanged
return path
try:
userhome = pwd.getpwuid(os.getuid()).pw_dir
except KeyError:
# bpo-10496: if the current user identifier doesn't exist in the
# password database, return the path unchanged
return path
else:
userhome = os.environ['HOME']
else:
try:
import pwd
name = path[1:i]
if isinstance(name, bytes):
name = name.decode('ascii')

userhome = pwd.getpwnam(name).pw_dir
except (ImportError, KeyError):
except ImportError:
# pwd module unavailable, return path unchanged
# bpo-10496: if the user name from the path doesn't exist in the
# password database, return the path unchanged
return path
elif 'HOME' in os.environ:
userhome = os.environ['HOME']
else:
name = path[1:i]
if isinstance(name, bytes):
name = str(name, 'ASCII')
try:
import pwd
userhome = pwd.getpwuid(os.getuid()).pw_dir
except (ImportError, KeyError):
# pwd module unavailable, return path unchanged
# bpo-10496: if the current user identifier doesn't exist in the
pwent = pwd.getpwnam(name)
except KeyError:
# bpo-10496: if the user name from the path doesn't exist in the
# password database, return the path unchanged
return path

userhome = pwent.pw_dir
# if no user home, return the path unchanged on VxWorks
if userhome is None and sys.platform == "vxworks":
return path
Expand DownExpand Up@@ -354,40 +372,45 @@ def expandvars(path):

try:
from posix import _path_normpath
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
return _path_normpath(path) or "."

except ImportError:
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
sep = b'/'
curdir = b'.'
pardir = b'..'
empty = b''
dot = b'.'
dotdot = b'..'
else:
sep = '/'
curdir = '.'
pardir = '..'
if not path:
return curdir
_, root, tail = splitroot(path)
comps = []
for comp in tail.split(sep):
if not comp or comp == curdir:
empty = ''
dot = '.'
dotdot = '..'
if path == empty:
return dot
_, initial_slashes, path = splitroot(path)
comps = path.split(sep)
new_comps = []
for comp in comps:
if comp in (empty, dot):
continue
if (
comp != pardir
or (not root and not comps)
or (comps and comps[-1] == pardir)
):
comps.append(comp)
elif comps:
comps.pop()
return (root + sep.join(comps)) or curdir
if (comp != dotdot or (not initial_slashes and not new_comps) or
(new_comps and new_comps[-1] == dotdot)):
new_comps.append(comp)
elif new_comps:
new_comps.pop()
comps = new_comps
path = initial_slashes + sep.join(comps)
return path or dot

else:
def normpath(path):
"""Normalize path, eliminating double slashes, etc."""
path = os.fspath(path)
if isinstance(path, bytes):
return os.fsencode(_path_normpath(os.fsdecode(path))) or b"."
return _path_normpath(path) or "."


def abspath(path):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp