Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: pathlib.py
import fnmatch
[0] Fix | Delete
import functools
[1] Fix | Delete
import io
[2] Fix | Delete
import ntpath
[3] Fix | Delete
import os
[4] Fix | Delete
import posixpath
[5] Fix | Delete
import re
[6] Fix | Delete
import sys
[7] Fix | Delete
from collections import Sequence
[8] Fix | Delete
from contextlib import contextmanager
[9] Fix | Delete
from errno import EINVAL, ENOENT, ENOTDIR
[10] Fix | Delete
from operator import attrgetter
[11] Fix | Delete
from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
[12] Fix | Delete
from urllib.parse import quote_from_bytes as urlquote_from_bytes
[13] Fix | Delete
[14] Fix | Delete
[15] Fix | Delete
supports_symlinks = True
[16] Fix | Delete
if os.name == 'nt':
[17] Fix | Delete
import nt
[18] Fix | Delete
if sys.getwindowsversion()[:2] >= (6, 0):
[19] Fix | Delete
from nt import _getfinalpathname
[20] Fix | Delete
else:
[21] Fix | Delete
supports_symlinks = False
[22] Fix | Delete
_getfinalpathname = None
[23] Fix | Delete
else:
[24] Fix | Delete
nt = None
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
__all__ = [
[28] Fix | Delete
"PurePath", "PurePosixPath", "PureWindowsPath",
[29] Fix | Delete
"Path", "PosixPath", "WindowsPath",
[30] Fix | Delete
]
[31] Fix | Delete
[32] Fix | Delete
#
[33] Fix | Delete
# Internals
[34] Fix | Delete
#
[35] Fix | Delete
[36] Fix | Delete
def _is_wildcard_pattern(pat):
[37] Fix | Delete
# Whether this pattern needs actual matching using fnmatch, or can
[38] Fix | Delete
# be looked up directly as a file.
[39] Fix | Delete
return "*" in pat or "?" in pat or "[" in pat
[40] Fix | Delete
[41] Fix | Delete
[42] Fix | Delete
class _Flavour(object):
[43] Fix | Delete
"""A flavour implements a particular (platform-specific) set of path
[44] Fix | Delete
semantics."""
[45] Fix | Delete
[46] Fix | Delete
def __init__(self):
[47] Fix | Delete
self.join = self.sep.join
[48] Fix | Delete
[49] Fix | Delete
def parse_parts(self, parts):
[50] Fix | Delete
parsed = []
[51] Fix | Delete
sep = self.sep
[52] Fix | Delete
altsep = self.altsep
[53] Fix | Delete
drv = root = ''
[54] Fix | Delete
it = reversed(parts)
[55] Fix | Delete
for part in it:
[56] Fix | Delete
if not part:
[57] Fix | Delete
continue
[58] Fix | Delete
if altsep:
[59] Fix | Delete
part = part.replace(altsep, sep)
[60] Fix | Delete
drv, root, rel = self.splitroot(part)
[61] Fix | Delete
if sep in rel:
[62] Fix | Delete
for x in reversed(rel.split(sep)):
[63] Fix | Delete
if x and x != '.':
[64] Fix | Delete
parsed.append(sys.intern(x))
[65] Fix | Delete
else:
[66] Fix | Delete
if rel and rel != '.':
[67] Fix | Delete
parsed.append(sys.intern(rel))
[68] Fix | Delete
if drv or root:
[69] Fix | Delete
if not drv:
[70] Fix | Delete
# If no drive is present, try to find one in the previous
[71] Fix | Delete
# parts. This makes the result of parsing e.g.
[72] Fix | Delete
# ("C:", "/", "a") reasonably intuitive.
[73] Fix | Delete
for part in it:
[74] Fix | Delete
if not part:
[75] Fix | Delete
continue
[76] Fix | Delete
if altsep:
[77] Fix | Delete
part = part.replace(altsep, sep)
[78] Fix | Delete
drv = self.splitroot(part)[0]
[79] Fix | Delete
if drv:
[80] Fix | Delete
break
[81] Fix | Delete
break
[82] Fix | Delete
if drv or root:
[83] Fix | Delete
parsed.append(drv + root)
[84] Fix | Delete
parsed.reverse()
[85] Fix | Delete
return drv, root, parsed
[86] Fix | Delete
[87] Fix | Delete
def join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
[88] Fix | Delete
"""
[89] Fix | Delete
Join the two paths represented by the respective
[90] Fix | Delete
(drive, root, parts) tuples. Return a new (drive, root, parts) tuple.
[91] Fix | Delete
"""
[92] Fix | Delete
if root2:
[93] Fix | Delete
if not drv2 and drv:
[94] Fix | Delete
return drv, root2, [drv + root2] + parts2[1:]
[95] Fix | Delete
elif drv2:
[96] Fix | Delete
if drv2 == drv or self.casefold(drv2) == self.casefold(drv):
[97] Fix | Delete
# Same drive => second path is relative to the first
[98] Fix | Delete
return drv, root, parts + parts2[1:]
[99] Fix | Delete
else:
[100] Fix | Delete
# Second path is non-anchored (common case)
[101] Fix | Delete
return drv, root, parts + parts2
[102] Fix | Delete
return drv2, root2, parts2
[103] Fix | Delete
[104] Fix | Delete
[105] Fix | Delete
class _WindowsFlavour(_Flavour):
[106] Fix | Delete
# Reference for Windows paths can be found at
[107] Fix | Delete
# http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
[108] Fix | Delete
[109] Fix | Delete
sep = '\\'
[110] Fix | Delete
altsep = '/'
[111] Fix | Delete
has_drv = True
[112] Fix | Delete
pathmod = ntpath
[113] Fix | Delete
[114] Fix | Delete
is_supported = (os.name == 'nt')
[115] Fix | Delete
[116] Fix | Delete
drive_letters = (
[117] Fix | Delete
set(chr(x) for x in range(ord('a'), ord('z') + 1)) |
[118] Fix | Delete
set(chr(x) for x in range(ord('A'), ord('Z') + 1))
[119] Fix | Delete
)
[120] Fix | Delete
ext_namespace_prefix = '\\\\?\\'
[121] Fix | Delete
[122] Fix | Delete
reserved_names = (
[123] Fix | Delete
{'CON', 'PRN', 'AUX', 'NUL'} |
[124] Fix | Delete
{'COM%d' % i for i in range(1, 10)} |
[125] Fix | Delete
{'LPT%d' % i for i in range(1, 10)}
[126] Fix | Delete
)
[127] Fix | Delete
[128] Fix | Delete
# Interesting findings about extended paths:
[129] Fix | Delete
# - '\\?\c:\a', '//?/c:\a' and '//?/c:/a' are all supported
[130] Fix | Delete
# but '\\?\c:/a' is not
[131] Fix | Delete
# - extended paths are always absolute; "relative" extended paths will
[132] Fix | Delete
# fail.
[133] Fix | Delete
[134] Fix | Delete
def splitroot(self, part, sep=sep):
[135] Fix | Delete
first = part[0:1]
[136] Fix | Delete
second = part[1:2]
[137] Fix | Delete
if (second == sep and first == sep):
[138] Fix | Delete
# XXX extended paths should also disable the collapsing of "."
[139] Fix | Delete
# components (according to MSDN docs).
[140] Fix | Delete
prefix, part = self._split_extended_path(part)
[141] Fix | Delete
first = part[0:1]
[142] Fix | Delete
second = part[1:2]
[143] Fix | Delete
else:
[144] Fix | Delete
prefix = ''
[145] Fix | Delete
third = part[2:3]
[146] Fix | Delete
if (second == sep and first == sep and third != sep):
[147] Fix | Delete
# is a UNC path:
[148] Fix | Delete
# vvvvvvvvvvvvvvvvvvvvv root
[149] Fix | Delete
# \\machine\mountpoint\directory\etc\...
[150] Fix | Delete
# directory ^^^^^^^^^^^^^^
[151] Fix | Delete
index = part.find(sep, 2)
[152] Fix | Delete
if index != -1:
[153] Fix | Delete
index2 = part.find(sep, index + 1)
[154] Fix | Delete
# a UNC path can't have two slashes in a row
[155] Fix | Delete
# (after the initial two)
[156] Fix | Delete
if index2 != index + 1:
[157] Fix | Delete
if index2 == -1:
[158] Fix | Delete
index2 = len(part)
[159] Fix | Delete
if prefix:
[160] Fix | Delete
return prefix + part[1:index2], sep, part[index2+1:]
[161] Fix | Delete
else:
[162] Fix | Delete
return part[:index2], sep, part[index2+1:]
[163] Fix | Delete
drv = root = ''
[164] Fix | Delete
if second == ':' and first in self.drive_letters:
[165] Fix | Delete
drv = part[:2]
[166] Fix | Delete
part = part[2:]
[167] Fix | Delete
first = third
[168] Fix | Delete
if first == sep:
[169] Fix | Delete
root = first
[170] Fix | Delete
part = part.lstrip(sep)
[171] Fix | Delete
return prefix + drv, root, part
[172] Fix | Delete
[173] Fix | Delete
def casefold(self, s):
[174] Fix | Delete
return s.lower()
[175] Fix | Delete
[176] Fix | Delete
def casefold_parts(self, parts):
[177] Fix | Delete
return [p.lower() for p in parts]
[178] Fix | Delete
[179] Fix | Delete
def resolve(self, path, strict=False):
[180] Fix | Delete
s = str(path)
[181] Fix | Delete
if not s:
[182] Fix | Delete
return os.getcwd()
[183] Fix | Delete
previous_s = None
[184] Fix | Delete
if _getfinalpathname is not None:
[185] Fix | Delete
if strict:
[186] Fix | Delete
return self._ext_to_normal(_getfinalpathname(s))
[187] Fix | Delete
else:
[188] Fix | Delete
tail_parts = [] # End of the path after the first one not found
[189] Fix | Delete
while True:
[190] Fix | Delete
try:
[191] Fix | Delete
s = self._ext_to_normal(_getfinalpathname(s))
[192] Fix | Delete
except FileNotFoundError:
[193] Fix | Delete
previous_s = s
[194] Fix | Delete
s, tail = os.path.split(s)
[195] Fix | Delete
tail_parts.append(tail)
[196] Fix | Delete
if previous_s == s:
[197] Fix | Delete
return path
[198] Fix | Delete
else:
[199] Fix | Delete
return os.path.join(s, *reversed(tail_parts))
[200] Fix | Delete
# Means fallback on absolute
[201] Fix | Delete
return None
[202] Fix | Delete
[203] Fix | Delete
def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
[204] Fix | Delete
prefix = ''
[205] Fix | Delete
if s.startswith(ext_prefix):
[206] Fix | Delete
prefix = s[:4]
[207] Fix | Delete
s = s[4:]
[208] Fix | Delete
if s.startswith('UNC\\'):
[209] Fix | Delete
prefix += s[:3]
[210] Fix | Delete
s = '\\' + s[3:]
[211] Fix | Delete
return prefix, s
[212] Fix | Delete
[213] Fix | Delete
def _ext_to_normal(self, s):
[214] Fix | Delete
# Turn back an extended path into a normal DOS-like path
[215] Fix | Delete
return self._split_extended_path(s)[1]
[216] Fix | Delete
[217] Fix | Delete
def is_reserved(self, parts):
[218] Fix | Delete
# NOTE: the rules for reserved names seem somewhat complicated
[219] Fix | Delete
# (e.g. r"..\NUL" is reserved but not r"foo\NUL").
[220] Fix | Delete
# We err on the side of caution and return True for paths which are
[221] Fix | Delete
# not considered reserved by Windows.
[222] Fix | Delete
if not parts:
[223] Fix | Delete
return False
[224] Fix | Delete
if parts[0].startswith('\\\\'):
[225] Fix | Delete
# UNC paths are never reserved
[226] Fix | Delete
return False
[227] Fix | Delete
return parts[-1].partition('.')[0].upper() in self.reserved_names
[228] Fix | Delete
[229] Fix | Delete
def make_uri(self, path):
[230] Fix | Delete
# Under Windows, file URIs use the UTF-8 encoding.
[231] Fix | Delete
drive = path.drive
[232] Fix | Delete
if len(drive) == 2 and drive[1] == ':':
[233] Fix | Delete
# It's a path on a local drive => 'file:///c:/a/b'
[234] Fix | Delete
rest = path.as_posix()[2:].lstrip('/')
[235] Fix | Delete
return 'file:///%s/%s' % (
[236] Fix | Delete
drive, urlquote_from_bytes(rest.encode('utf-8')))
[237] Fix | Delete
else:
[238] Fix | Delete
# It's a path on a network drive => 'file://host/share/a/b'
[239] Fix | Delete
return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8'))
[240] Fix | Delete
[241] Fix | Delete
def gethomedir(self, username):
[242] Fix | Delete
if 'HOME' in os.environ:
[243] Fix | Delete
userhome = os.environ['HOME']
[244] Fix | Delete
elif 'USERPROFILE' in os.environ:
[245] Fix | Delete
userhome = os.environ['USERPROFILE']
[246] Fix | Delete
elif 'HOMEPATH' in os.environ:
[247] Fix | Delete
try:
[248] Fix | Delete
drv = os.environ['HOMEDRIVE']
[249] Fix | Delete
except KeyError:
[250] Fix | Delete
drv = ''
[251] Fix | Delete
userhome = drv + os.environ['HOMEPATH']
[252] Fix | Delete
else:
[253] Fix | Delete
raise RuntimeError("Can't determine home directory")
[254] Fix | Delete
[255] Fix | Delete
if username:
[256] Fix | Delete
# Try to guess user home directory. By default all users
[257] Fix | Delete
# directories are located in the same place and are named by
[258] Fix | Delete
# corresponding usernames. If current user home directory points
[259] Fix | Delete
# to nonstandard place, this guess is likely wrong.
[260] Fix | Delete
if os.environ['USERNAME'] != username:
[261] Fix | Delete
drv, root, parts = self.parse_parts((userhome,))
[262] Fix | Delete
if parts[-1] != os.environ['USERNAME']:
[263] Fix | Delete
raise RuntimeError("Can't determine home directory "
[264] Fix | Delete
"for %r" % username)
[265] Fix | Delete
parts[-1] = username
[266] Fix | Delete
if drv or root:
[267] Fix | Delete
userhome = drv + root + self.join(parts[1:])
[268] Fix | Delete
else:
[269] Fix | Delete
userhome = self.join(parts)
[270] Fix | Delete
return userhome
[271] Fix | Delete
[272] Fix | Delete
class _PosixFlavour(_Flavour):
[273] Fix | Delete
sep = '/'
[274] Fix | Delete
altsep = ''
[275] Fix | Delete
has_drv = False
[276] Fix | Delete
pathmod = posixpath
[277] Fix | Delete
[278] Fix | Delete
is_supported = (os.name != 'nt')
[279] Fix | Delete
[280] Fix | Delete
def splitroot(self, part, sep=sep):
[281] Fix | Delete
if part and part[0] == sep:
[282] Fix | Delete
stripped_part = part.lstrip(sep)
[283] Fix | Delete
# According to POSIX path resolution:
[284] Fix | Delete
# http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11
[285] Fix | Delete
# "A pathname that begins with two successive slashes may be
[286] Fix | Delete
# interpreted in an implementation-defined manner, although more
[287] Fix | Delete
# than two leading slashes shall be treated as a single slash".
[288] Fix | Delete
if len(part) - len(stripped_part) == 2:
[289] Fix | Delete
return '', sep * 2, stripped_part
[290] Fix | Delete
else:
[291] Fix | Delete
return '', sep, stripped_part
[292] Fix | Delete
else:
[293] Fix | Delete
return '', '', part
[294] Fix | Delete
[295] Fix | Delete
def casefold(self, s):
[296] Fix | Delete
return s
[297] Fix | Delete
[298] Fix | Delete
def casefold_parts(self, parts):
[299] Fix | Delete
return parts
[300] Fix | Delete
[301] Fix | Delete
def resolve(self, path, strict=False):
[302] Fix | Delete
sep = self.sep
[303] Fix | Delete
accessor = path._accessor
[304] Fix | Delete
seen = {}
[305] Fix | Delete
def _resolve(path, rest):
[306] Fix | Delete
if rest.startswith(sep):
[307] Fix | Delete
path = ''
[308] Fix | Delete
[309] Fix | Delete
for name in rest.split(sep):
[310] Fix | Delete
if not name or name == '.':
[311] Fix | Delete
# current dir
[312] Fix | Delete
continue
[313] Fix | Delete
if name == '..':
[314] Fix | Delete
# parent dir
[315] Fix | Delete
path, _, _ = path.rpartition(sep)
[316] Fix | Delete
continue
[317] Fix | Delete
newpath = path + sep + name
[318] Fix | Delete
if newpath in seen:
[319] Fix | Delete
# Already seen this path
[320] Fix | Delete
path = seen[newpath]
[321] Fix | Delete
if path is not None:
[322] Fix | Delete
# use cached value
[323] Fix | Delete
continue
[324] Fix | Delete
# The symlink is not resolved, so we must have a symlink loop.
[325] Fix | Delete
raise RuntimeError("Symlink loop from %r" % newpath)
[326] Fix | Delete
# Resolve the symbolic link
[327] Fix | Delete
try:
[328] Fix | Delete
target = accessor.readlink(newpath)
[329] Fix | Delete
except OSError as e:
[330] Fix | Delete
if e.errno != EINVAL and strict:
[331] Fix | Delete
raise
[332] Fix | Delete
# Not a symlink, or non-strict mode. We just leave the path
[333] Fix | Delete
# untouched.
[334] Fix | Delete
path = newpath
[335] Fix | Delete
else:
[336] Fix | Delete
seen[newpath] = None # not resolved symlink
[337] Fix | Delete
path = _resolve(path, target)
[338] Fix | Delete
seen[newpath] = path # resolved symlink
[339] Fix | Delete
[340] Fix | Delete
return path
[341] Fix | Delete
# NOTE: according to POSIX, getcwd() cannot contain path components
[342] Fix | Delete
# which are symlinks.
[343] Fix | Delete
base = '' if path.is_absolute() else os.getcwd()
[344] Fix | Delete
return _resolve(base, str(path)) or sep
[345] Fix | Delete
[346] Fix | Delete
def is_reserved(self, parts):
[347] Fix | Delete
return False
[348] Fix | Delete
[349] Fix | Delete
def make_uri(self, path):
[350] Fix | Delete
# We represent the path using the local filesystem encoding,
[351] Fix | Delete
# for portability to other applications.
[352] Fix | Delete
bpath = bytes(path)
[353] Fix | Delete
return 'file://' + urlquote_from_bytes(bpath)
[354] Fix | Delete
[355] Fix | Delete
def gethomedir(self, username):
[356] Fix | Delete
if not username:
[357] Fix | Delete
try:
[358] Fix | Delete
return os.environ['HOME']
[359] Fix | Delete
except KeyError:
[360] Fix | Delete
import pwd
[361] Fix | Delete
return pwd.getpwuid(os.getuid()).pw_dir
[362] Fix | Delete
else:
[363] Fix | Delete
import pwd
[364] Fix | Delete
try:
[365] Fix | Delete
return pwd.getpwnam(username).pw_dir
[366] Fix | Delete
except KeyError:
[367] Fix | Delete
raise RuntimeError("Can't determine home directory "
[368] Fix | Delete
"for %r" % username)
[369] Fix | Delete
[370] Fix | Delete
[371] Fix | Delete
_windows_flavour = _WindowsFlavour()
[372] Fix | Delete
_posix_flavour = _PosixFlavour()
[373] Fix | Delete
[374] Fix | Delete
[375] Fix | Delete
class _Accessor:
[376] Fix | Delete
"""An accessor implements a particular (system-specific or not) way of
[377] Fix | Delete
accessing paths on the filesystem."""
[378] Fix | Delete
[379] Fix | Delete
[380] Fix | Delete
class _NormalAccessor(_Accessor):
[381] Fix | Delete
[382] Fix | Delete
def _wrap_strfunc(strfunc):
[383] Fix | Delete
@functools.wraps(strfunc)
[384] Fix | Delete
def wrapped(pathobj, *args):
[385] Fix | Delete
return strfunc(str(pathobj), *args)
[386] Fix | Delete
return staticmethod(wrapped)
[387] Fix | Delete
[388] Fix | Delete
def _wrap_binary_strfunc(strfunc):
[389] Fix | Delete
@functools.wraps(strfunc)
[390] Fix | Delete
def wrapped(pathobjA, pathobjB, *args):
[391] Fix | Delete
return strfunc(str(pathobjA), str(pathobjB), *args)
[392] Fix | Delete
return staticmethod(wrapped)
[393] Fix | Delete
[394] Fix | Delete
stat = _wrap_strfunc(os.stat)
[395] Fix | Delete
[396] Fix | Delete
lstat = _wrap_strfunc(os.lstat)
[397] Fix | Delete
[398] Fix | Delete
open = _wrap_strfunc(os.open)
[399] Fix | Delete
[400] Fix | Delete
listdir = _wrap_strfunc(os.listdir)
[401] Fix | Delete
[402] Fix | Delete
scandir = _wrap_strfunc(os.scandir)
[403] Fix | Delete
[404] Fix | Delete
chmod = _wrap_strfunc(os.chmod)
[405] Fix | Delete
[406] Fix | Delete
if hasattr(os, "lchmod"):
[407] Fix | Delete
lchmod = _wrap_strfunc(os.lchmod)
[408] Fix | Delete
else:
[409] Fix | Delete
def lchmod(self, pathobj, mode):
[410] Fix | Delete
raise NotImplementedError("lchmod() not available on this system")
[411] Fix | Delete
[412] Fix | Delete
mkdir = _wrap_strfunc(os.mkdir)
[413] Fix | Delete
[414] Fix | Delete
unlink = _wrap_strfunc(os.unlink)
[415] Fix | Delete
[416] Fix | Delete
rmdir = _wrap_strfunc(os.rmdir)
[417] Fix | Delete
[418] Fix | Delete
rename = _wrap_binary_strfunc(os.rename)
[419] Fix | Delete
[420] Fix | Delete
replace = _wrap_binary_strfunc(os.replace)
[421] Fix | Delete
[422] Fix | Delete
if nt:
[423] Fix | Delete
if supports_symlinks:
[424] Fix | Delete
symlink = _wrap_binary_strfunc(os.symlink)
[425] Fix | Delete
else:
[426] Fix | Delete
def symlink(a, b, target_is_directory):
[427] Fix | Delete
raise NotImplementedError("symlink() not available on this system")
[428] Fix | Delete
else:
[429] Fix | Delete
# Under POSIX, os.symlink() takes two args
[430] Fix | Delete
@staticmethod
[431] Fix | Delete
def symlink(a, b, target_is_directory):
[432] Fix | Delete
return os.symlink(str(a), str(b))
[433] Fix | Delete
[434] Fix | Delete
utime = _wrap_strfunc(os.utime)
[435] Fix | Delete
[436] Fix | Delete
# Helper for resolve()
[437] Fix | Delete
def readlink(self, path):
[438] Fix | Delete
return os.readlink(path)
[439] Fix | Delete
[440] Fix | Delete
[441] Fix | Delete
_normal_accessor = _NormalAccessor()
[442] Fix | Delete
[443] Fix | Delete
[444] Fix | Delete
#
[445] Fix | Delete
# Globbing helpers
[446] Fix | Delete
#
[447] Fix | Delete
[448] Fix | Delete
def _make_selector(pattern_parts):
[449] Fix | Delete
pat = pattern_parts[0]
[450] Fix | Delete
child_parts = pattern_parts[1:]
[451] Fix | Delete
if pat == '**':
[452] Fix | Delete
cls = _RecursiveWildcardSelector
[453] Fix | Delete
elif '**' in pat:
[454] Fix | Delete
raise ValueError("Invalid pattern: '**' can only be an entire path component")
[455] Fix | Delete
elif _is_wildcard_pattern(pat):
[456] Fix | Delete
cls = _WildcardSelector
[457] Fix | Delete
else:
[458] Fix | Delete
cls = _PreciseSelector
[459] Fix | Delete
return cls(pat, child_parts)
[460] Fix | Delete
[461] Fix | Delete
if hasattr(functools, "lru_cache"):
[462] Fix | Delete
_make_selector = functools.lru_cache()(_make_selector)
[463] Fix | Delete
[464] Fix | Delete
[465] Fix | Delete
class _Selector:
[466] Fix | Delete
"""A selector matches a specific glob pattern part against the children
[467] Fix | Delete
of a given path."""
[468] Fix | Delete
[469] Fix | Delete
def __init__(self, child_parts):
[470] Fix | Delete
self.child_parts = child_parts
[471] Fix | Delete
if child_parts:
[472] Fix | Delete
self.successor = _make_selector(child_parts)
[473] Fix | Delete
self.dironly = True
[474] Fix | Delete
else:
[475] Fix | Delete
self.successor = _TerminatingSelector()
[476] Fix | Delete
self.dironly = False
[477] Fix | Delete
[478] Fix | Delete
def select_from(self, parent_path):
[479] Fix | Delete
"""Iterate over all child paths of `parent_path` matched by this
[480] Fix | Delete
selector. This can contain parent_path itself."""
[481] Fix | Delete
path_cls = type(parent_path)
[482] Fix | Delete
is_dir = path_cls.is_dir
[483] Fix | Delete
exists = path_cls.exists
[484] Fix | Delete
scandir = parent_path._accessor.scandir
[485] Fix | Delete
if not is_dir(parent_path):
[486] Fix | Delete
return iter([])
[487] Fix | Delete
return self._select_from(parent_path, is_dir, exists, scandir)
[488] Fix | Delete
[489] Fix | Delete
[490] Fix | Delete
class _TerminatingSelector:
[491] Fix | Delete
[492] Fix | Delete
def _select_from(self, parent_path, is_dir, exists, scandir):
[493] Fix | Delete
yield parent_path
[494] Fix | Delete
[495] Fix | Delete
[496] Fix | Delete
class _PreciseSelector(_Selector):
[497] Fix | Delete
[498] Fix | Delete
def __init__(self, name, child_parts):
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function