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