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