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