/opt/alt/python311/lib64/python3.11
""" Path operations common to more than one OS Do not use directly. The OS specific modules import the appropriate functions from this module themselves. """ import os import stat __all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime', 'getsize', 'isdir', 'isfile', 'samefile', 'sameopenfile', 'samestat', 'ALLOW_MISSING'] # Does a path exist? # This is false for dangling symbolic links on systems that support them. def exists(path): """Test whether a path exists. Returns False for broken symbolic links""" try: os.stat(path) except (OSError, ValueError): return False return True # This follows symbolic links, so both islink() and isdir() can be true # for the same path on systems that support symlinks def isfile(path): """Test whether a path is a regular file""" try: st = os.stat(path) except (OSError, ValueError): return False return stat.S_ISREG(st.st_mode) # Is a path a directory? # This follows symbolic links, so both islink() and isdir() # can be true for the same path on systems that support symlinks def isdir(s): """Return true if the pathname refers to an existing directory.""" try: st = os.stat(s) except (OSError, ValueError): return False return stat.S_ISDIR(st.st_mode) def getsize(filename): """Return the size of a file, reported by os.stat().""" return os.stat(filename).st_size def getmtime(filename): """Return the last modification time of a file, reported by os.stat().""" return os.stat(filename).st_mtime def getatime(filename): """Return the last access time of a file, reported by os.stat().""" return os.stat(filename).st_atime def getctime(filename): """Return the metadata change time of a file, reported by os.stat().""" return os.stat(filename).st_ctime # Return the longest prefix of all list elements. def commonprefix(m): "Given a list of pathnames, returns the longest common leading component" if not m: return '' # Some people pass in a list of pathname parts to operate in an OS-agnostic # fashion; don't try to translate in that case as that's an abuse of the # API and they are already doing what they need to be OS-agnostic and so # they most likely won't be using an os.PathLike object in the sublists. if not isinstance(m[0], (list, tuple)): m = tuple(map(os.fspath, m)) s1 = min(m) s2 = max(m) for i, c in enumerate(s1): if c != s2[i]: return s1[:i] return s1 # Are two stat buffers (obtained from stat, fstat or lstat) # describing the same file? def samestat(s1, s2): """Test whether two stat buffers reference the same file""" return (s1.st_ino == s2.st_ino and s1.st_dev == s2.st_dev) # Are two filenames really pointing to the same file? def samefile(f1, f2): """Test whether two pathnames reference the same actual file or directory This is determined by the device number and i-node number and raises an exception if an os.stat() call on either pathname fails. """ s1 = os.stat(f1) s2 = os.stat(f2) return samestat(s1, s2) # Are two open files really referencing the same file? # (Not necessarily the same file descriptor!) def sameopenfile(fp1, fp2): """Test whether two open file objects reference the same file""" s1 = os.fstat(fp1) s2 = os.fstat(fp2) return samestat(s1, s2) # Split a path in root and extension. # The extension is everything starting at the last dot in the last # pathname component; the root is everything before that. # It is always true that root + ext == p. # Generic implementation of splitext, to be parametrized with # the separators def _splitext(p, sep, altsep, extsep): """Split the extension from a pathname. Extension is everything from the last dot to the end, ignoring leading dots. Returns "(root, ext)"; ext may be empty.""" # NOTE: This code must work for text and bytes strings. sepIndex = p.rfind(sep) if altsep: altsepIndex = p.rfind(altsep) sepIndex = max(sepIndex, altsepIndex) dotIndex = p.rfind(extsep) if dotIndex > sepIndex: # skip all leading dots filenameIndex = sepIndex + 1 while filenameIndex < dotIndex: if p[filenameIndex:filenameIndex+1] != extsep: return p[:dotIndex], p[dotIndex:] filenameIndex += 1 return p, p[:0] def _check_arg_types(funcname, *args): hasstr = hasbytes = False for s in args: if isinstance(s, str): hasstr = True elif isinstance(s, bytes): hasbytes = True else: raise TypeError(f'{funcname}() argument must be str, bytes, or ' f'os.PathLike object, not {s.__class__.__name__!r}') from None if hasstr and hasbytes: raise TypeError("Can't mix strings and bytes in path components") from None # A singleton with a true boolean value. @object.__new__ class ALLOW_MISSING: """Special value for use in realpath().""" def __repr__(self): return 'os.path.ALLOW_MISSING' def __reduce__(self): return self.__class__.__name__
.
Edit
..
Edit
LICENSE.txt
Edit
__future__.py
Edit
__hello__.py
Edit
__pycache__
Edit
_aix_support.py
Edit
_bootsubprocess.py
Edit
_collections_abc.py
Edit
_compat_pickle.py
Edit
_compression.py
Edit
_markupbase.py
Edit
_osx_support.py
Edit
_py_abc.py
Edit
_pydecimal.py
Edit
_pyio.py
Edit
_sitebuiltins.py
Edit
_strptime.py
Edit
_sysconfigdata__linux_x86_64-linux-gnu.py
Edit
_sysconfigdata_d_linux_x86_64-linux-gnu.py
Edit
_threading_local.py
Edit
_weakrefset.py
Edit
abc.py
Edit
aifc.py
Edit
antigravity.py
Edit
argparse.py
Edit
ast.py
Edit
asynchat.py
Edit
asyncio
Edit
asyncore.py
Edit
base64.py
Edit
bdb.py
Edit
bisect.py
Edit
bz2.py
Edit
cProfile.py
Edit
calendar.py
Edit
cgi.py
Edit
cgitb.py
Edit
chunk.py
Edit
cmd.py
Edit
code.py
Edit
codecs.py
Edit
codeop.py
Edit
collections
Edit
colorsys.py
Edit
compileall.py
Edit
concurrent
Edit
config-3.11-x86_64-linux-gnu
Edit
configparser.py
Edit
contextlib.py
Edit
contextvars.py
Edit
copy.py
Edit
copyreg.py
Edit
crypt.py
Edit
csv.py
Edit
ctypes
Edit
curses
Edit
dataclasses.py
Edit
datetime.py
Edit
dbm
Edit
decimal.py
Edit
difflib.py
Edit
dis.py
Edit
distutils
Edit
doctest.py
Edit
email
Edit
encodings
Edit
ensurepip
Edit
enum.py
Edit
filecmp.py
Edit
fileinput.py
Edit
fnmatch.py
Edit
fractions.py
Edit
ftplib.py
Edit
functools.py
Edit
genericpath.py
Edit
getopt.py
Edit
getpass.py
Edit
gettext.py
Edit
glob.py
Edit
graphlib.py
Edit
gzip.py
Edit
hashlib.py
Edit
heapq.py
Edit
hmac.py
Edit
html
Edit
http
Edit
imaplib.py
Edit
imghdr.py
Edit
imp.py
Edit
importlib
Edit
inspect.py
Edit
io.py
Edit
ipaddress.py
Edit
json
Edit
keyword.py
Edit
lib-dynload
Edit
lib2to3
Edit
linecache.py
Edit
locale.py
Edit
logging
Edit
lzma.py
Edit
mailbox.py
Edit
mailcap.py
Edit
mimetypes.py
Edit
modulefinder.py
Edit
multiprocessing
Edit
netrc.py
Edit
nntplib.py
Edit
ntpath.py
Edit
nturl2path.py
Edit
numbers.py
Edit
opcode.py
Edit
operator.py
Edit
optparse.py
Edit
os.py
Edit
pathlib.py
Edit
pdb.py
Edit
pickle.py
Edit
pickletools.py
Edit
pipes.py
Edit
pkgutil.py
Edit
platform.py
Edit
plistlib.py
Edit
poplib.py
Edit
posixpath.py
Edit
pprint.py
Edit
profile.py
Edit
pstats.py
Edit
pty.py
Edit
py_compile.py
Edit
pyclbr.py
Edit
pydoc.py
Edit
pydoc_data
Edit
queue.py
Edit
quopri.py
Edit
random.py
Edit
re
Edit
reprlib.py
Edit
rlcompleter.py
Edit
runpy.py
Edit
sched.py
Edit
secrets.py
Edit
selectors.py
Edit
shelve.py
Edit
shlex.py
Edit
shutil.py
Edit
signal.py
Edit
site-packages
Edit
site.py
Edit
smtpd.py
Edit
smtplib.py
Edit
sndhdr.py
Edit
socket.py
Edit
socketserver.py
Edit
sqlite3
Edit
sre_compile.py
Edit
sre_constants.py
Edit
sre_parse.py
Edit
ssl.py
Edit
stat.py
Edit
statistics.py
Edit
string.py
Edit
stringprep.py
Edit
struct.py
Edit
subprocess.py
Edit
sunau.py
Edit
symtable.py
Edit
sysconfig.py
Edit
tabnanny.py
Edit
tarfile.py
Edit
telnetlib.py
Edit
tempfile.py
Edit
textwrap.py
Edit
this.py
Edit
threading.py
Edit
timeit.py
Edit
token.py
Edit
tokenize.py
Edit
tomllib
Edit
trace.py
Edit
traceback.py
Edit
tracemalloc.py
Edit
tty.py
Edit
types.py
Edit
typing.py
Edit
unittest
Edit
urllib
Edit
uu.py
Edit
uuid.py
Edit
venv
Edit
warnings.py
Edit
wave.py
Edit
weakref.py
Edit
webbrowser.py
Edit
wsgiref
Edit
xdrlib.py
Edit
xml
Edit
xmlrpc
Edit
zipapp.py
Edit
zipfile.py
Edit
zipimport.py
Edit
zoneinfo
Edit