Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: macpath.py
"""Pathname and path-related operations for the Macintosh."""
[0] Fix | Delete
[1] Fix | Delete
# strings representing various path-related bits and pieces
[2] Fix | Delete
# These are primarily for export; internally, they are hardcoded.
[3] Fix | Delete
# Should be set before imports for resolving cyclic dependency.
[4] Fix | Delete
curdir = ':'
[5] Fix | Delete
pardir = '::'
[6] Fix | Delete
extsep = '.'
[7] Fix | Delete
sep = ':'
[8] Fix | Delete
pathsep = '\n'
[9] Fix | Delete
defpath = ':'
[10] Fix | Delete
altsep = None
[11] Fix | Delete
devnull = 'Dev:Null'
[12] Fix | Delete
[13] Fix | Delete
import os
[14] Fix | Delete
from stat import *
[15] Fix | Delete
import genericpath
[16] Fix | Delete
from genericpath import *
[17] Fix | Delete
[18] Fix | Delete
__all__ = ["normcase","isabs","join","splitdrive","split","splitext",
[19] Fix | Delete
"basename","dirname","commonprefix","getsize","getmtime",
[20] Fix | Delete
"getatime","getctime", "islink","exists","lexists","isdir","isfile",
[21] Fix | Delete
"expanduser","expandvars","normpath","abspath",
[22] Fix | Delete
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
[23] Fix | Delete
"devnull","realpath","supports_unicode_filenames"]
[24] Fix | Delete
[25] Fix | Delete
def _get_colon(path):
[26] Fix | Delete
if isinstance(path, bytes):
[27] Fix | Delete
return b':'
[28] Fix | Delete
else:
[29] Fix | Delete
return ':'
[30] Fix | Delete
[31] Fix | Delete
# Normalize the case of a pathname. Dummy in Posix, but <s>.lower() here.
[32] Fix | Delete
[33] Fix | Delete
def normcase(path):
[34] Fix | Delete
if not isinstance(path, (bytes, str)):
[35] Fix | Delete
raise TypeError("normcase() argument must be str or bytes, "
[36] Fix | Delete
"not '{}'".format(path.__class__.__name__))
[37] Fix | Delete
return path.lower()
[38] Fix | Delete
[39] Fix | Delete
[40] Fix | Delete
def isabs(s):
[41] Fix | Delete
"""Return true if a path is absolute.
[42] Fix | Delete
On the Mac, relative paths begin with a colon,
[43] Fix | Delete
but as a special case, paths with no colons at all are also relative.
[44] Fix | Delete
Anything else is absolute (the string up to the first colon is the
[45] Fix | Delete
volume name)."""
[46] Fix | Delete
[47] Fix | Delete
colon = _get_colon(s)
[48] Fix | Delete
return colon in s and s[:1] != colon
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
def join(s, *p):
[52] Fix | Delete
try:
[53] Fix | Delete
colon = _get_colon(s)
[54] Fix | Delete
path = s
[55] Fix | Delete
if not p:
[56] Fix | Delete
path[:0] + colon #23780: Ensure compatible data type even if p is null.
[57] Fix | Delete
for t in p:
[58] Fix | Delete
if (not path) or isabs(t):
[59] Fix | Delete
path = t
[60] Fix | Delete
continue
[61] Fix | Delete
if t[:1] == colon:
[62] Fix | Delete
t = t[1:]
[63] Fix | Delete
if colon not in path:
[64] Fix | Delete
path = colon + path
[65] Fix | Delete
if path[-1:] != colon:
[66] Fix | Delete
path = path + colon
[67] Fix | Delete
path = path + t
[68] Fix | Delete
return path
[69] Fix | Delete
except (TypeError, AttributeError, BytesWarning):
[70] Fix | Delete
genericpath._check_arg_types('join', s, *p)
[71] Fix | Delete
raise
[72] Fix | Delete
[73] Fix | Delete
[74] Fix | Delete
def split(s):
[75] Fix | Delete
"""Split a pathname into two parts: the directory leading up to the final
[76] Fix | Delete
bit, and the basename (the filename, without colons, in that directory).
[77] Fix | Delete
The result (s, t) is such that join(s, t) yields the original argument."""
[78] Fix | Delete
[79] Fix | Delete
colon = _get_colon(s)
[80] Fix | Delete
if colon not in s: return s[:0], s
[81] Fix | Delete
col = 0
[82] Fix | Delete
for i in range(len(s)):
[83] Fix | Delete
if s[i:i+1] == colon: col = i + 1
[84] Fix | Delete
path, file = s[:col-1], s[col:]
[85] Fix | Delete
if path and not colon in path:
[86] Fix | Delete
path = path + colon
[87] Fix | Delete
return path, file
[88] Fix | Delete
[89] Fix | Delete
[90] Fix | Delete
def splitext(p):
[91] Fix | Delete
if isinstance(p, bytes):
[92] Fix | Delete
return genericpath._splitext(p, b':', altsep, b'.')
[93] Fix | Delete
else:
[94] Fix | Delete
return genericpath._splitext(p, sep, altsep, extsep)
[95] Fix | Delete
splitext.__doc__ = genericpath._splitext.__doc__
[96] Fix | Delete
[97] Fix | Delete
def splitdrive(p):
[98] Fix | Delete
"""Split a pathname into a drive specification and the rest of the
[99] Fix | Delete
path. Useful on DOS/Windows/NT; on the Mac, the drive is always
[100] Fix | Delete
empty (don't use the volume name -- it doesn't have the same
[101] Fix | Delete
syntactic and semantic oddities as DOS drive letters, such as there
[102] Fix | Delete
being a separate current directory per drive)."""
[103] Fix | Delete
[104] Fix | Delete
return p[:0], p
[105] Fix | Delete
[106] Fix | Delete
[107] Fix | Delete
# Short interfaces to split()
[108] Fix | Delete
[109] Fix | Delete
def dirname(s): return split(s)[0]
[110] Fix | Delete
def basename(s): return split(s)[1]
[111] Fix | Delete
[112] Fix | Delete
def ismount(s):
[113] Fix | Delete
if not isabs(s):
[114] Fix | Delete
return False
[115] Fix | Delete
components = split(s)
[116] Fix | Delete
return len(components) == 2 and not components[1]
[117] Fix | Delete
[118] Fix | Delete
def islink(s):
[119] Fix | Delete
"""Return true if the pathname refers to a symbolic link."""
[120] Fix | Delete
[121] Fix | Delete
try:
[122] Fix | Delete
import Carbon.File
[123] Fix | Delete
return Carbon.File.ResolveAliasFile(s, 0)[2]
[124] Fix | Delete
except:
[125] Fix | Delete
return False
[126] Fix | Delete
[127] Fix | Delete
# Is `stat`/`lstat` a meaningful difference on the Mac? This is safe in any
[128] Fix | Delete
# case.
[129] Fix | Delete
[130] Fix | Delete
def lexists(path):
[131] Fix | Delete
"""Test whether a path exists. Returns True for broken symbolic links"""
[132] Fix | Delete
[133] Fix | Delete
try:
[134] Fix | Delete
st = os.lstat(path)
[135] Fix | Delete
except OSError:
[136] Fix | Delete
return False
[137] Fix | Delete
return True
[138] Fix | Delete
[139] Fix | Delete
def expandvars(path):
[140] Fix | Delete
"""Dummy to retain interface-compatibility with other operating systems."""
[141] Fix | Delete
return path
[142] Fix | Delete
[143] Fix | Delete
[144] Fix | Delete
def expanduser(path):
[145] Fix | Delete
"""Dummy to retain interface-compatibility with other operating systems."""
[146] Fix | Delete
return path
[147] Fix | Delete
[148] Fix | Delete
class norm_error(Exception):
[149] Fix | Delete
"""Path cannot be normalized"""
[150] Fix | Delete
[151] Fix | Delete
def normpath(s):
[152] Fix | Delete
"""Normalize a pathname. Will return the same result for
[153] Fix | Delete
equivalent paths."""
[154] Fix | Delete
[155] Fix | Delete
colon = _get_colon(s)
[156] Fix | Delete
[157] Fix | Delete
if colon not in s:
[158] Fix | Delete
return colon + s
[159] Fix | Delete
[160] Fix | Delete
comps = s.split(colon)
[161] Fix | Delete
i = 1
[162] Fix | Delete
while i < len(comps)-1:
[163] Fix | Delete
if not comps[i] and comps[i-1]:
[164] Fix | Delete
if i > 1:
[165] Fix | Delete
del comps[i-1:i+1]
[166] Fix | Delete
i = i - 1
[167] Fix | Delete
else:
[168] Fix | Delete
# best way to handle this is to raise an exception
[169] Fix | Delete
raise norm_error('Cannot use :: immediately after volume name')
[170] Fix | Delete
else:
[171] Fix | Delete
i = i + 1
[172] Fix | Delete
[173] Fix | Delete
s = colon.join(comps)
[174] Fix | Delete
[175] Fix | Delete
# remove trailing ":" except for ":" and "Volume:"
[176] Fix | Delete
if s[-1:] == colon and len(comps) > 2 and s != colon*len(s):
[177] Fix | Delete
s = s[:-1]
[178] Fix | Delete
return s
[179] Fix | Delete
[180] Fix | Delete
def abspath(path):
[181] Fix | Delete
"""Return an absolute path."""
[182] Fix | Delete
if not isabs(path):
[183] Fix | Delete
if isinstance(path, bytes):
[184] Fix | Delete
cwd = os.getcwdb()
[185] Fix | Delete
else:
[186] Fix | Delete
cwd = os.getcwd()
[187] Fix | Delete
path = join(cwd, path)
[188] Fix | Delete
return normpath(path)
[189] Fix | Delete
[190] Fix | Delete
# realpath is a no-op on systems without islink support
[191] Fix | Delete
def realpath(path):
[192] Fix | Delete
path = abspath(path)
[193] Fix | Delete
try:
[194] Fix | Delete
import Carbon.File
[195] Fix | Delete
except ImportError:
[196] Fix | Delete
return path
[197] Fix | Delete
if not path:
[198] Fix | Delete
return path
[199] Fix | Delete
colon = _get_colon(path)
[200] Fix | Delete
components = path.split(colon)
[201] Fix | Delete
path = components[0] + colon
[202] Fix | Delete
for c in components[1:]:
[203] Fix | Delete
path = join(path, c)
[204] Fix | Delete
try:
[205] Fix | Delete
path = Carbon.File.FSResolveAliasFile(path, 1)[0].as_pathname()
[206] Fix | Delete
except Carbon.File.Error:
[207] Fix | Delete
pass
[208] Fix | Delete
return path
[209] Fix | Delete
[210] Fix | Delete
supports_unicode_filenames = True
[211] Fix | Delete
[212] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function