Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: posixpath.py
"""Common operations on Posix pathnames.
[0] Fix | Delete
[1] Fix | Delete
Instead of importing this module directly, import os and refer to
[2] Fix | Delete
this module as os.path. The "os.path" name is an alias for this
[3] Fix | Delete
module on Posix systems; on other systems (e.g. Mac, Windows),
[4] Fix | Delete
os.path provides the same operations in a manner specific to that
[5] Fix | Delete
platform, and is an alias to another module (e.g. macpath, ntpath).
[6] Fix | Delete
[7] Fix | Delete
Some of this can actually be useful on non-Posix systems too, e.g.
[8] Fix | Delete
for manipulation of the pathname component of URLs.
[9] Fix | Delete
"""
[10] Fix | Delete
[11] Fix | Delete
# Strings representing various path-related bits and pieces.
[12] Fix | Delete
# These are primarily for export; internally, they are hardcoded.
[13] Fix | Delete
# Should be set before imports for resolving cyclic dependency.
[14] Fix | Delete
curdir = '.'
[15] Fix | Delete
pardir = '..'
[16] Fix | Delete
extsep = '.'
[17] Fix | Delete
sep = '/'
[18] Fix | Delete
pathsep = ':'
[19] Fix | Delete
defpath = ':/bin:/usr/bin'
[20] Fix | Delete
altsep = None
[21] Fix | Delete
devnull = '/dev/null'
[22] Fix | Delete
[23] Fix | Delete
import os
[24] Fix | Delete
import sys
[25] Fix | Delete
import stat
[26] Fix | Delete
import genericpath
[27] Fix | Delete
from genericpath import *
[28] Fix | Delete
[29] Fix | Delete
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
[30] Fix | Delete
"basename","dirname","commonprefix","getsize","getmtime",
[31] Fix | Delete
"getatime","getctime","islink","exists","lexists","isdir","isfile",
[32] Fix | Delete
"ismount", "expanduser","expandvars","normpath","abspath",
[33] Fix | Delete
"samefile","sameopenfile","samestat",
[34] Fix | Delete
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
[35] Fix | Delete
"devnull","realpath","supports_unicode_filenames","relpath",
[36] Fix | Delete
"commonpath"]
[37] Fix | Delete
[38] Fix | Delete
[39] Fix | Delete
def _get_sep(path):
[40] Fix | Delete
if isinstance(path, bytes):
[41] Fix | Delete
return b'/'
[42] Fix | Delete
else:
[43] Fix | Delete
return '/'
[44] Fix | Delete
[45] Fix | Delete
# Normalize the case of a pathname. Trivial in Posix, string.lower on Mac.
[46] Fix | Delete
# On MS-DOS this may also turn slashes into backslashes; however, other
[47] Fix | Delete
# normalizations (such as optimizing '../' away) are not allowed
[48] Fix | Delete
# (another function should be defined to do that).
[49] Fix | Delete
[50] Fix | Delete
def normcase(s):
[51] Fix | Delete
"""Normalize case of pathname. Has no effect under Posix"""
[52] Fix | Delete
s = os.fspath(s)
[53] Fix | Delete
if not isinstance(s, (bytes, str)):
[54] Fix | Delete
raise TypeError("normcase() argument must be str or bytes, "
[55] Fix | Delete
"not '{}'".format(s.__class__.__name__))
[56] Fix | Delete
return s
[57] Fix | Delete
[58] Fix | Delete
[59] Fix | Delete
# Return whether a path is absolute.
[60] Fix | Delete
# Trivial in Posix, harder on the Mac or MS-DOS.
[61] Fix | Delete
[62] Fix | Delete
def isabs(s):
[63] Fix | Delete
"""Test whether a path is absolute"""
[64] Fix | Delete
s = os.fspath(s)
[65] Fix | Delete
sep = _get_sep(s)
[66] Fix | Delete
return s.startswith(sep)
[67] Fix | Delete
[68] Fix | Delete
[69] Fix | Delete
# Join pathnames.
[70] Fix | Delete
# Ignore the previous parts if a part is absolute.
[71] Fix | Delete
# Insert a '/' unless the first part is empty or already ends in '/'.
[72] Fix | Delete
[73] Fix | Delete
def join(a, *p):
[74] Fix | Delete
"""Join two or more pathname components, inserting '/' as needed.
[75] Fix | Delete
If any component is an absolute path, all previous path components
[76] Fix | Delete
will be discarded. An empty last part will result in a path that
[77] Fix | Delete
ends with a separator."""
[78] Fix | Delete
a = os.fspath(a)
[79] Fix | Delete
sep = _get_sep(a)
[80] Fix | Delete
path = a
[81] Fix | Delete
try:
[82] Fix | Delete
if not p:
[83] Fix | Delete
path[:0] + sep #23780: Ensure compatible data type even if p is null.
[84] Fix | Delete
for b in map(os.fspath, p):
[85] Fix | Delete
if b.startswith(sep):
[86] Fix | Delete
path = b
[87] Fix | Delete
elif not path or path.endswith(sep):
[88] Fix | Delete
path += b
[89] Fix | Delete
else:
[90] Fix | Delete
path += sep + b
[91] Fix | Delete
except (TypeError, AttributeError, BytesWarning):
[92] Fix | Delete
genericpath._check_arg_types('join', a, *p)
[93] Fix | Delete
raise
[94] Fix | Delete
return path
[95] Fix | Delete
[96] Fix | Delete
[97] Fix | Delete
# Split a path in head (everything up to the last '/') and tail (the
[98] Fix | Delete
# rest). If the path ends in '/', tail will be empty. If there is no
[99] Fix | Delete
# '/' in the path, head will be empty.
[100] Fix | Delete
# Trailing '/'es are stripped from head unless it is the root.
[101] Fix | Delete
[102] Fix | Delete
def split(p):
[103] Fix | Delete
"""Split a pathname. Returns tuple "(head, tail)" where "tail" is
[104] Fix | Delete
everything after the final slash. Either part may be empty."""
[105] Fix | Delete
p = os.fspath(p)
[106] Fix | Delete
sep = _get_sep(p)
[107] Fix | Delete
i = p.rfind(sep) + 1
[108] Fix | Delete
head, tail = p[:i], p[i:]
[109] Fix | Delete
if head and head != sep*len(head):
[110] Fix | Delete
head = head.rstrip(sep)
[111] Fix | Delete
return head, tail
[112] Fix | Delete
[113] Fix | Delete
[114] Fix | Delete
# Split a path in root and extension.
[115] Fix | Delete
# The extension is everything starting at the last dot in the last
[116] Fix | Delete
# pathname component; the root is everything before that.
[117] Fix | Delete
# It is always true that root + ext == p.
[118] Fix | Delete
[119] Fix | Delete
def splitext(p):
[120] Fix | Delete
p = os.fspath(p)
[121] Fix | Delete
if isinstance(p, bytes):
[122] Fix | Delete
sep = b'/'
[123] Fix | Delete
extsep = b'.'
[124] Fix | Delete
else:
[125] Fix | Delete
sep = '/'
[126] Fix | Delete
extsep = '.'
[127] Fix | Delete
return genericpath._splitext(p, sep, None, extsep)
[128] Fix | Delete
splitext.__doc__ = genericpath._splitext.__doc__
[129] Fix | Delete
[130] Fix | Delete
# Split a pathname into a drive specification and the rest of the
[131] Fix | Delete
# path. Useful on DOS/Windows/NT; on Unix, the drive is always empty.
[132] Fix | Delete
[133] Fix | Delete
def splitdrive(p):
[134] Fix | Delete
"""Split a pathname into drive and path. On Posix, drive is always
[135] Fix | Delete
empty."""
[136] Fix | Delete
p = os.fspath(p)
[137] Fix | Delete
return p[:0], p
[138] Fix | Delete
[139] Fix | Delete
[140] Fix | Delete
# Return the tail (basename) part of a path, same as split(path)[1].
[141] Fix | Delete
[142] Fix | Delete
def basename(p):
[143] Fix | Delete
"""Returns the final component of a pathname"""
[144] Fix | Delete
p = os.fspath(p)
[145] Fix | Delete
sep = _get_sep(p)
[146] Fix | Delete
i = p.rfind(sep) + 1
[147] Fix | Delete
return p[i:]
[148] Fix | Delete
[149] Fix | Delete
[150] Fix | Delete
# Return the head (dirname) part of a path, same as split(path)[0].
[151] Fix | Delete
[152] Fix | Delete
def dirname(p):
[153] Fix | Delete
"""Returns the directory component of a pathname"""
[154] Fix | Delete
p = os.fspath(p)
[155] Fix | Delete
sep = _get_sep(p)
[156] Fix | Delete
i = p.rfind(sep) + 1
[157] Fix | Delete
head = p[:i]
[158] Fix | Delete
if head and head != sep*len(head):
[159] Fix | Delete
head = head.rstrip(sep)
[160] Fix | Delete
return head
[161] Fix | Delete
[162] Fix | Delete
[163] Fix | Delete
# Is a path a symbolic link?
[164] Fix | Delete
# This will always return false on systems where os.lstat doesn't exist.
[165] Fix | Delete
[166] Fix | Delete
def islink(path):
[167] Fix | Delete
"""Test whether a path is a symbolic link"""
[168] Fix | Delete
try:
[169] Fix | Delete
st = os.lstat(path)
[170] Fix | Delete
except (OSError, AttributeError):
[171] Fix | Delete
return False
[172] Fix | Delete
return stat.S_ISLNK(st.st_mode)
[173] Fix | Delete
[174] Fix | Delete
# Being true for dangling symbolic links is also useful.
[175] Fix | Delete
[176] Fix | Delete
def lexists(path):
[177] Fix | Delete
"""Test whether a path exists. Returns True for broken symbolic links"""
[178] Fix | Delete
try:
[179] Fix | Delete
os.lstat(path)
[180] Fix | Delete
except OSError:
[181] Fix | Delete
return False
[182] Fix | Delete
return True
[183] Fix | Delete
[184] Fix | Delete
[185] Fix | Delete
# Is a path a mount point?
[186] Fix | Delete
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)
[187] Fix | Delete
[188] Fix | Delete
def ismount(path):
[189] Fix | Delete
"""Test whether a path is a mount point"""
[190] Fix | Delete
try:
[191] Fix | Delete
s1 = os.lstat(path)
[192] Fix | Delete
except OSError:
[193] Fix | Delete
# It doesn't exist -- so not a mount point. :-)
[194] Fix | Delete
return False
[195] Fix | Delete
else:
[196] Fix | Delete
# A symlink can never be a mount point
[197] Fix | Delete
if stat.S_ISLNK(s1.st_mode):
[198] Fix | Delete
return False
[199] Fix | Delete
[200] Fix | Delete
if isinstance(path, bytes):
[201] Fix | Delete
parent = join(path, b'..')
[202] Fix | Delete
else:
[203] Fix | Delete
parent = join(path, '..')
[204] Fix | Delete
parent = realpath(parent)
[205] Fix | Delete
try:
[206] Fix | Delete
s2 = os.lstat(parent)
[207] Fix | Delete
except OSError:
[208] Fix | Delete
return False
[209] Fix | Delete
[210] Fix | Delete
dev1 = s1.st_dev
[211] Fix | Delete
dev2 = s2.st_dev
[212] Fix | Delete
if dev1 != dev2:
[213] Fix | Delete
return True # path/.. on a different device as path
[214] Fix | Delete
ino1 = s1.st_ino
[215] Fix | Delete
ino2 = s2.st_ino
[216] Fix | Delete
if ino1 == ino2:
[217] Fix | Delete
return True # path/.. is the same i-node as path
[218] Fix | Delete
return False
[219] Fix | Delete
[220] Fix | Delete
[221] Fix | Delete
# Expand paths beginning with '~' or '~user'.
[222] Fix | Delete
# '~' means $HOME; '~user' means that user's home directory.
[223] Fix | Delete
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
[224] Fix | Delete
# the path is returned unchanged (leaving error reporting to whatever
[225] Fix | Delete
# function is called with the expanded path as argument).
[226] Fix | Delete
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
[227] Fix | Delete
# (A function should also be defined to do full *sh-style environment
[228] Fix | Delete
# variable expansion.)
[229] Fix | Delete
[230] Fix | Delete
def expanduser(path):
[231] Fix | Delete
"""Expand ~ and ~user constructions. If user or $HOME is unknown,
[232] Fix | Delete
do nothing."""
[233] Fix | Delete
path = os.fspath(path)
[234] Fix | Delete
if isinstance(path, bytes):
[235] Fix | Delete
tilde = b'~'
[236] Fix | Delete
else:
[237] Fix | Delete
tilde = '~'
[238] Fix | Delete
if not path.startswith(tilde):
[239] Fix | Delete
return path
[240] Fix | Delete
sep = _get_sep(path)
[241] Fix | Delete
i = path.find(sep, 1)
[242] Fix | Delete
if i < 0:
[243] Fix | Delete
i = len(path)
[244] Fix | Delete
if i == 1:
[245] Fix | Delete
if 'HOME' not in os.environ:
[246] Fix | Delete
import pwd
[247] Fix | Delete
try:
[248] Fix | Delete
userhome = pwd.getpwuid(os.getuid()).pw_dir
[249] Fix | Delete
except KeyError:
[250] Fix | Delete
# bpo-10496: if the current user identifier doesn't exist in the
[251] Fix | Delete
# password database, return the path unchanged
[252] Fix | Delete
return path
[253] Fix | Delete
else:
[254] Fix | Delete
userhome = os.environ['HOME']
[255] Fix | Delete
else:
[256] Fix | Delete
import pwd
[257] Fix | Delete
name = path[1:i]
[258] Fix | Delete
if isinstance(name, bytes):
[259] Fix | Delete
name = str(name, 'ASCII')
[260] Fix | Delete
try:
[261] Fix | Delete
pwent = pwd.getpwnam(name)
[262] Fix | Delete
except KeyError:
[263] Fix | Delete
# bpo-10496: if the user name from the path doesn't exist in the
[264] Fix | Delete
# password database, return the path unchanged
[265] Fix | Delete
return path
[266] Fix | Delete
userhome = pwent.pw_dir
[267] Fix | Delete
if isinstance(path, bytes):
[268] Fix | Delete
userhome = os.fsencode(userhome)
[269] Fix | Delete
root = b'/'
[270] Fix | Delete
else:
[271] Fix | Delete
root = '/'
[272] Fix | Delete
userhome = userhome.rstrip(root)
[273] Fix | Delete
return (userhome + path[i:]) or root
[274] Fix | Delete
[275] Fix | Delete
[276] Fix | Delete
# Expand paths containing shell variable substitutions.
[277] Fix | Delete
# This expands the forms $variable and ${variable} only.
[278] Fix | Delete
# Non-existent variables are left unchanged.
[279] Fix | Delete
[280] Fix | Delete
_varprog = None
[281] Fix | Delete
_varprogb = None
[282] Fix | Delete
[283] Fix | Delete
def expandvars(path):
[284] Fix | Delete
"""Expand shell variables of form $var and ${var}. Unknown variables
[285] Fix | Delete
are left unchanged."""
[286] Fix | Delete
path = os.fspath(path)
[287] Fix | Delete
global _varprog, _varprogb
[288] Fix | Delete
if isinstance(path, bytes):
[289] Fix | Delete
if b'$' not in path:
[290] Fix | Delete
return path
[291] Fix | Delete
if not _varprogb:
[292] Fix | Delete
import re
[293] Fix | Delete
_varprogb = re.compile(br'\$(\w+|\{[^}]*\})', re.ASCII)
[294] Fix | Delete
search = _varprogb.search
[295] Fix | Delete
start = b'{'
[296] Fix | Delete
end = b'}'
[297] Fix | Delete
environ = getattr(os, 'environb', None)
[298] Fix | Delete
else:
[299] Fix | Delete
if '$' not in path:
[300] Fix | Delete
return path
[301] Fix | Delete
if not _varprog:
[302] Fix | Delete
import re
[303] Fix | Delete
_varprog = re.compile(r'\$(\w+|\{[^}]*\})', re.ASCII)
[304] Fix | Delete
search = _varprog.search
[305] Fix | Delete
start = '{'
[306] Fix | Delete
end = '}'
[307] Fix | Delete
environ = os.environ
[308] Fix | Delete
i = 0
[309] Fix | Delete
while True:
[310] Fix | Delete
m = search(path, i)
[311] Fix | Delete
if not m:
[312] Fix | Delete
break
[313] Fix | Delete
i, j = m.span(0)
[314] Fix | Delete
name = m.group(1)
[315] Fix | Delete
if name.startswith(start) and name.endswith(end):
[316] Fix | Delete
name = name[1:-1]
[317] Fix | Delete
try:
[318] Fix | Delete
if environ is None:
[319] Fix | Delete
value = os.fsencode(os.environ[os.fsdecode(name)])
[320] Fix | Delete
else:
[321] Fix | Delete
value = environ[name]
[322] Fix | Delete
except KeyError:
[323] Fix | Delete
i = j
[324] Fix | Delete
else:
[325] Fix | Delete
tail = path[j:]
[326] Fix | Delete
path = path[:i] + value
[327] Fix | Delete
i = len(path)
[328] Fix | Delete
path += tail
[329] Fix | Delete
return path
[330] Fix | Delete
[331] Fix | Delete
[332] Fix | Delete
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
[333] Fix | Delete
# It should be understood that this may change the meaning of the path
[334] Fix | Delete
# if it contains symbolic links!
[335] Fix | Delete
[336] Fix | Delete
def normpath(path):
[337] Fix | Delete
"""Normalize path, eliminating double slashes, etc."""
[338] Fix | Delete
path = os.fspath(path)
[339] Fix | Delete
if isinstance(path, bytes):
[340] Fix | Delete
sep = b'/'
[341] Fix | Delete
empty = b''
[342] Fix | Delete
dot = b'.'
[343] Fix | Delete
dotdot = b'..'
[344] Fix | Delete
else:
[345] Fix | Delete
sep = '/'
[346] Fix | Delete
empty = ''
[347] Fix | Delete
dot = '.'
[348] Fix | Delete
dotdot = '..'
[349] Fix | Delete
if path == empty:
[350] Fix | Delete
return dot
[351] Fix | Delete
initial_slashes = path.startswith(sep)
[352] Fix | Delete
# POSIX allows one or two initial slashes, but treats three or more
[353] Fix | Delete
# as single slash.
[354] Fix | Delete
if (initial_slashes and
[355] Fix | Delete
path.startswith(sep*2) and not path.startswith(sep*3)):
[356] Fix | Delete
initial_slashes = 2
[357] Fix | Delete
comps = path.split(sep)
[358] Fix | Delete
new_comps = []
[359] Fix | Delete
for comp in comps:
[360] Fix | Delete
if comp in (empty, dot):
[361] Fix | Delete
continue
[362] Fix | Delete
if (comp != dotdot or (not initial_slashes and not new_comps) or
[363] Fix | Delete
(new_comps and new_comps[-1] == dotdot)):
[364] Fix | Delete
new_comps.append(comp)
[365] Fix | Delete
elif new_comps:
[366] Fix | Delete
new_comps.pop()
[367] Fix | Delete
comps = new_comps
[368] Fix | Delete
path = sep.join(comps)
[369] Fix | Delete
if initial_slashes:
[370] Fix | Delete
path = sep*initial_slashes + path
[371] Fix | Delete
return path or dot
[372] Fix | Delete
[373] Fix | Delete
[374] Fix | Delete
def abspath(path):
[375] Fix | Delete
"""Return an absolute path."""
[376] Fix | Delete
path = os.fspath(path)
[377] Fix | Delete
if not isabs(path):
[378] Fix | Delete
if isinstance(path, bytes):
[379] Fix | Delete
cwd = os.getcwdb()
[380] Fix | Delete
else:
[381] Fix | Delete
cwd = os.getcwd()
[382] Fix | Delete
path = join(cwd, path)
[383] Fix | Delete
return normpath(path)
[384] Fix | Delete
[385] Fix | Delete
[386] Fix | Delete
# Return a canonical path (i.e. the absolute location of a file on the
[387] Fix | Delete
# filesystem).
[388] Fix | Delete
[389] Fix | Delete
def realpath(filename):
[390] Fix | Delete
"""Return the canonical path of the specified filename, eliminating any
[391] Fix | Delete
symbolic links encountered in the path."""
[392] Fix | Delete
filename = os.fspath(filename)
[393] Fix | Delete
path, ok = _joinrealpath(filename[:0], filename, {})
[394] Fix | Delete
return abspath(path)
[395] Fix | Delete
[396] Fix | Delete
# Join two paths, normalizing and eliminating any symbolic links
[397] Fix | Delete
# encountered in the second path.
[398] Fix | Delete
def _joinrealpath(path, rest, seen):
[399] Fix | Delete
if isinstance(path, bytes):
[400] Fix | Delete
sep = b'/'
[401] Fix | Delete
curdir = b'.'
[402] Fix | Delete
pardir = b'..'
[403] Fix | Delete
else:
[404] Fix | Delete
sep = '/'
[405] Fix | Delete
curdir = '.'
[406] Fix | Delete
pardir = '..'
[407] Fix | Delete
[408] Fix | Delete
if isabs(rest):
[409] Fix | Delete
rest = rest[1:]
[410] Fix | Delete
path = sep
[411] Fix | Delete
[412] Fix | Delete
while rest:
[413] Fix | Delete
name, _, rest = rest.partition(sep)
[414] Fix | Delete
if not name or name == curdir:
[415] Fix | Delete
# current dir
[416] Fix | Delete
continue
[417] Fix | Delete
if name == pardir:
[418] Fix | Delete
# parent dir
[419] Fix | Delete
if path:
[420] Fix | Delete
path, name = split(path)
[421] Fix | Delete
if name == pardir:
[422] Fix | Delete
path = join(path, pardir, pardir)
[423] Fix | Delete
else:
[424] Fix | Delete
path = pardir
[425] Fix | Delete
continue
[426] Fix | Delete
newpath = join(path, name)
[427] Fix | Delete
if not islink(newpath):
[428] Fix | Delete
path = newpath
[429] Fix | Delete
continue
[430] Fix | Delete
# Resolve the symbolic link
[431] Fix | Delete
if newpath in seen:
[432] Fix | Delete
# Already seen this path
[433] Fix | Delete
path = seen[newpath]
[434] Fix | Delete
if path is not None:
[435] Fix | Delete
# use cached value
[436] Fix | Delete
continue
[437] Fix | Delete
# The symlink is not resolved, so we must have a symlink loop.
[438] Fix | Delete
# Return already resolved part + rest of the path unchanged.
[439] Fix | Delete
return join(newpath, rest), False
[440] Fix | Delete
seen[newpath] = None # not resolved symlink
[441] Fix | Delete
path, ok = _joinrealpath(path, os.readlink(newpath), seen)
[442] Fix | Delete
if not ok:
[443] Fix | Delete
return join(path, rest), False
[444] Fix | Delete
seen[newpath] = path # resolved symlink
[445] Fix | Delete
[446] Fix | Delete
return path, True
[447] Fix | Delete
[448] Fix | Delete
[449] Fix | Delete
supports_unicode_filenames = (sys.platform == 'darwin')
[450] Fix | Delete
[451] Fix | Delete
def relpath(path, start=None):
[452] Fix | Delete
"""Return a relative version of a path"""
[453] Fix | Delete
[454] Fix | Delete
if not path:
[455] Fix | Delete
raise ValueError("no path specified")
[456] Fix | Delete
[457] Fix | Delete
path = os.fspath(path)
[458] Fix | Delete
if isinstance(path, bytes):
[459] Fix | Delete
curdir = b'.'
[460] Fix | Delete
sep = b'/'
[461] Fix | Delete
pardir = b'..'
[462] Fix | Delete
else:
[463] Fix | Delete
curdir = '.'
[464] Fix | Delete
sep = '/'
[465] Fix | Delete
pardir = '..'
[466] Fix | Delete
[467] Fix | Delete
if start is None:
[468] Fix | Delete
start = curdir
[469] Fix | Delete
else:
[470] Fix | Delete
start = os.fspath(start)
[471] Fix | Delete
[472] Fix | Delete
try:
[473] Fix | Delete
start_list = [x for x in abspath(start).split(sep) if x]
[474] Fix | Delete
path_list = [x for x in abspath(path).split(sep) if x]
[475] Fix | Delete
# Work out how much of the filepath is shared by start and path.
[476] Fix | Delete
i = len(commonprefix([start_list, path_list]))
[477] Fix | Delete
[478] Fix | Delete
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
[479] Fix | Delete
if not rel_list:
[480] Fix | Delete
return curdir
[481] Fix | Delete
return join(*rel_list)
[482] Fix | Delete
except (TypeError, AttributeError, BytesWarning, DeprecationWarning):
[483] Fix | Delete
genericpath._check_arg_types('relpath', path, start)
[484] Fix | Delete
raise
[485] Fix | Delete
[486] Fix | Delete
[487] Fix | Delete
# Return the longest common sub-path of the sequence of paths given as input.
[488] Fix | Delete
# The paths are not normalized before comparing them (this is the
[489] Fix | Delete
# responsibility of the caller). Any trailing separator is stripped from the
[490] Fix | Delete
# returned path.
[491] Fix | Delete
[492] Fix | Delete
def commonpath(paths):
[493] Fix | Delete
"""Given a sequence of path names, returns the longest common sub-path."""
[494] Fix | Delete
[495] Fix | Delete
if not paths:
[496] Fix | Delete
raise ValueError('commonpath() arg is an empty sequence')
[497] Fix | Delete
[498] Fix | Delete
paths = tuple(map(os.fspath, paths))
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function