Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/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:
[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:
[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:
[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"""
[94] Fix | Delete
s1 = os.stat(f1)
[95] Fix | Delete
s2 = os.stat(f2)
[96] Fix | Delete
return samestat(s1, s2)
[97] Fix | Delete
[98] Fix | Delete
[99] Fix | Delete
# Are two open files really referencing the same file?
[100] Fix | Delete
# (Not necessarily the same file descriptor!)
[101] Fix | Delete
def sameopenfile(fp1, fp2):
[102] Fix | Delete
"""Test whether two open file objects reference the same file"""
[103] Fix | Delete
s1 = os.fstat(fp1)
[104] Fix | Delete
s2 = os.fstat(fp2)
[105] Fix | Delete
return samestat(s1, s2)
[106] Fix | Delete
[107] Fix | Delete
[108] Fix | Delete
# Split a path in root and extension.
[109] Fix | Delete
# The extension is everything starting at the last dot in the last
[110] Fix | Delete
# pathname component; the root is everything before that.
[111] Fix | Delete
# It is always true that root + ext == p.
[112] Fix | Delete
[113] Fix | Delete
# Generic implementation of splitext, to be parametrized with
[114] Fix | Delete
# the separators
[115] Fix | Delete
def _splitext(p, sep, altsep, extsep):
[116] Fix | Delete
"""Split the extension from a pathname.
[117] Fix | Delete
[118] Fix | Delete
Extension is everything from the last dot to the end, ignoring
[119] Fix | Delete
leading dots. Returns "(root, ext)"; ext may be empty."""
[120] Fix | Delete
# NOTE: This code must work for text and bytes strings.
[121] Fix | Delete
[122] Fix | Delete
sepIndex = p.rfind(sep)
[123] Fix | Delete
if altsep:
[124] Fix | Delete
altsepIndex = p.rfind(altsep)
[125] Fix | Delete
sepIndex = max(sepIndex, altsepIndex)
[126] Fix | Delete
[127] Fix | Delete
dotIndex = p.rfind(extsep)
[128] Fix | Delete
if dotIndex > sepIndex:
[129] Fix | Delete
# skip all leading dots
[130] Fix | Delete
filenameIndex = sepIndex + 1
[131] Fix | Delete
while filenameIndex < dotIndex:
[132] Fix | Delete
if p[filenameIndex:filenameIndex+1] != extsep:
[133] Fix | Delete
return p[:dotIndex], p[dotIndex:]
[134] Fix | Delete
filenameIndex += 1
[135] Fix | Delete
[136] Fix | Delete
return p, p[:0]
[137] Fix | Delete
[138] Fix | Delete
def _check_arg_types(funcname, *args):
[139] Fix | Delete
hasstr = hasbytes = False
[140] Fix | Delete
for s in args:
[141] Fix | Delete
if isinstance(s, str):
[142] Fix | Delete
hasstr = True
[143] Fix | Delete
elif isinstance(s, bytes):
[144] Fix | Delete
hasbytes = True
[145] Fix | Delete
else:
[146] Fix | Delete
raise TypeError('%s() argument must be str or bytes, not %r' %
[147] Fix | Delete
(funcname, s.__class__.__name__)) from None
[148] Fix | Delete
if hasstr and hasbytes:
[149] Fix | Delete
raise TypeError("Can't mix strings and bytes in path components") from None
[150] Fix | Delete
[151] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function