def translate(self, pattern): """
Given a glob pattern, produce a regex that matches it. """ return self.extend(self.match_dirs(self.translate_core(pattern)))
def extend(self, pattern):
r"""
Extend regex for pattern-wide concerns.
Apply '(?s:)' to create a non-matching group that
matches newlines (valid on Unix).
Append '\Z' to imply fullmatch even when match is used. """ return rf'(?s:{pattern})\Z'
def match_dirs(self, pattern): """
Ensure that zipfile.Path directory names are matched.
zipfile.Path directory names always end in a slash. """ return rf'{pattern}[/]?'
def translate_core(self, pattern):
r"""
Given a glob pattern, produce a regex that matches it.
def replace(self, match): """
Perform the replacements for a match from :func:`separate`. """ return match.group('set') or (
re.escape(match.group(0))
.replace('\\*\\*', r'.*')
.replace('\\*', rf'[^{re.escape(self.seps)}]*')
.replace('\\?', r'[^/]')
)
def restrict_rglob(self, pattern): """ Raise ValueError if ** appears in anything but a full path segment.
>>> Translator().translate('**foo')
Traceback (most recent call last):
...
ValueError: ** must appear alone in a path segment """
seps_pattern = rf'[{re.escape(self.seps)}]+'
segments = re.split(seps_pattern, pattern) if any('**'in segment and segment != '**'for segment in segments): raise ValueError("** must appear alone in a path segment")
def star_not_empty(self, pattern): """
Ensure that * will not match an empty segment. """
def separate(pattern): """
Separate out character sets to avoid translating their contents.
>>> [m.group(0) for m in separate('*.txt')]
['*.txt']
>>> [m.group(0) for m in separate('a[?]txt')]
['a', '[?]', 'txt'] """ return re.finditer(r'([^\[]+)|(?P[\[].*?[\]])|([\[][^\]]*$)', pattern)
Messung V0.5
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.