Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
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
import os
[7] Fix | Delete
import sys
[8] Fix | Delete
import stat
[9] Fix | Delete
import genericpath
[10] Fix | Delete
import warnings
[11] Fix | Delete
[12] Fix | Delete
from genericpath import *
[13] Fix | Delete
from genericpath import _unicode
[14] Fix | Delete
[15] Fix | Delete
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
[16] Fix | Delete
"basename","dirname","commonprefix","getsize","getmtime",
[17] Fix | Delete
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
[18] Fix | Delete
"ismount","walk","expanduser","expandvars","normpath","abspath",
[19] Fix | Delete
"splitunc","curdir","pardir","sep","pathsep","defpath","altsep",
[20] Fix | Delete
"extsep","devnull","realpath","supports_unicode_filenames","relpath"]
[21] Fix | Delete
[22] Fix | Delete
# strings representing various path-related bits and pieces
[23] Fix | Delete
curdir = '.'
[24] Fix | Delete
pardir = '..'
[25] Fix | Delete
extsep = '.'
[26] Fix | Delete
sep = '\\'
[27] Fix | Delete
pathsep = ';'
[28] Fix | Delete
altsep = '/'
[29] Fix | Delete
defpath = '.;C:\\bin'
[30] Fix | Delete
if 'ce' in sys.builtin_module_names:
[31] Fix | Delete
defpath = '\\Windows'
[32] Fix | Delete
elif 'os2' in sys.builtin_module_names:
[33] Fix | Delete
# OS/2 w/ VACPP
[34] Fix | Delete
altsep = '/'
[35] Fix | Delete
devnull = 'nul'
[36] Fix | Delete
[37] Fix | Delete
# Normalize the case of a pathname and map slashes to backslashes.
[38] Fix | Delete
# Other normalizations (such as optimizing '../' away) are not done
[39] Fix | Delete
# (this is done by normpath).
[40] Fix | Delete
[41] Fix | Delete
def normcase(s):
[42] Fix | Delete
"""Normalize case of pathname.
[43] Fix | Delete
[44] Fix | Delete
Makes all characters lowercase and all slashes into backslashes."""
[45] Fix | Delete
return s.replace("/", "\\").lower()
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
# Return whether a path is absolute.
[49] Fix | Delete
# Trivial in Posix, harder on the Mac or MS-DOS.
[50] Fix | Delete
# For DOS it is absolute if it starts with a slash or backslash (current
[51] Fix | Delete
# volume), or if a pathname after the volume letter and colon / UNC resource
[52] Fix | Delete
# starts with a slash or backslash.
[53] Fix | Delete
[54] Fix | Delete
def isabs(s):
[55] Fix | Delete
"""Test whether a path is absolute"""
[56] Fix | Delete
s = splitdrive(s)[1]
[57] Fix | Delete
return s != '' and s[:1] in '/\\'
[58] Fix | Delete
[59] Fix | Delete
[60] Fix | Delete
# Join two (or more) paths.
[61] Fix | Delete
def join(path, *paths):
[62] Fix | Delete
"""Join two or more pathname components, inserting "\\" as needed."""
[63] Fix | Delete
result_drive, result_path = splitdrive(path)
[64] Fix | Delete
for p in paths:
[65] Fix | Delete
p_drive, p_path = splitdrive(p)
[66] Fix | Delete
if p_path and p_path[0] in '\\/':
[67] Fix | Delete
# Second path is absolute
[68] Fix | Delete
if p_drive or not result_drive:
[69] Fix | Delete
result_drive = p_drive
[70] Fix | Delete
result_path = p_path
[71] Fix | Delete
continue
[72] Fix | Delete
elif p_drive and p_drive != result_drive:
[73] Fix | Delete
if p_drive.lower() != result_drive.lower():
[74] Fix | Delete
# Different drives => ignore the first path entirely
[75] Fix | Delete
result_drive = p_drive
[76] Fix | Delete
result_path = p_path
[77] Fix | Delete
continue
[78] Fix | Delete
# Same drive in different case
[79] Fix | Delete
result_drive = p_drive
[80] Fix | Delete
# Second path is relative to the first
[81] Fix | Delete
if result_path and result_path[-1] not in '\\/':
[82] Fix | Delete
result_path = result_path + '\\'
[83] Fix | Delete
result_path = result_path + p_path
[84] Fix | Delete
## add separator between UNC and non-absolute path
[85] Fix | Delete
if (result_path and result_path[0] not in '\\/' and
[86] Fix | Delete
result_drive and result_drive[-1:] != ':'):
[87] Fix | Delete
return result_drive + sep + result_path
[88] Fix | Delete
return result_drive + result_path
[89] Fix | Delete
[90] Fix | Delete
[91] Fix | Delete
# Split a path in a drive specification (a drive letter followed by a
[92] Fix | Delete
# colon) and the path specification.
[93] Fix | Delete
# It is always true that drivespec + pathspec == p
[94] Fix | Delete
def splitdrive(p):
[95] Fix | Delete
"""Split a pathname into drive/UNC sharepoint and relative path specifiers.
[96] Fix | Delete
Returns a 2-tuple (drive_or_unc, path); either part may be empty.
[97] Fix | Delete
[98] Fix | Delete
If you assign
[99] Fix | Delete
result = splitdrive(p)
[100] Fix | Delete
It is always true that:
[101] Fix | Delete
result[0] + result[1] == p
[102] Fix | Delete
[103] Fix | Delete
If the path contained a drive letter, drive_or_unc will contain everything
[104] Fix | Delete
up to and including the colon. e.g. splitdrive("c:/dir") returns ("c:", "/dir")
[105] Fix | Delete
[106] Fix | Delete
If the path contained a UNC path, the drive_or_unc will contain the host name
[107] Fix | Delete
and share up to but not including the fourth directory separator character.
[108] Fix | Delete
e.g. splitdrive("//host/computer/dir") returns ("//host/computer", "/dir")
[109] Fix | Delete
[110] Fix | Delete
Paths cannot contain both a drive letter and a UNC path.
[111] Fix | Delete
[112] Fix | Delete
"""
[113] Fix | Delete
if len(p) > 1:
[114] Fix | Delete
normp = p.replace(altsep, sep)
[115] Fix | Delete
if (normp[0:2] == sep*2) and (normp[2:3] != sep):
[116] Fix | Delete
# is a UNC path:
[117] Fix | Delete
# vvvvvvvvvvvvvvvvvvvv drive letter or UNC path
[118] Fix | Delete
# \\machine\mountpoint\directory\etc\...
[119] Fix | Delete
# directory ^^^^^^^^^^^^^^^
[120] Fix | Delete
index = normp.find(sep, 2)
[121] Fix | Delete
if index == -1:
[122] Fix | Delete
return '', p
[123] Fix | Delete
index2 = normp.find(sep, index + 1)
[124] Fix | Delete
# a UNC path can't have two slashes in a row
[125] Fix | Delete
# (after the initial two)
[126] Fix | Delete
if index2 == index + 1:
[127] Fix | Delete
return '', p
[128] Fix | Delete
if index2 == -1:
[129] Fix | Delete
index2 = len(p)
[130] Fix | Delete
return p[:index2], p[index2:]
[131] Fix | Delete
if normp[1] == ':':
[132] Fix | Delete
return p[:2], p[2:]
[133] Fix | Delete
return '', p
[134] Fix | Delete
[135] Fix | Delete
# Parse UNC paths
[136] Fix | Delete
def splitunc(p):
[137] Fix | Delete
"""Split a pathname into UNC mount point and relative path specifiers.
[138] Fix | Delete
[139] Fix | Delete
Return a 2-tuple (unc, rest); either part may be empty.
[140] Fix | Delete
If unc is not empty, it has the form '//host/mount' (or similar
[141] Fix | Delete
using backslashes). unc+rest is always the input path.
[142] Fix | Delete
Paths containing drive letters never have a UNC part.
[143] Fix | Delete
"""
[144] Fix | Delete
if p[1:2] == ':':
[145] Fix | Delete
return '', p # Drive letter present
[146] Fix | Delete
firstTwo = p[0:2]
[147] Fix | Delete
if firstTwo == '//' or firstTwo == '\\\\':
[148] Fix | Delete
# is a UNC path:
[149] Fix | Delete
# vvvvvvvvvvvvvvvvvvvv equivalent to drive letter
[150] Fix | Delete
# \\machine\mountpoint\directories...
[151] Fix | Delete
# directory ^^^^^^^^^^^^^^^
[152] Fix | Delete
normp = p.replace('\\', '/')
[153] Fix | Delete
index = normp.find('/', 2)
[154] Fix | Delete
if index <= 2:
[155] Fix | Delete
return '', p
[156] Fix | Delete
index2 = normp.find('/', index + 1)
[157] Fix | Delete
# a UNC path can't have two slashes in a row
[158] Fix | Delete
# (after the initial two)
[159] Fix | Delete
if index2 == index + 1:
[160] Fix | Delete
return '', p
[161] Fix | Delete
if index2 == -1:
[162] Fix | Delete
index2 = len(p)
[163] Fix | Delete
return p[:index2], p[index2:]
[164] Fix | Delete
return '', p
[165] Fix | Delete
[166] Fix | Delete
[167] Fix | Delete
# Split a path in head (everything up to the last '/') and tail (the
[168] Fix | Delete
# rest). After the trailing '/' is stripped, the invariant
[169] Fix | Delete
# join(head, tail) == p holds.
[170] Fix | Delete
# The resulting head won't end in '/' unless it is the root.
[171] Fix | Delete
[172] Fix | Delete
def split(p):
[173] Fix | Delete
"""Split a pathname.
[174] Fix | Delete
[175] Fix | Delete
Return tuple (head, tail) where tail is everything after the final slash.
[176] Fix | Delete
Either part may be empty."""
[177] Fix | Delete
[178] Fix | Delete
d, p = splitdrive(p)
[179] Fix | Delete
# set i to index beyond p's last slash
[180] Fix | Delete
i = len(p)
[181] Fix | Delete
while i and p[i-1] not in '/\\':
[182] Fix | Delete
i = i - 1
[183] Fix | Delete
head, tail = p[:i], p[i:] # now tail has no slashes
[184] Fix | Delete
# remove trailing slashes from head, unless it's all slashes
[185] Fix | Delete
head2 = head
[186] Fix | Delete
while head2 and head2[-1] in '/\\':
[187] Fix | Delete
head2 = head2[:-1]
[188] Fix | Delete
head = head2 or head
[189] Fix | Delete
return d + head, tail
[190] Fix | Delete
[191] Fix | Delete
[192] Fix | Delete
# Split a path in root and extension.
[193] Fix | Delete
# The extension is everything starting at the last dot in the last
[194] Fix | Delete
# pathname component; the root is everything before that.
[195] Fix | Delete
# It is always true that root + ext == p.
[196] Fix | Delete
[197] Fix | Delete
def splitext(p):
[198] Fix | Delete
return genericpath._splitext(p, sep, altsep, extsep)
[199] Fix | Delete
splitext.__doc__ = genericpath._splitext.__doc__
[200] Fix | Delete
[201] Fix | Delete
[202] Fix | Delete
# Return the tail (basename) part of a path.
[203] Fix | Delete
[204] Fix | Delete
def basename(p):
[205] Fix | Delete
"""Returns the final component of a pathname"""
[206] Fix | Delete
return split(p)[1]
[207] Fix | Delete
[208] Fix | Delete
[209] Fix | Delete
# Return the head (dirname) part of a path.
[210] Fix | Delete
[211] Fix | Delete
def dirname(p):
[212] Fix | Delete
"""Returns the directory component of a pathname"""
[213] Fix | Delete
return split(p)[0]
[214] Fix | Delete
[215] Fix | Delete
# Is a path a symbolic link?
[216] Fix | Delete
# This will always return false on systems where posix.lstat doesn't exist.
[217] Fix | Delete
[218] Fix | Delete
def islink(path):
[219] Fix | Delete
"""Test for symbolic link.
[220] Fix | Delete
On WindowsNT/95 and OS/2 always returns false
[221] Fix | Delete
"""
[222] Fix | Delete
return False
[223] Fix | Delete
[224] Fix | Delete
# alias exists to lexists
[225] Fix | Delete
lexists = exists
[226] Fix | Delete
[227] Fix | Delete
# Is a path a mount point? Either a root (with or without drive letter)
[228] Fix | Delete
# or a UNC path with at most a / or \ after the mount point.
[229] Fix | Delete
[230] Fix | Delete
def ismount(path):
[231] Fix | Delete
"""Test whether a path is a mount point (defined as root of drive)"""
[232] Fix | Delete
unc, rest = splitunc(path)
[233] Fix | Delete
if unc:
[234] Fix | Delete
return rest in ("", "/", "\\")
[235] Fix | Delete
p = splitdrive(path)[1]
[236] Fix | Delete
return len(p) == 1 and p[0] in '/\\'
[237] Fix | Delete
[238] Fix | Delete
[239] Fix | Delete
# Directory tree walk.
[240] Fix | Delete
# For each directory under top (including top itself, but excluding
[241] Fix | Delete
# '.' and '..'), func(arg, dirname, filenames) is called, where
[242] Fix | Delete
# dirname is the name of the directory and filenames is the list
[243] Fix | Delete
# of files (and subdirectories etc.) in the directory.
[244] Fix | Delete
# The func may modify the filenames list, to implement a filter,
[245] Fix | Delete
# or to impose a different order of visiting.
[246] Fix | Delete
[247] Fix | Delete
def walk(top, func, arg):
[248] Fix | Delete
"""Directory tree walk with callback function.
[249] Fix | Delete
[250] Fix | Delete
For each directory in the directory tree rooted at top (including top
[251] Fix | Delete
itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
[252] Fix | Delete
dirname is the name of the directory, and fnames a list of the names of
[253] Fix | Delete
the files and subdirectories in dirname (excluding '.' and '..'). func
[254] Fix | Delete
may modify the fnames list in-place (e.g. via del or slice assignment),
[255] Fix | Delete
and walk will only recurse into the subdirectories whose names remain in
[256] Fix | Delete
fnames; this can be used to implement a filter, or to impose a specific
[257] Fix | Delete
order of visiting. No semantics are defined for, or required of, arg,
[258] Fix | Delete
beyond that arg is always passed to func. It can be used, e.g., to pass
[259] Fix | Delete
a filename pattern, or a mutable object designed to accumulate
[260] Fix | Delete
statistics. Passing None for arg is common."""
[261] Fix | Delete
warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
[262] Fix | Delete
stacklevel=2)
[263] Fix | Delete
try:
[264] Fix | Delete
names = os.listdir(top)
[265] Fix | Delete
except os.error:
[266] Fix | Delete
return
[267] Fix | Delete
func(arg, top, names)
[268] Fix | Delete
for name in names:
[269] Fix | Delete
name = join(top, name)
[270] Fix | Delete
if isdir(name):
[271] Fix | Delete
walk(name, func, arg)
[272] Fix | Delete
[273] Fix | Delete
[274] Fix | Delete
# Expand paths beginning with '~' or '~user'.
[275] Fix | Delete
# '~' means $HOME; '~user' means that user's home directory.
[276] Fix | Delete
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
[277] Fix | Delete
# the path is returned unchanged (leaving error reporting to whatever
[278] Fix | Delete
# function is called with the expanded path as argument).
[279] Fix | Delete
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
[280] Fix | Delete
# (A function should also be defined to do full *sh-style environment
[281] Fix | Delete
# variable expansion.)
[282] Fix | Delete
[283] Fix | Delete
def expanduser(path):
[284] Fix | Delete
"""Expand ~ and ~user constructs.
[285] Fix | Delete
[286] Fix | Delete
If user or $HOME is unknown, do nothing."""
[287] Fix | Delete
if path[:1] != '~':
[288] Fix | Delete
return path
[289] Fix | Delete
i, n = 1, len(path)
[290] Fix | Delete
while i < n and path[i] not in '/\\':
[291] Fix | Delete
i = i + 1
[292] Fix | Delete
[293] Fix | Delete
if 'HOME' in os.environ:
[294] Fix | Delete
userhome = os.environ['HOME']
[295] Fix | Delete
elif 'USERPROFILE' in os.environ:
[296] Fix | Delete
userhome = os.environ['USERPROFILE']
[297] Fix | Delete
elif not 'HOMEPATH' in os.environ:
[298] Fix | Delete
return path
[299] Fix | Delete
else:
[300] Fix | Delete
try:
[301] Fix | Delete
drive = os.environ['HOMEDRIVE']
[302] Fix | Delete
except KeyError:
[303] Fix | Delete
drive = ''
[304] Fix | Delete
userhome = join(drive, os.environ['HOMEPATH'])
[305] Fix | Delete
[306] Fix | Delete
if i != 1: #~user
[307] Fix | Delete
userhome = join(dirname(userhome), path[1:i])
[308] Fix | Delete
[309] Fix | Delete
return userhome + path[i:]
[310] Fix | Delete
[311] Fix | Delete
[312] Fix | Delete
# Expand paths containing shell variable substitutions.
[313] Fix | Delete
# The following rules apply:
[314] Fix | Delete
# - no expansion within single quotes
[315] Fix | Delete
# - '$$' is translated into '$'
[316] Fix | Delete
# - '%%' is translated into '%' if '%%' are not seen in %var1%%var2%
[317] Fix | Delete
# - ${varname} is accepted.
[318] Fix | Delete
# - $varname is accepted.
[319] Fix | Delete
# - %varname% is accepted.
[320] Fix | Delete
# - varnames can be made out of letters, digits and the characters '_-'
[321] Fix | Delete
# (though is not verified in the ${varname} and %varname% cases)
[322] Fix | Delete
# XXX With COMMAND.COM you can use any characters in a variable name,
[323] Fix | Delete
# XXX except '^|<>='.
[324] Fix | Delete
[325] Fix | Delete
def expandvars(path):
[326] Fix | Delete
"""Expand shell variables of the forms $var, ${var} and %var%.
[327] Fix | Delete
[328] Fix | Delete
Unknown variables are left unchanged."""
[329] Fix | Delete
if '$' not in path and '%' not in path:
[330] Fix | Delete
return path
[331] Fix | Delete
import string
[332] Fix | Delete
varchars = string.ascii_letters + string.digits + '_-'
[333] Fix | Delete
if isinstance(path, _unicode):
[334] Fix | Delete
encoding = sys.getfilesystemencoding()
[335] Fix | Delete
def getenv(var):
[336] Fix | Delete
return os.environ[var.encode(encoding)].decode(encoding)
[337] Fix | Delete
else:
[338] Fix | Delete
def getenv(var):
[339] Fix | Delete
return os.environ[var]
[340] Fix | Delete
res = ''
[341] Fix | Delete
index = 0
[342] Fix | Delete
pathlen = len(path)
[343] Fix | Delete
while index < pathlen:
[344] Fix | Delete
c = path[index]
[345] Fix | Delete
if c == '\'': # no expansion within single quotes
[346] Fix | Delete
path = path[index + 1:]
[347] Fix | Delete
pathlen = len(path)
[348] Fix | Delete
try:
[349] Fix | Delete
index = path.index('\'')
[350] Fix | Delete
res = res + '\'' + path[:index + 1]
[351] Fix | Delete
except ValueError:
[352] Fix | Delete
res = res + c + path
[353] Fix | Delete
index = pathlen - 1
[354] Fix | Delete
elif c == '%': # variable or '%'
[355] Fix | Delete
if path[index + 1:index + 2] == '%':
[356] Fix | Delete
res = res + c
[357] Fix | Delete
index = index + 1
[358] Fix | Delete
else:
[359] Fix | Delete
path = path[index+1:]
[360] Fix | Delete
pathlen = len(path)
[361] Fix | Delete
try:
[362] Fix | Delete
index = path.index('%')
[363] Fix | Delete
except ValueError:
[364] Fix | Delete
res = res + '%' + path
[365] Fix | Delete
index = pathlen - 1
[366] Fix | Delete
else:
[367] Fix | Delete
var = path[:index]
[368] Fix | Delete
try:
[369] Fix | Delete
res = res + getenv(var)
[370] Fix | Delete
except KeyError:
[371] Fix | Delete
res = res + '%' + var + '%'
[372] Fix | Delete
elif c == '$': # variable or '$$'
[373] Fix | Delete
if path[index + 1:index + 2] == '$':
[374] Fix | Delete
res = res + c
[375] Fix | Delete
index = index + 1
[376] Fix | Delete
elif path[index + 1:index + 2] == '{':
[377] Fix | Delete
path = path[index+2:]
[378] Fix | Delete
pathlen = len(path)
[379] Fix | Delete
try:
[380] Fix | Delete
index = path.index('}')
[381] Fix | Delete
var = path[:index]
[382] Fix | Delete
try:
[383] Fix | Delete
res = res + getenv(var)
[384] Fix | Delete
except KeyError:
[385] Fix | Delete
res = res + '${' + var + '}'
[386] Fix | Delete
except ValueError:
[387] Fix | Delete
res = res + '${' + path
[388] Fix | Delete
index = pathlen - 1
[389] Fix | Delete
else:
[390] Fix | Delete
var = ''
[391] Fix | Delete
index = index + 1
[392] Fix | Delete
c = path[index:index + 1]
[393] Fix | Delete
while c != '' and c in varchars:
[394] Fix | Delete
var = var + c
[395] Fix | Delete
index = index + 1
[396] Fix | Delete
c = path[index:index + 1]
[397] Fix | Delete
try:
[398] Fix | Delete
res = res + getenv(var)
[399] Fix | Delete
except KeyError:
[400] Fix | Delete
res = res + '$' + var
[401] Fix | Delete
if c != '':
[402] Fix | Delete
index = index - 1
[403] Fix | Delete
else:
[404] Fix | Delete
res = res + c
[405] Fix | Delete
index = index + 1
[406] Fix | Delete
return res
[407] Fix | Delete
[408] Fix | Delete
[409] Fix | Delete
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A\B.
[410] Fix | Delete
# Previously, this function also truncated pathnames to 8+3 format,
[411] Fix | Delete
# but as this module is called "ntpath", that's obviously wrong!
[412] Fix | Delete
[413] Fix | Delete
def normpath(path):
[414] Fix | Delete
"""Normalize path, eliminating double slashes, etc."""
[415] Fix | Delete
# Preserve unicode (if path is unicode)
[416] Fix | Delete
backslash, dot = (u'\\', u'.') if isinstance(path, _unicode) else ('\\', '.')
[417] Fix | Delete
if path.startswith(('\\\\.\\', '\\\\?\\')):
[418] Fix | Delete
# in the case of paths with these prefixes:
[419] Fix | Delete
# \\.\ -> device names
[420] Fix | Delete
# \\?\ -> literal paths
[421] Fix | Delete
# do not do any normalization, but return the path unchanged
[422] Fix | Delete
return path
[423] Fix | Delete
path = path.replace("/", "\\")
[424] Fix | Delete
prefix, path = splitdrive(path)
[425] Fix | Delete
# We need to be careful here. If the prefix is empty, and the path starts
[426] Fix | Delete
# with a backslash, it could either be an absolute path on the current
[427] Fix | Delete
# drive (\dir1\dir2\file) or a UNC filename (\\server\mount\dir1\file). It
[428] Fix | Delete
# is therefore imperative NOT to collapse multiple backslashes blindly in
[429] Fix | Delete
# that case.
[430] Fix | Delete
# The code below preserves multiple backslashes when there is no drive
[431] Fix | Delete
# letter. This means that the invalid filename \\\a\b is preserved
[432] Fix | Delete
# unchanged, where a\\\b is normalised to a\b. It's not clear that there
[433] Fix | Delete
# is any better behaviour for such edge cases.
[434] Fix | Delete
if prefix == '':
[435] Fix | Delete
# No drive letter - preserve initial backslashes
[436] Fix | Delete
while path[:1] == "\\":
[437] Fix | Delete
prefix = prefix + backslash
[438] Fix | Delete
path = path[1:]
[439] Fix | Delete
else:
[440] Fix | Delete
# We have a drive letter - collapse initial backslashes
[441] Fix | Delete
if path.startswith("\\"):
[442] Fix | Delete
prefix = prefix + backslash
[443] Fix | Delete
path = path.lstrip("\\")
[444] Fix | Delete
comps = path.split("\\")
[445] Fix | Delete
i = 0
[446] Fix | Delete
while i < len(comps):
[447] Fix | Delete
if comps[i] in ('.', ''):
[448] Fix | Delete
del comps[i]
[449] Fix | Delete
elif comps[i] == '..':
[450] Fix | Delete
if i > 0 and comps[i-1] != '..':
[451] Fix | Delete
del comps[i-1:i+1]
[452] Fix | Delete
i -= 1
[453] Fix | Delete
elif i == 0 and prefix.endswith("\\"):
[454] Fix | Delete
del comps[i]
[455] Fix | Delete
else:
[456] Fix | Delete
i += 1
[457] Fix | Delete
else:
[458] Fix | Delete
i += 1
[459] Fix | Delete
# If the path is now empty, substitute '.'
[460] Fix | Delete
if not prefix and not comps:
[461] Fix | Delete
comps.append(dot)
[462] Fix | Delete
return prefix + backslash.join(comps)
[463] Fix | Delete
[464] Fix | Delete
[465] Fix | Delete
# Return an absolute path.
[466] Fix | Delete
try:
[467] Fix | Delete
from nt import _getfullpathname
[468] Fix | Delete
[469] Fix | Delete
except ImportError: # not running on Windows - mock up something sensible
[470] Fix | Delete
def abspath(path):
[471] Fix | Delete
"""Return the absolute version of a path."""
[472] Fix | Delete
if not isabs(path):
[473] Fix | Delete
if isinstance(path, _unicode):
[474] Fix | Delete
cwd = os.getcwdu()
[475] Fix | Delete
else:
[476] Fix | Delete
cwd = os.getcwd()
[477] Fix | Delete
path = join(cwd, path)
[478] Fix | Delete
return normpath(path)
[479] Fix | Delete
[480] Fix | Delete
else: # use native Windows method on Windows
[481] Fix | Delete
def abspath(path):
[482] Fix | Delete
"""Return the absolute version of a path."""
[483] Fix | Delete
[484] Fix | Delete
if path: # Empty path must return current working directory.
[485] Fix | Delete
try:
[486] Fix | Delete
path = _getfullpathname(path)
[487] Fix | Delete
except WindowsError:
[488] Fix | Delete
pass # Bad path - return unchanged.
[489] Fix | Delete
elif isinstance(path, _unicode):
[490] Fix | Delete
path = os.getcwdu()
[491] Fix | Delete
else:
[492] Fix | Delete
path = os.getcwd()
[493] Fix | Delete
return normpath(path)
[494] Fix | Delete
[495] Fix | Delete
# realpath is a no-op on systems without islink support
[496] Fix | Delete
realpath = abspath
[497] Fix | Delete
# Win9x family and earlier have no Unicode filename support.
[498] Fix | Delete
supports_unicode_filenames = (hasattr(sys, "getwindowsversion") and
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function