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