Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/python3....
File: ntpath.py
# Module 'ntpath' -- common operations on WinNT/Win95 pathnames
[0] Fix | Delete
"""Common pathname manipulations, WindowsNT/95 version.
[1] Fix | Delete
[2] Fix | Delete
Instead of importing this module directly, import os and refer to this
[3] Fix | Delete
module as os.path.
[4] Fix | Delete
"""
[5] Fix | Delete
[6] Fix | Delete
# strings representing various path-related bits and pieces
[7] Fix | Delete
# These are primarily for export; internally, they are hardcoded.
[8] Fix | Delete
# Should be set before imports for resolving cyclic dependency.
[9] Fix | Delete
curdir = '.'
[10] Fix | Delete
pardir = '..'
[11] Fix | Delete
extsep = '.'
[12] Fix | Delete
sep = '\\'
[13] Fix | Delete
pathsep = ';'
[14] Fix | Delete
altsep = '/'
[15] Fix | Delete
defpath = '.;C:\\bin'
[16] Fix | Delete
devnull = 'nul'
[17] Fix | Delete
[18] Fix | Delete
import os
[19] Fix | Delete
import sys
[20] Fix | Delete
import stat
[21] Fix | Delete
import genericpath
[22] Fix | Delete
from genericpath import *
[23] Fix | Delete
[24] Fix | Delete
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
[25] Fix | Delete
"basename","dirname","commonprefix","getsize","getmtime",
[26] Fix | Delete
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
[27] Fix | Delete
"ismount", "expanduser","expandvars","normpath","abspath",
[28] Fix | Delete
"curdir","pardir","sep","pathsep","defpath","altsep",
[29] Fix | Delete
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
[30] Fix | Delete
"samefile", "sameopenfile", "samestat", "commonpath"]
[31] Fix | Delete
[32] Fix | Delete
def _get_bothseps(path):
[33] Fix | Delete
if isinstance(path, bytes):
[34] Fix | Delete
return b'\\/'
[35] Fix | Delete
else:
[36] Fix | Delete
return '\\/'
[37] Fix | Delete
[38] Fix | Delete
# Normalize the case of a pathname and map slashes to backslashes.
[39] Fix | Delete
# Other normalizations (such as optimizing '../' away) are not done
[40] Fix | Delete
# (this is done by normpath).
[41] Fix | Delete
[42] Fix | Delete
def normcase(s):
[43] Fix | Delete
"""Normalize case of pathname.
[44] Fix | Delete
[45] Fix | Delete
Makes all characters lowercase and all slashes into backslashes."""
[46] Fix | Delete
s = os.fspath(s)
[47] Fix | Delete
if isinstance(s, bytes):
[48] Fix | Delete
return s.replace(b'/', b'\\').lower()
[49] Fix | Delete
else:
[50] Fix | Delete
return s.replace('/', '\\').lower()
[51] Fix | Delete
[52] Fix | Delete
[53] Fix | Delete
# Return whether a path is absolute.
[54] Fix | Delete
# Trivial in Posix, harder on Windows.
[55] Fix | Delete
# For Windows it is absolute if it starts with a slash or backslash (current
[56] Fix | Delete
# volume), or if a pathname after the volume-letter-and-colon or UNC-resource
[57] Fix | Delete
# starts with a slash or backslash.
[58] Fix | Delete
[59] Fix | Delete
def isabs(s):
[60] Fix | Delete
"""Test whether a path is absolute"""
[61] Fix | Delete
s = os.fspath(s)
[62] Fix | Delete
# Paths beginning with \\?\ are always absolute, but do not
[63] Fix | Delete
# necessarily contain a drive.
[64] Fix | Delete
if isinstance(s, bytes):
[65] Fix | Delete
if s.replace(b'/', b'\\').startswith(b'\\\\?\\'):
[66] Fix | Delete
return True
[67] Fix | Delete
else:
[68] Fix | Delete
if s.replace('/', '\\').startswith('\\\\?\\'):
[69] Fix | Delete
return True
[70] Fix | Delete
s = splitdrive(s)[1]
[71] Fix | Delete
return len(s) > 0 and s[0] in _get_bothseps(s)
[72] Fix | Delete
[73] Fix | Delete
[74] Fix | Delete
# Join two (or more) paths.
[75] Fix | Delete
def join(path, *paths):
[76] Fix | Delete
path = os.fspath(path)
[77] Fix | Delete
if isinstance(path, bytes):
[78] Fix | Delete
sep = b'\\'
[79] Fix | Delete
seps = b'\\/'
[80] Fix | Delete
colon = b':'
[81] Fix | Delete
else:
[82] Fix | Delete
sep = '\\'
[83] Fix | Delete
seps = '\\/'
[84] Fix | Delete
colon = ':'
[85] Fix | Delete
try:
[86] Fix | Delete
if not paths:
[87] Fix | Delete
path[:0] + sep #23780: Ensure compatible data type even if p is null.
[88] Fix | Delete
result_drive, result_path = splitdrive(path)
[89] Fix | Delete
for p in map(os.fspath, paths):
[90] Fix | Delete
p_drive, p_path = splitdrive(p)
[91] Fix | Delete
if p_path and p_path[0] in seps:
[92] Fix | Delete
# Second path is absolute
[93] Fix | Delete
if p_drive or not result_drive:
[94] Fix | Delete
result_drive = p_drive
[95] Fix | Delete
result_path = p_path
[96] Fix | Delete
continue
[97] Fix | Delete
elif p_drive and p_drive != result_drive:
[98] Fix | Delete
if p_drive.lower() != result_drive.lower():
[99] Fix | Delete
# Different drives => ignore the first path entirely
[100] Fix | Delete
result_drive = p_drive
[101] Fix | Delete
result_path = p_path
[102] Fix | Delete
continue
[103] Fix | Delete
# Same drive in different case
[104] Fix | Delete
result_drive = p_drive
[105] Fix | Delete
# Second path is relative to the first
[106] Fix | Delete
if result_path and result_path[-1] not in seps:
[107] Fix | Delete
result_path = result_path + sep
[108] Fix | Delete
result_path = result_path + p_path
[109] Fix | Delete
## add separator between UNC and non-absolute path
[110] Fix | Delete
if (result_path and result_path[0] not in seps and
[111] Fix | Delete
result_drive and result_drive[-1:] != colon):
[112] Fix | Delete
return result_drive + sep + result_path
[113] Fix | Delete
return result_drive + result_path
[114] Fix | Delete
except (TypeError, AttributeError, BytesWarning):
[115] Fix | Delete
genericpath._check_arg_types('join', path, *paths)
[116] Fix | Delete
raise
[117] Fix | Delete
[118] Fix | Delete
[119] Fix | Delete
# Split a path in a drive specification (a drive letter followed by a
[120] Fix | Delete
# colon) and the path specification.
[121] Fix | Delete
# It is always true that drivespec + pathspec == p
[122] Fix | Delete
def splitdrive(p):
[123] Fix | Delete
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
[124] Fix | Delete
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
[125] Fix | Delete
[126] Fix | Delete
If you assign
[127] Fix | Delete
result = splitdrive(p)
[128] Fix | Delete
It is always true that:
[129] Fix | Delete
result[0] + result[1] == p
[130] Fix | Delete
[131] Fix | Delete
If the path contained a drive letter, drive_or_unc will contain everything
[132] Fix | Delete
up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
[133] Fix | Delete
[134] Fix | Delete
If the path contained a UNC path, the drive_or_unc will contain the host name
[135] Fix | Delete
and share up to but not including the fourth directory separator character.
[136] Fix | Delete
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
[137] Fix | Delete
[138] Fix | Delete
Paths cannot contain both a drive letter and a UNC path.
[139] Fix | Delete
[140] Fix | Delete
"""
[141] Fix | Delete
p = os.fspath(p)
[142] Fix | Delete
if len(p) >= 2:
[143] Fix | Delete
if isinstance(p, bytes):
[144] Fix | Delete
sep = b'\\'
[145] Fix | Delete
altsep = b'/'
[146] Fix | Delete
colon = b':'
[147] Fix | Delete
else:
[148] Fix | Delete
sep = '\\'
[149] Fix | Delete
altsep = '/'
[150] Fix | Delete
colon = ':'
[151] Fix | Delete
normp = p.replace(altsep, sep)
[152] Fix | Delete
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
[153] Fix | Delete
# is a UNC path:
[154] Fix | Delete
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
[155] Fix | Delete
# \\machine\mountpoint\directory\etc\...
[156] Fix | Delete
# directory ^^^^^^^^^^^^^^^
[157] Fix | Delete
index = normp.find(sep, 2)
[158] Fix | Delete
if index == -1:
[159] Fix | Delete
return p[:0], p
[160] Fix | Delete
index2 = normp.find(sep, index + 1)
[161] Fix | Delete
# a UNC path can't have two slashes in a row
[162] Fix | Delete
# (after the initial two)
[163] Fix | Delete
if index2 == index + 1:
[164] Fix | Delete
return p[:0], p
[165] Fix | Delete
if index2 == -1:
[166] Fix | Delete
index2 = len(p)
[167] Fix | Delete
return p[:index2], p[index2:]
[168] Fix | Delete
if normp[1:2] == colon:
[169] Fix | Delete
return p[:2], p[2:]
[170] Fix | Delete
return p[:0], p
[171] Fix | Delete
[172] Fix | Delete
[173] Fix | Delete
# Split a path in head (everything up to the last '/') and tail (the
[174] Fix | Delete
# rest). After the trailing '/' is stripped, the invariant
[175] Fix | Delete
# join(head, tail) == p holds.
[176] Fix | Delete
# The resulting head won't end in '/' unless it is the root.
[177] Fix | Delete
[178] Fix | Delete
def split(p):
[179] Fix | Delete
"""Split a pathname.
[180] Fix | Delete
[181] Fix | Delete
Return tuple (head, tail) where tail is everything after the final slash.
[182] Fix | Delete
Either part may be empty."""
[183] Fix | Delete
p = os.fspath(p)
[184] Fix | Delete
seps = _get_bothseps(p)
[185] Fix | Delete
d, p = splitdrive(p)
[186] Fix | Delete
# set i to index beyond p's last slash
[187] Fix | Delete
i = len(p)
[188] Fix | Delete
while i and p[i-1] not in seps:
[189] Fix | Delete
i -= 1
[190] Fix | Delete
head, tail = p[:i], p[i:] # now tail has no slashes
[191] Fix | Delete
# remove trailing slashes from head, unless it's all slashes
[192] Fix | Delete
head = head.rstrip(seps) or head
[193] Fix | Delete
return d + head, tail
[194] Fix | Delete
[195] Fix | Delete
[196] Fix | Delete
# Split a path in root and extension.
[197] Fix | Delete
# The extension is everything starting at the last dot in the last
[198] Fix | Delete
# pathname component; the root is everything before that.
[199] Fix | Delete
# It is always true that root + ext == p.
[200] Fix | Delete
[201] Fix | Delete
def splitext(p):
[202] Fix | Delete
p = os.fspath(p)
[203] Fix | Delete
if isinstance(p, bytes):
[204] Fix | Delete
return genericpath._splitext(p, b'\\', b'/', b'.')
[205] Fix | Delete
else:
[206] Fix | Delete
return genericpath._splitext(p, '\\', '/', '.')
[207] Fix | Delete
splitext.__doc__ = genericpath._splitext.__doc__
[208] Fix | Delete
[209] Fix | Delete
[210] Fix | Delete
# Return the tail (basename) part of a path.
[211] Fix | Delete
[212] Fix | Delete
def basename(p):
[213] Fix | Delete
"""Returns the final component of a pathname"""
[214] Fix | Delete
return split(p)[1]
[215] Fix | Delete
[216] Fix | Delete
[217] Fix | Delete
# Return the head (dirname) part of a path.
[218] Fix | Delete
[219] Fix | Delete
def dirname(p):
[220] Fix | Delete
"""Returns the directory component of a pathname"""
[221] Fix | Delete
return split(p)[0]
[222] Fix | Delete
[223] Fix | Delete
# Is a path a symbolic link?
[224] Fix | Delete
# This will always return false on systems where os.lstat doesn't exist.
[225] Fix | Delete
[226] Fix | Delete
def islink(path):
[227] Fix | Delete
"""Test whether a path is a symbolic link.
[228] Fix | Delete
This will always return false for Windows prior to 6.0.
[229] Fix | Delete
"""
[230] Fix | Delete
try:
[231] Fix | Delete
st = os.lstat(path)
[232] Fix | Delete
except (OSError, ValueError, AttributeError):
[233] Fix | Delete
return False
[234] Fix | Delete
return stat.S_ISLNK(st.st_mode)
[235] Fix | Delete
[236] Fix | Delete
# Being true for dangling symbolic links is also useful.
[237] Fix | Delete
[238] Fix | Delete
def lexists(path):
[239] Fix | Delete
"""Test whether a path exists. Returns True for broken symbolic links"""
[240] Fix | Delete
try:
[241] Fix | Delete
st = os.lstat(path)
[242] Fix | Delete
except (OSError, ValueError):
[243] Fix | Delete
return False
[244] Fix | Delete
return True
[245] Fix | Delete
[246] Fix | Delete
# Is a path a mount point?
[247] Fix | Delete
# Any drive letter root (eg c:\)
[248] Fix | Delete
# Any share UNC (eg \\server\share)
[249] Fix | Delete
# Any volume mounted on a filesystem folder
[250] Fix | Delete
#
[251] Fix | Delete
# No one method detects all three situations. Historically we've lexically
[252] Fix | Delete
# detected drive letter roots and share UNCs. The canonical approach to
[253] Fix | Delete
# detecting mounted volumes (querying the reparse tag) fails for the most
[254] Fix | Delete
# common case: drive letter roots. The alternative which uses GetVolumePathName
[255] Fix | Delete
# fails if the drive letter is the result of a SUBST.
[256] Fix | Delete
try:
[257] Fix | Delete
from nt import _getvolumepathname
[258] Fix | Delete
except ImportError:
[259] Fix | Delete
_getvolumepathname = None
[260] Fix | Delete
def ismount(path):
[261] Fix | Delete
"""Test whether a path is a mount point (a drive root, the root of a
[262] Fix | Delete
share, or a mounted volume)"""
[263] Fix | Delete
path = os.fspath(path)
[264] Fix | Delete
seps = _get_bothseps(path)
[265] Fix | Delete
path = abspath(path)
[266] Fix | Delete
root, rest = splitdrive(path)
[267] Fix | Delete
if root and root[0] in seps:
[268] Fix | Delete
return (not rest) or (rest in seps)
[269] Fix | Delete
if rest in seps:
[270] Fix | Delete
return True
[271] Fix | Delete
[272] Fix | Delete
if _getvolumepathname:
[273] Fix | Delete
return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
[274] Fix | Delete
else:
[275] Fix | Delete
return False
[276] Fix | Delete
[277] Fix | Delete
[278] Fix | Delete
# Expand paths beginning with '~' or '~user'.
[279] Fix | Delete
# '~' means $HOME; '~user' means that user's home directory.
[280] Fix | Delete
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
[281] Fix | Delete
# the path is returned unchanged (leaving error reporting to whatever
[282] Fix | Delete
# function is called with the expanded path as argument).
[283] Fix | Delete
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
[284] Fix | Delete
# (A function should also be defined to do full *sh-style environment
[285] Fix | Delete
# variable expansion.)
[286] Fix | Delete
[287] Fix | Delete
def expanduser(path):
[288] Fix | Delete
"""Expand ~ and ~user constructs.
[289] Fix | Delete
[290] Fix | Delete
If user or $HOME is unknown, do nothing."""
[291] Fix | Delete
path = os.fspath(path)
[292] Fix | Delete
if isinstance(path, bytes):
[293] Fix | Delete
tilde = b'~'
[294] Fix | Delete
else:
[295] Fix | Delete
tilde = '~'
[296] Fix | Delete
if not path.startswith(tilde):
[297] Fix | Delete
return path
[298] Fix | Delete
i, n = 1, len(path)
[299] Fix | Delete
while i < n and path[i] not in _get_bothseps(path):
[300] Fix | Delete
i += 1
[301] Fix | Delete
[302] Fix | Delete
if 'USERPROFILE' in os.environ:
[303] Fix | Delete
userhome = os.environ['USERPROFILE']
[304] Fix | Delete
elif not 'HOMEPATH' in os.environ:
[305] Fix | Delete
return path
[306] Fix | Delete
else:
[307] Fix | Delete
try:
[308] Fix | Delete
drive = os.environ['HOMEDRIVE']
[309] Fix | Delete
except KeyError:
[310] Fix | Delete
drive = ''
[311] Fix | Delete
userhome = join(drive, os.environ['HOMEPATH'])
[312] Fix | Delete
[313] Fix | Delete
if isinstance(path, bytes):
[314] Fix | Delete
userhome = os.fsencode(userhome)
[315] Fix | Delete
[316] Fix | Delete
if i != 1: #~user
[317] Fix | Delete
userhome = join(dirname(userhome), path[1:i])
[318] Fix | Delete
[319] Fix | Delete
return userhome + path[i:]
[320] Fix | Delete
[321] Fix | Delete
[322] Fix | Delete
# Expand paths containing shell variable substitutions.
[323] Fix | Delete
# The following rules apply:
[324] Fix | Delete
# - no expansion within single quotes
[325] Fix | Delete
# - '$$' is translated into '$'
[326] Fix | Delete
# - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
[327] Fix | Delete
# - ${varname} is accepted.
[328] Fix | Delete
# - $varname is accepted.
[329] Fix | Delete
# - %varname% is accepted.
[330] Fix | Delete
# - varnames can be made out of letters, digits and the characters '_-'
[331] Fix | Delete
# (though is not verified in the ${varname} and %varname% cases)
[332] Fix | Delete
# XXX With COMMAND.COM you can use any characters in a variable name,
[333] Fix | Delete
# XXX except '^|<>='.
[334] Fix | Delete
[335] Fix | Delete
def expandvars(path):
[336] Fix | Delete
"""Expand shell variables of the forms $var, ${var} and %var%.
[337] Fix | Delete
[338] Fix | Delete
Unknown variables are left unchanged."""
[339] Fix | Delete
path = os.fspath(path)
[340] Fix | Delete
if isinstance(path, bytes):
[341] Fix | Delete
if b'$' not in path and b'%' not in path:
[342] Fix | Delete
return path
[343] Fix | Delete
import string
[344] Fix | Delete
varchars = bytes(string.ascii_letters + string.digits + '_-', 'ascii')
[345] Fix | Delete
quote = b'\''
[346] Fix | Delete
percent = b'%'
[347] Fix | Delete
brace = b'{'
[348] Fix | Delete
rbrace = b'}'
[349] Fix | Delete
dollar = b'$'
[350] Fix | Delete
environ = getattr(os, 'environb', None)
[351] Fix | Delete
else:
[352] Fix | Delete
if '$' not in path and '%' not in path:
[353] Fix | Delete
return path
[354] Fix | Delete
import string
[355] Fix | Delete
varchars = string.ascii_letters + string.digits + '_-'
[356] Fix | Delete
quote = '\''
[357] Fix | Delete
percent = '%'
[358] Fix | Delete
brace = '{'
[359] Fix | Delete
rbrace = '}'
[360] Fix | Delete
dollar = '$'
[361] Fix | Delete
environ = os.environ
[362] Fix | Delete
res = path[:0]
[363] Fix | Delete
index = 0
[364] Fix | Delete
pathlen = len(path)
[365] Fix | Delete
while index < pathlen:
[366] Fix | Delete
c = path[index:index+1]
[367] Fix | Delete
if c == quote: # no expansion within single quotes
[368] Fix | Delete
path = path[index + 1:]
[369] Fix | Delete
pathlen = len(path)
[370] Fix | Delete
try:
[371] Fix | Delete
index = path.index(c)
[372] Fix | Delete
res += c + path[:index + 1]
[373] Fix | Delete
except ValueError:
[374] Fix | Delete
res += c + path
[375] Fix | Delete
index = pathlen - 1
[376] Fix | Delete
elif c == percent: # variable or '%'
[377] Fix | Delete
if path[index + 1:index + 2] == percent:
[378] Fix | Delete
res += c
[379] Fix | Delete
index += 1
[380] Fix | Delete
else:
[381] Fix | Delete
path = path[index+1:]
[382] Fix | Delete
pathlen = len(path)
[383] Fix | Delete
try:
[384] Fix | Delete
index = path.index(percent)
[385] Fix | Delete
except ValueError:
[386] Fix | Delete
res += percent + path
[387] Fix | Delete
index = pathlen - 1
[388] Fix | Delete
else:
[389] Fix | Delete
var = path[:index]
[390] Fix | Delete
try:
[391] Fix | Delete
if environ is None:
[392] Fix | Delete
value = os.fsencode(os.environ[os.fsdecode(var)])
[393] Fix | Delete
else:
[394] Fix | Delete
value = environ[var]
[395] Fix | Delete
except KeyError:
[396] Fix | Delete
value = percent + var + percent
[397] Fix | Delete
res += value
[398] Fix | Delete
elif c == dollar: # variable or '$$'
[399] Fix | Delete
if path[index + 1:index + 2] == dollar:
[400] Fix | Delete
res += c
[401] Fix | Delete
index += 1
[402] Fix | Delete
elif path[index + 1:index + 2] == brace:
[403] Fix | Delete
path = path[index+2:]
[404] Fix | Delete
pathlen = len(path)
[405] Fix | Delete
try:
[406] Fix | Delete
index = path.index(rbrace)
[407] Fix | Delete
except ValueError:
[408] Fix | Delete
res += dollar + brace + path
[409] Fix | Delete
index = pathlen - 1
[410] Fix | Delete
else:
[411] Fix | Delete
var = path[:index]
[412] Fix | Delete
try:
[413] Fix | Delete
if environ is None:
[414] Fix | Delete
value = os.fsencode(os.environ[os.fsdecode(var)])
[415] Fix | Delete
else:
[416] Fix | Delete
value = environ[var]
[417] Fix | Delete
except KeyError:
[418] Fix | Delete
value = dollar + brace + var + rbrace
[419] Fix | Delete
res += value
[420] Fix | Delete
else:
[421] Fix | Delete
var = path[:0]
[422] Fix | Delete
index += 1
[423] Fix | Delete
c = path[index:index + 1]
[424] Fix | Delete
while c and c in varchars:
[425] Fix | Delete
var += c
[426] Fix | Delete
index += 1
[427] Fix | Delete
c = path[index:index + 1]
[428] Fix | Delete
try:
[429] Fix | Delete
if environ is None:
[430] Fix | Delete
value = os.fsencode(os.environ[os.fsdecode(var)])
[431] Fix | Delete
else:
[432] Fix | Delete
value = environ[var]
[433] Fix | Delete
except KeyError:
[434] Fix | Delete
value = dollar + var
[435] Fix | Delete
res += value
[436] Fix | Delete
if c:
[437] Fix | Delete
index -= 1
[438] Fix | Delete
else:
[439] Fix | Delete
res += c
[440] Fix | Delete
index += 1
[441] Fix | Delete
return res
[442] Fix | Delete
[443] Fix | Delete
[444] Fix | Delete
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
[445] Fix | Delete
# Previously, this function also truncated pathnames to 8+3 format,
[446] Fix | Delete
# but as this module is called "ntpath", that's obviously wrong!
[447] Fix | Delete
[448] Fix | Delete
def normpath(path):
[449] Fix | Delete
"""Normalize path, eliminating double slashes, etc."""
[450] Fix | Delete
path = os.fspath(path)
[451] Fix | Delete
if isinstance(path, bytes):
[452] Fix | Delete
sep = b'\\'
[453] Fix | Delete
altsep = b'/'
[454] Fix | Delete
curdir = b'.'
[455] Fix | Delete
pardir = b'..'
[456] Fix | Delete
special_prefixes = (b'\\\\.\\', b'\\\\?\\')
[457] Fix | Delete
else:
[458] Fix | Delete
sep = '\\'
[459] Fix | Delete
altsep = '/'
[460] Fix | Delete
curdir = '.'
[461] Fix | Delete
pardir = '..'
[462] Fix | Delete
special_prefixes = ('\\\\.\\', '\\\\?\\')
[463] Fix | Delete
if path.startswith(special_prefixes):
[464] Fix | Delete
# in the case of paths with these prefixes:
[465] Fix | Delete
# \\.\ -> device names
[466] Fix | Delete
# \\?\ -> literal paths
[467] Fix | Delete
# do not do any normalization, but return the path
[468] Fix | Delete
# unchanged apart from the call to os.fspath()
[469] Fix | Delete
return path
[470] Fix | Delete
path = path.replace(altsep, sep)
[471] Fix | Delete
prefix, path = splitdrive(path)
[472] Fix | Delete
[473] Fix | Delete
# collapse initial backslashes
[474] Fix | Delete
if path.startswith(sep):
[475] Fix | Delete
prefix += sep
[476] Fix | Delete
path = path.lstrip(sep)
[477] Fix | Delete
[478] Fix | Delete
comps = path.split(sep)
[479] Fix | Delete
i = 0
[480] Fix | Delete
while i < len(comps):
[481] Fix | Delete
if not comps[i] or comps[i] == curdir:
[482] Fix | Delete
del comps[i]
[483] Fix | Delete
elif comps[i] == pardir:
[484] Fix | Delete
if i > 0 and comps[i-1] != pardir:
[485] Fix | Delete
del comps[i-1:i+1]
[486] Fix | Delete
i -= 1
[487] Fix | Delete
elif i == 0 and prefix.endswith(sep):
[488] Fix | Delete
del comps[i]
[489] Fix | Delete
else:
[490] Fix | Delete
i += 1
[491] Fix | Delete
else:
[492] Fix | Delete
i += 1
[493] Fix | Delete
# If the path is now empty, substitute '.'
[494] Fix | Delete
if not prefix and not comps:
[495] Fix | Delete
comps.append(curdir)
[496] Fix | Delete
return prefix + sep.join(comps)
[497] Fix | Delete
[498] Fix | Delete
def _abspath_fallback(path):
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function