Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: genericpath.py
"""
[0] Fix | Delete
Path operations common to more than one OS
[1] Fix | Delete
Do not use directly. The OS specific modules import the appropriate
[2] Fix | Delete
functions from this module themselves.
[3] Fix | Delete
"""
[4] Fix | Delete
import os
[5] Fix | Delete
import stat
[6] Fix | Delete
[7] Fix | Delete
__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
[8] Fix | Delete
'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile',
[9] Fix | Delete
'samestat']
[10] Fix | Delete
[11] Fix | Delete
[12] Fix | Delete
# Does a path exist?
[13] Fix | Delete
# This is false for dangling symbolic links on systems that support them.
[14] Fix | Delete
def exists(path):
[15] Fix | Delete
"""Test whether a path exists. Returns False for broken symbolic links"""
[16] Fix | Delete
try:
[17] Fix | Delete
os.stat(path)
[18] Fix | Delete
except (OSError, ValueError):
[19] Fix | Delete
return False
[20] Fix | Delete
return True
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
# This follows symbolic links, so both islink() and isdir() can be true
[24] Fix | Delete
# for the same path on systems that support symlinks
[25] Fix | Delete
def isfile(path):
[26] Fix | Delete
"""Test whether a path is a regular file"""
[27] Fix | Delete
try:
[28] Fix | Delete
st = os.stat(path)
[29] Fix | Delete
except (OSError, ValueError):
[30] Fix | Delete
return False
[31] Fix | Delete
return stat.S_ISREG(st.st_mode)
[32] Fix | Delete
[33] Fix | Delete
[34] Fix | Delete
# Is a path a directory?
[35] Fix | Delete
# This follows symbolic links, so both islink() and isdir()
[36] Fix | Delete
# can be true for the same path on systems that support symlinks
[37] Fix | Delete
def isdir(s):
[38] Fix | Delete
"""Return true if the pathname refers to an existing directory."""
[39] Fix | Delete
try:
[40] Fix | Delete
st = os.stat(s)
[41] Fix | Delete
except (OSError, ValueError):
[42] Fix | Delete
return False
[43] Fix | Delete
return stat.S_ISDIR(st.st_mode)
[44] Fix | Delete
[45] Fix | Delete
[46] Fix | Delete
def getsize(filename):
[47] Fix | Delete
"""Return the size of a file, reported by os.stat()."""
[48] Fix | Delete
return os.stat(filename).st_size
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
def getmtime(filename):
[52] Fix | Delete
"""Return the last modification time of a file, reported by os.stat()."""
[53] Fix | Delete
return os.stat(filename).st_mtime
[54] Fix | Delete
[55] Fix | Delete
[56] Fix | Delete
def getatime(filename):
[57] Fix | Delete
"""Return the last access time of a file, reported by os.stat()."""
[58] Fix | Delete
return os.stat(filename).st_atime
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
def getctime(filename):
[62] Fix | Delete
"""Return the metadata change time of a file, reported by os.stat()."""
[63] Fix | Delete
return os.stat(filename).st_ctime
[64] Fix | Delete
[65] Fix | Delete
[66] Fix | Delete
# Return the longest prefix of all list elements.
[67] Fix | Delete
def commonprefix(m):
[68] Fix | Delete
"Given a list of pathnames, returns the longest common leading component"
[69] Fix | Delete
if not m: return ''
[70] Fix | Delete
# Some people pass in a list of pathname parts to operate in an OS-agnostic
[71] Fix | Delete
# fashion; don't try to translate in that case as that's an abuse of the
[72] Fix | Delete
# API and they are already doing what they need to be OS-agnostic and so
[73] Fix | Delete
# they most likely won't be using an os.PathLike object in the sublists.
[74] Fix | Delete
if not isinstance(m[0], (list, tuple)):
[75] Fix | Delete
m = tuple(map(os.fspath, m))
[76] Fix | Delete
s1 = min(m)
[77] Fix | Delete
s2 = max(m)
[78] Fix | Delete
for i, c in enumerate(s1):
[79] Fix | Delete
if c != s2[i]:
[80] Fix | Delete
return s1[:i]
[81] Fix | Delete
return s1
[82] Fix | Delete
[83] Fix | Delete
# Are two stat buffers (obtained from stat, fstat or lstat)
[84] Fix | Delete
# describing the same file?
[85] Fix | Delete
def samestat(s1, s2):
[86] Fix | Delete
"""Test whether two stat buffers reference the same file"""
[87] Fix | Delete
return (s1.st_ino == s2.st_ino and
[88] Fix | Delete
s1.st_dev == s2.st_dev)
[89] Fix | Delete
[90] Fix | Delete
[91] Fix | Delete
# Are two filenames really pointing to the same file?
[92] Fix | Delete
def samefile(f1, f2):
[93] Fix | Delete
"""Test whether two pathnames reference the same actual file or directory
[94] Fix | Delete
[95] Fix | Delete
This is determined by the device number and i-node number and
[96] Fix | Delete
raises an exception if an os.stat() call on either pathname fails.
[97] Fix | Delete
"""
[98] Fix | Delete
s1 = os.stat(f1)
[99] Fix | Delete
s2 = os.stat(f2)
[100] Fix | Delete
return samestat(s1, s2)
[101] Fix | Delete
[102] Fix | Delete
[103] Fix | Delete
# Are two open files really referencing the same file?
[104] Fix | Delete
# (Not necessarily the same file descriptor!)
[105] Fix | Delete
def sameopenfile(fp1, fp2):
[106] Fix | Delete
"""Test whether two open file objects reference the same file"""
[107] Fix | Delete
s1 = os.fstat(fp1)
[108] Fix | Delete
s2 = os.fstat(fp2)
[109] Fix | Delete
return samestat(s1, s2)
[110] Fix | Delete
[111] Fix | Delete
[112] Fix | Delete
# Split a path in root and extension.
[113] Fix | Delete
# The extension is everything starting at the last dot in the last
[114] Fix | Delete
# pathname component; the root is everything before that.
[115] Fix | Delete
# It is always true that root + ext == p.
[116] Fix | Delete
[117] Fix | Delete
# Generic implementation of splitext, to be parametrized with
[118] Fix | Delete
# the separators
[119] Fix | Delete
def _splitext(p, sep, altsep, extsep):
[120] Fix | Delete
"""Split the extension from a pathname.
[121] Fix | Delete
[122] Fix | Delete
Extension is everything from the last dot to the end, ignoring
[123] Fix | Delete
leading dots. Returns "(root, ext)"; ext may be empty."""
[124] Fix | Delete
# NOTE: This code must work for text and bytes strings.
[125] Fix | Delete
[126] Fix | Delete
sepIndex = p.rfind(sep)
[127] Fix | Delete
if altsep:
[128] Fix | Delete
altsepIndex = p.rfind(altsep)
[129] Fix | Delete
sepIndex = max(sepIndex, altsepIndex)
[130] Fix | Delete
[131] Fix | Delete
dotIndex = p.rfind(extsep)
[132] Fix | Delete
if dotIndex > sepIndex:
[133] Fix | Delete
# skip all leading dots
[134] Fix | Delete
filenameIndex = sepIndex + 1
[135] Fix | Delete
while filenameIndex < dotIndex:
[136] Fix | Delete
if p[filenameIndex:filenameIndex+1] != extsep:
[137] Fix | Delete
return p[:dotIndex], p[dotIndex:]
[138] Fix | Delete
filenameIndex += 1
[139] Fix | Delete
[140] Fix | Delete
return p, p[:0]
[141] Fix | Delete
[142] Fix | Delete
def _check_arg_types(funcname, *args):
[143] Fix | Delete
hasstr = hasbytes = False
[144] Fix | Delete
for s in args:
[145] Fix | Delete
if isinstance(s, str):
[146] Fix | Delete
hasstr = True
[147] Fix | Delete
elif isinstance(s, bytes):
[148] Fix | Delete
hasbytes = True
[149] Fix | Delete
else:
[150] Fix | Delete
raise TypeError(f'{funcname}() argument must be str, bytes, or '
[151] Fix | Delete
f'os.PathLike object, not {s.__class__.__name__!r}') from None
[152] Fix | Delete
if hasstr and hasbytes:
[153] Fix | Delete
raise TypeError("Can't mix strings and bytes in path components") from None
[154] Fix | Delete
[155] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function