mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-06 05:01:14 -07:00
Bump pyparsing from 3.0.7 to 3.0.9 (#1741)
* Bump pyparsing from 3.0.7 to 3.0.9 Bumps [pyparsing](https://github.com/pyparsing/pyparsing) from 3.0.7 to 3.0.9. - [Release notes](https://github.com/pyparsing/pyparsing/releases) - [Changelog](https://github.com/pyparsing/pyparsing/blob/master/CHANGES) - [Commits](https://github.com/pyparsing/pyparsing/compare/pyparsing_3.0.7...pyparsing_3.0.9) --- updated-dependencies: - dependency-name: pyparsing dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Update pyparsing==3.0.9 Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
This commit is contained in:
parent
93b6370759
commit
d17015de44
12 changed files with 322 additions and 232 deletions
|
@ -2,9 +2,8 @@
|
|||
# core.py
|
||||
#
|
||||
import os
|
||||
import typing
|
||||
from typing import (
|
||||
Optional as OptionalType,
|
||||
Iterable as IterableType,
|
||||
NamedTuple,
|
||||
Union,
|
||||
Callable,
|
||||
|
@ -14,7 +13,6 @@ from typing import (
|
|||
List,
|
||||
TextIO,
|
||||
Set,
|
||||
Dict as DictType,
|
||||
Sequence,
|
||||
)
|
||||
from abc import ABC, abstractmethod
|
||||
|
@ -23,7 +21,6 @@ import string
|
|||
import copy
|
||||
import warnings
|
||||
import re
|
||||
import sre_constants
|
||||
import sys
|
||||
from collections.abc import Iterable
|
||||
import traceback
|
||||
|
@ -53,7 +50,7 @@ _MAX_INT = sys.maxsize
|
|||
str_type: Tuple[type, ...] = (str, bytes)
|
||||
|
||||
#
|
||||
# Copyright (c) 2003-2021 Paul T. McGuire
|
||||
# Copyright (c) 2003-2022 Paul T. McGuire
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
|
@ -76,6 +73,19 @@ str_type: Tuple[type, ...] = (str, bytes)
|
|||
#
|
||||
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from functools import cached_property
|
||||
else:
|
||||
|
||||
class cached_property:
|
||||
def __init__(self, func):
|
||||
self._func = func
|
||||
|
||||
def __get__(self, instance, owner=None):
|
||||
ret = instance.__dict__[self._func.__name__] = self._func(instance)
|
||||
return ret
|
||||
|
||||
|
||||
class __compat__(__config_flags):
|
||||
"""
|
||||
A cross-version compatibility configuration for pyparsing features that will be
|
||||
|
@ -180,7 +190,7 @@ del __config_flags
|
|||
|
||||
|
||||
def _should_enable_warnings(
|
||||
cmd_line_warn_options: IterableType[str], warn_env_var: OptionalType[str]
|
||||
cmd_line_warn_options: typing.Iterable[str], warn_env_var: typing.Optional[str]
|
||||
) -> bool:
|
||||
enable = bool(warn_env_var)
|
||||
for warn_opt in cmd_line_warn_options:
|
||||
|
@ -246,10 +256,10 @@ hexnums = nums + "ABCDEFabcdef"
|
|||
alphanums = alphas + nums
|
||||
printables = "".join([c for c in string.printable if c not in string.whitespace])
|
||||
|
||||
_trim_arity_call_line = None
|
||||
_trim_arity_call_line: traceback.StackSummary = None
|
||||
|
||||
|
||||
def _trim_arity(func, maxargs=2):
|
||||
def _trim_arity(func, max_limit=3):
|
||||
"""decorator to trim function calls to match the arity of the target"""
|
||||
global _trim_arity_call_line
|
||||
|
||||
|
@ -267,16 +277,12 @@ def _trim_arity(func, maxargs=2):
|
|||
# synthesize what would be returned by traceback.extract_stack at the call to
|
||||
# user's parse action 'func', so that we don't incur call penalty at parse time
|
||||
|
||||
LINE_DIFF = 11
|
||||
# fmt: off
|
||||
LINE_DIFF = 7
|
||||
# IF ANY CODE CHANGES, EVEN JUST COMMENTS OR BLANK LINES, BETWEEN THE NEXT LINE AND
|
||||
# THE CALL TO FUNC INSIDE WRAPPER, LINE_DIFF MUST BE MODIFIED!!!!
|
||||
_trim_arity_call_line = (
|
||||
_trim_arity_call_line or traceback.extract_stack(limit=2)[-1]
|
||||
)
|
||||
pa_call_line_synth = (
|
||||
_trim_arity_call_line[0],
|
||||
_trim_arity_call_line[1] + LINE_DIFF,
|
||||
)
|
||||
_trim_arity_call_line = (_trim_arity_call_line or traceback.extract_stack(limit=2)[-1])
|
||||
pa_call_line_synth = (_trim_arity_call_line[0], _trim_arity_call_line[1] + LINE_DIFF)
|
||||
|
||||
def wrapper(*args):
|
||||
nonlocal found_arity, limit
|
||||
|
@ -297,16 +303,18 @@ def _trim_arity(func, maxargs=2):
|
|||
del tb
|
||||
|
||||
if trim_arity_type_error:
|
||||
if limit <= maxargs:
|
||||
if limit < max_limit:
|
||||
limit += 1
|
||||
continue
|
||||
|
||||
raise
|
||||
# fmt: on
|
||||
|
||||
# copy func name to wrapper for sensible debug output
|
||||
# (can't use functools.wraps, since that messes with function signature)
|
||||
func_name = getattr(func, "__name__", getattr(func, "__class__").__name__)
|
||||
wrapper.__name__ = func_name
|
||||
wrapper.__doc__ = func.__doc__
|
||||
|
||||
return wrapper
|
||||
|
||||
|
@ -394,7 +402,7 @@ class ParserElement(ABC):
|
|||
|
||||
DEFAULT_WHITE_CHARS: str = " \n\t\r"
|
||||
verbose_stacktrace: bool = False
|
||||
_literalStringClass: OptionalType[type] = None
|
||||
_literalStringClass: typing.Optional[type] = None
|
||||
|
||||
@staticmethod
|
||||
def set_default_whitespace_chars(chars: str) -> None:
|
||||
|
@ -404,11 +412,11 @@ class ParserElement(ABC):
|
|||
Example::
|
||||
|
||||
# default whitespace chars are space, <TAB> and newline
|
||||
OneOrMore(Word(alphas)).parse_string("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl']
|
||||
Word(alphas)[1, ...].parse_string("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl']
|
||||
|
||||
# change to just treat newline as significant
|
||||
ParserElement.set_default_whitespace_chars(" \t")
|
||||
OneOrMore(Word(alphas)).parse_string("abc def\nghi jkl") # -> ['abc', 'def']
|
||||
Word(alphas)[1, ...].parse_string("abc def\nghi jkl") # -> ['abc', 'def']
|
||||
"""
|
||||
ParserElement.DEFAULT_WHITE_CHARS = chars
|
||||
|
||||
|
@ -440,13 +448,13 @@ class ParserElement(ABC):
|
|||
ParserElement._literalStringClass = cls
|
||||
|
||||
class DebugActions(NamedTuple):
|
||||
debug_try: OptionalType[DebugStartAction]
|
||||
debug_match: OptionalType[DebugSuccessAction]
|
||||
debug_fail: OptionalType[DebugExceptionAction]
|
||||
debug_try: typing.Optional[DebugStartAction]
|
||||
debug_match: typing.Optional[DebugSuccessAction]
|
||||
debug_fail: typing.Optional[DebugExceptionAction]
|
||||
|
||||
def __init__(self, savelist: bool = False):
|
||||
self.parseAction: List[ParseAction] = list()
|
||||
self.failAction: OptionalType[ParseFailAction] = None
|
||||
self.failAction: typing.Optional[ParseFailAction] = None
|
||||
self.customName = None
|
||||
self._defaultName = None
|
||||
self.resultsName = None
|
||||
|
@ -467,7 +475,6 @@ class ParserElement(ABC):
|
|||
self.modalResults = True
|
||||
# custom debug actions
|
||||
self.debugActions = self.DebugActions(None, None, None)
|
||||
self.re = None
|
||||
# avoid redundant calls to preParse
|
||||
self.callPreparse = True
|
||||
self.callDuringTry = False
|
||||
|
@ -501,7 +508,7 @@ class ParserElement(ABC):
|
|||
integerK = integer.copy().add_parse_action(lambda toks: toks[0] * 1024) + Suppress("K")
|
||||
integerM = integer.copy().add_parse_action(lambda toks: toks[0] * 1024 * 1024) + Suppress("M")
|
||||
|
||||
print(OneOrMore(integerK | integerM | integer).parse_string("5K 100 640K 256M"))
|
||||
print((integerK | integerM | integer)[1, ...].parse_string("5K 100 640K 256M"))
|
||||
|
||||
prints::
|
||||
|
||||
|
@ -886,7 +893,7 @@ class ParserElement(ABC):
|
|||
|
||||
# cache for left-recursion in Forward references
|
||||
recursion_lock = RLock()
|
||||
recursion_memos: DictType[
|
||||
recursion_memos: typing.Dict[
|
||||
Tuple[int, "Forward", bool], Tuple[int, Union[ParseResults, Exception]]
|
||||
] = {}
|
||||
|
||||
|
@ -976,7 +983,7 @@ class ParserElement(ABC):
|
|||
|
||||
@staticmethod
|
||||
def enable_left_recursion(
|
||||
cache_size_limit: OptionalType[int] = None, *, force=False
|
||||
cache_size_limit: typing.Optional[int] = None, *, force=False
|
||||
) -> None:
|
||||
"""
|
||||
Enables "bounded recursion" parsing, which allows for both direct and indirect
|
||||
|
@ -1342,7 +1349,7 @@ class ParserElement(ABC):
|
|||
last = e
|
||||
yield instring[last:]
|
||||
|
||||
def __add__(self, other):
|
||||
def __add__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``+`` operator - returns :class:`And`. Adding strings to a :class:`ParserElement`
|
||||
converts them to :class:`Literal`s by default.
|
||||
|
@ -1382,7 +1389,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return And([self, other])
|
||||
|
||||
def __radd__(self, other):
|
||||
def __radd__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``+`` operator when left operand is not a :class:`ParserElement`
|
||||
"""
|
||||
|
@ -1399,7 +1406,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return other + self
|
||||
|
||||
def __sub__(self, other):
|
||||
def __sub__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``-`` operator, returns :class:`And` with error stop
|
||||
"""
|
||||
|
@ -1413,7 +1420,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return self + And._ErrorStop() + other
|
||||
|
||||
def __rsub__(self, other):
|
||||
def __rsub__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``-`` operator when left operand is not a :class:`ParserElement`
|
||||
"""
|
||||
|
@ -1427,7 +1434,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return other - self
|
||||
|
||||
def __mul__(self, other):
|
||||
def __mul__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``*`` operator, allows use of ``expr * 3`` in place of
|
||||
``expr + expr + expr``. Expressions may also be multiplied by a 2-integer
|
||||
|
@ -1513,10 +1520,10 @@ class ParserElement(ABC):
|
|||
ret = And([self] * minElements)
|
||||
return ret
|
||||
|
||||
def __rmul__(self, other):
|
||||
def __rmul__(self, other) -> "ParserElement":
|
||||
return self.__mul__(other)
|
||||
|
||||
def __or__(self, other):
|
||||
def __or__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``|`` operator - returns :class:`MatchFirst`
|
||||
"""
|
||||
|
@ -1533,7 +1540,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return MatchFirst([self, other])
|
||||
|
||||
def __ror__(self, other):
|
||||
def __ror__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``|`` operator when left operand is not a :class:`ParserElement`
|
||||
"""
|
||||
|
@ -1547,7 +1554,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return other | self
|
||||
|
||||
def __xor__(self, other):
|
||||
def __xor__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``^`` operator - returns :class:`Or`
|
||||
"""
|
||||
|
@ -1561,7 +1568,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return Or([self, other])
|
||||
|
||||
def __rxor__(self, other):
|
||||
def __rxor__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``^`` operator when left operand is not a :class:`ParserElement`
|
||||
"""
|
||||
|
@ -1575,7 +1582,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return other ^ self
|
||||
|
||||
def __and__(self, other):
|
||||
def __and__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``&`` operator - returns :class:`Each`
|
||||
"""
|
||||
|
@ -1589,7 +1596,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return Each([self, other])
|
||||
|
||||
def __rand__(self, other):
|
||||
def __rand__(self, other) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``&`` operator when left operand is not a :class:`ParserElement`
|
||||
"""
|
||||
|
@ -1603,7 +1610,7 @@ class ParserElement(ABC):
|
|||
)
|
||||
return other & self
|
||||
|
||||
def __invert__(self):
|
||||
def __invert__(self) -> "ParserElement":
|
||||
"""
|
||||
Implementation of ``~`` operator - returns :class:`NotAny`
|
||||
"""
|
||||
|
@ -1653,7 +1660,7 @@ class ParserElement(ABC):
|
|||
ret = self * tuple(key[:2])
|
||||
return ret
|
||||
|
||||
def __call__(self, name: str = None):
|
||||
def __call__(self, name: str = None) -> "ParserElement":
|
||||
"""
|
||||
Shortcut for :class:`set_results_name`, with ``list_all_matches=False``.
|
||||
|
||||
|
@ -1729,7 +1736,7 @@ class ParserElement(ABC):
|
|||
|
||||
Example::
|
||||
|
||||
patt = OneOrMore(Word(alphas))
|
||||
patt = Word(alphas)[1, ...]
|
||||
patt.parse_string('ablaj /* comment */ lskjd')
|
||||
# -> ['ablaj']
|
||||
|
||||
|
@ -1789,7 +1796,7 @@ class ParserElement(ABC):
|
|||
# turn on debugging for wd
|
||||
wd.set_debug()
|
||||
|
||||
OneOrMore(term).parse_string("abc 123 xyz 890")
|
||||
term[1, ...].parse_string("abc 123 xyz 890")
|
||||
|
||||
prints::
|
||||
|
||||
|
@ -1944,12 +1951,12 @@ class ParserElement(ABC):
|
|||
self,
|
||||
tests: Union[str, List[str]],
|
||||
parse_all: bool = True,
|
||||
comment: OptionalType[Union["ParserElement", str]] = "#",
|
||||
comment: typing.Optional[Union["ParserElement", str]] = "#",
|
||||
full_dump: bool = True,
|
||||
print_results: bool = True,
|
||||
failure_tests: bool = False,
|
||||
post_parse: Callable[[str, ParseResults], str] = None,
|
||||
file: OptionalType[TextIO] = None,
|
||||
file: typing.Optional[TextIO] = None,
|
||||
with_line_numbers: bool = False,
|
||||
*,
|
||||
parseAll: bool = True,
|
||||
|
@ -2140,6 +2147,7 @@ class ParserElement(ABC):
|
|||
output_html: Union[TextIO, Path, str],
|
||||
vertical: int = 3,
|
||||
show_results_names: bool = False,
|
||||
show_groups: bool = False,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
"""
|
||||
|
@ -2152,7 +2160,7 @@ class ParserElement(ABC):
|
|||
instead of horizontally (default=3)
|
||||
- show_results_names - bool flag whether diagram should show annotations for
|
||||
defined results names
|
||||
|
||||
- show_groups - bool flag whether groups should be highlighted with an unlabeled surrounding box
|
||||
Additional diagram-formatting keyword arguments can also be included;
|
||||
see railroad.Diagram class.
|
||||
"""
|
||||
|
@ -2170,6 +2178,7 @@ class ParserElement(ABC):
|
|||
self,
|
||||
vertical=vertical,
|
||||
show_results_names=show_results_names,
|
||||
show_groups=show_groups,
|
||||
diagram_kwargs=kwargs,
|
||||
)
|
||||
if isinstance(output_html, (str, Path)):
|
||||
|
@ -2219,7 +2228,7 @@ class _PendingSkip(ParserElement):
|
|||
def _generateDefaultName(self):
|
||||
return str(self.anchor + Empty()).replace("Empty", "...")
|
||||
|
||||
def __add__(self, other):
|
||||
def __add__(self, other) -> "ParserElement":
|
||||
skipper = SkipTo(other).set_name("...")("_skipped*")
|
||||
if self.must_skip:
|
||||
|
||||
|
@ -2374,11 +2383,11 @@ class Keyword(Token):
|
|||
def __init__(
|
||||
self,
|
||||
match_string: str = "",
|
||||
ident_chars: OptionalType[str] = None,
|
||||
ident_chars: typing.Optional[str] = None,
|
||||
caseless: bool = False,
|
||||
*,
|
||||
matchString: str = "",
|
||||
identChars: OptionalType[str] = None,
|
||||
identChars: typing.Optional[str] = None,
|
||||
):
|
||||
super().__init__()
|
||||
identChars = identChars or ident_chars
|
||||
|
@ -2468,7 +2477,7 @@ class CaselessLiteral(Literal):
|
|||
|
||||
Example::
|
||||
|
||||
OneOrMore(CaselessLiteral("CMD")).parse_string("cmd CMD Cmd10")
|
||||
CaselessLiteral("CMD")[1, ...].parse_string("cmd CMD Cmd10")
|
||||
# -> ['CMD', 'CMD', 'CMD']
|
||||
|
||||
(Contrast with example for :class:`CaselessKeyword`.)
|
||||
|
@ -2493,7 +2502,7 @@ class CaselessKeyword(Keyword):
|
|||
|
||||
Example::
|
||||
|
||||
OneOrMore(CaselessKeyword("CMD")).parse_string("cmd CMD Cmd10")
|
||||
CaselessKeyword("CMD")[1, ...].parse_string("cmd CMD Cmd10")
|
||||
# -> ['CMD', 'CMD']
|
||||
|
||||
(Contrast with example for :class:`CaselessLiteral`.)
|
||||
|
@ -2502,10 +2511,10 @@ class CaselessKeyword(Keyword):
|
|||
def __init__(
|
||||
self,
|
||||
match_string: str = "",
|
||||
ident_chars: OptionalType[str] = None,
|
||||
ident_chars: typing.Optional[str] = None,
|
||||
*,
|
||||
matchString: str = "",
|
||||
identChars: OptionalType[str] = None,
|
||||
identChars: typing.Optional[str] = None,
|
||||
):
|
||||
identChars = identChars or ident_chars
|
||||
match_string = matchString or match_string
|
||||
|
@ -2669,17 +2678,17 @@ class Word(Token):
|
|||
def __init__(
|
||||
self,
|
||||
init_chars: str = "",
|
||||
body_chars: OptionalType[str] = None,
|
||||
body_chars: typing.Optional[str] = None,
|
||||
min: int = 1,
|
||||
max: int = 0,
|
||||
exact: int = 0,
|
||||
as_keyword: bool = False,
|
||||
exclude_chars: OptionalType[str] = None,
|
||||
exclude_chars: typing.Optional[str] = None,
|
||||
*,
|
||||
initChars: OptionalType[str] = None,
|
||||
bodyChars: OptionalType[str] = None,
|
||||
initChars: typing.Optional[str] = None,
|
||||
bodyChars: typing.Optional[str] = None,
|
||||
asKeyword: bool = False,
|
||||
excludeChars: OptionalType[str] = None,
|
||||
excludeChars: typing.Optional[str] = None,
|
||||
):
|
||||
initChars = initChars or init_chars
|
||||
bodyChars = bodyChars or body_chars
|
||||
|
@ -2773,7 +2782,7 @@ class Word(Token):
|
|||
|
||||
try:
|
||||
self.re = re.compile(self.reString)
|
||||
except sre_constants.error:
|
||||
except re.error:
|
||||
self.re = None
|
||||
else:
|
||||
self.re_match = self.re.match
|
||||
|
@ -2861,10 +2870,10 @@ class Char(_WordRegex):
|
|||
self,
|
||||
charset: str,
|
||||
as_keyword: bool = False,
|
||||
exclude_chars: OptionalType[str] = None,
|
||||
exclude_chars: typing.Optional[str] = None,
|
||||
*,
|
||||
asKeyword: bool = False,
|
||||
excludeChars: OptionalType[str] = None,
|
||||
excludeChars: typing.Optional[str] = None,
|
||||
):
|
||||
asKeyword = asKeyword or as_keyword
|
||||
excludeChars = excludeChars or exclude_chars
|
||||
|
@ -2926,19 +2935,12 @@ class Regex(Token):
|
|||
if not pattern:
|
||||
raise ValueError("null string passed to Regex; use Empty() instead")
|
||||
|
||||
self.pattern = pattern
|
||||
self._re = None
|
||||
self.reString = self.pattern = pattern
|
||||
self.flags = flags
|
||||
|
||||
try:
|
||||
self.re = re.compile(self.pattern, self.flags)
|
||||
self.reString = self.pattern
|
||||
except sre_constants.error:
|
||||
raise ValueError(
|
||||
"invalid pattern ({!r}) passed to Regex".format(pattern)
|
||||
)
|
||||
|
||||
elif hasattr(pattern, "pattern") and hasattr(pattern, "match"):
|
||||
self.re = pattern
|
||||
self._re = pattern
|
||||
self.pattern = self.reString = pattern.pattern
|
||||
self.flags = flags
|
||||
|
||||
|
@ -2947,11 +2949,8 @@ class Regex(Token):
|
|||
"Regex may only be constructed with a string or a compiled RE object"
|
||||
)
|
||||
|
||||
self.re_match = self.re.match
|
||||
|
||||
self.errmsg = "Expected " + self.name
|
||||
self.mayIndexError = False
|
||||
self.mayReturnEmpty = self.re_match("") is not None
|
||||
self.asGroupList = asGroupList
|
||||
self.asMatch = asMatch
|
||||
if self.asGroupList:
|
||||
|
@ -2959,6 +2958,26 @@ class Regex(Token):
|
|||
if self.asMatch:
|
||||
self.parseImpl = self.parseImplAsMatch
|
||||
|
||||
@cached_property
|
||||
def re(self):
|
||||
if self._re:
|
||||
return self._re
|
||||
else:
|
||||
try:
|
||||
return re.compile(self.pattern, self.flags)
|
||||
except re.error:
|
||||
raise ValueError(
|
||||
"invalid pattern ({!r}) passed to Regex".format(self.pattern)
|
||||
)
|
||||
|
||||
@cached_property
|
||||
def re_match(self):
|
||||
return self.re.match
|
||||
|
||||
@cached_property
|
||||
def mayReturnEmpty(self):
|
||||
return self.re_match("") is not None
|
||||
|
||||
def _generateDefaultName(self):
|
||||
return "Re:({})".format(repr(self.pattern).replace("\\\\", "\\"))
|
||||
|
||||
|
@ -3067,18 +3086,18 @@ class QuotedString(Token):
|
|||
def __init__(
|
||||
self,
|
||||
quote_char: str = "",
|
||||
esc_char: OptionalType[str] = None,
|
||||
esc_quote: OptionalType[str] = None,
|
||||
esc_char: typing.Optional[str] = None,
|
||||
esc_quote: typing.Optional[str] = None,
|
||||
multiline: bool = False,
|
||||
unquote_results: bool = True,
|
||||
end_quote_char: OptionalType[str] = None,
|
||||
end_quote_char: typing.Optional[str] = None,
|
||||
convert_whitespace_escapes: bool = True,
|
||||
*,
|
||||
quoteChar: str = "",
|
||||
escChar: OptionalType[str] = None,
|
||||
escQuote: OptionalType[str] = None,
|
||||
escChar: typing.Optional[str] = None,
|
||||
escQuote: typing.Optional[str] = None,
|
||||
unquoteResults: bool = True,
|
||||
endQuoteChar: OptionalType[str] = None,
|
||||
endQuoteChar: typing.Optional[str] = None,
|
||||
convertWhitespaceEscapes: bool = True,
|
||||
):
|
||||
super().__init__()
|
||||
|
@ -3168,7 +3187,7 @@ class QuotedString(Token):
|
|||
self.re = re.compile(self.pattern, self.flags)
|
||||
self.reString = self.pattern
|
||||
self.re_match = self.re.match
|
||||
except sre_constants.error:
|
||||
except re.error:
|
||||
raise ValueError(
|
||||
"invalid pattern {!r} passed to Regex".format(self.pattern)
|
||||
)
|
||||
|
@ -3579,7 +3598,7 @@ class ParseExpression(ParserElement):
|
|||
post-processing parsed tokens.
|
||||
"""
|
||||
|
||||
def __init__(self, exprs: IterableType[ParserElement], savelist: bool = False):
|
||||
def __init__(self, exprs: typing.Iterable[ParserElement], savelist: bool = False):
|
||||
super().__init__(savelist)
|
||||
self.exprs: List[ParserElement]
|
||||
if isinstance(exprs, _generatorType):
|
||||
|
@ -3746,7 +3765,7 @@ class And(ParseExpression):
|
|||
Example::
|
||||
|
||||
integer = Word(nums)
|
||||
name_expr = OneOrMore(Word(alphas))
|
||||
name_expr = Word(alphas)[1, ...]
|
||||
|
||||
expr = And([integer("id"), name_expr("name"), integer("age")])
|
||||
# more easily written as:
|
||||
|
@ -3761,7 +3780,9 @@ class And(ParseExpression):
|
|||
def _generateDefaultName(self):
|
||||
return "-"
|
||||
|
||||
def __init__(self, exprs_arg: IterableType[ParserElement], savelist: bool = True):
|
||||
def __init__(
|
||||
self, exprs_arg: typing.Iterable[ParserElement], savelist: bool = True
|
||||
):
|
||||
exprs: List[ParserElement] = list(exprs_arg)
|
||||
if exprs and Ellipsis in exprs:
|
||||
tmp = []
|
||||
|
@ -3826,7 +3847,9 @@ class And(ParseExpression):
|
|||
seen.add(id(cur))
|
||||
if isinstance(cur, IndentedBlock):
|
||||
prev.add_parse_action(
|
||||
lambda s, l, t, cur_=cur: setattr(cur_, "parent_anchor", col(l, s))
|
||||
lambda s, l, t, cur_=cur: setattr(
|
||||
cur_, "parent_anchor", col(l, s)
|
||||
)
|
||||
)
|
||||
break
|
||||
subs = cur.recurse()
|
||||
|
@ -3903,7 +3926,7 @@ class Or(ParseExpression):
|
|||
[['123'], ['3.1416'], ['789']]
|
||||
"""
|
||||
|
||||
def __init__(self, exprs: IterableType[ParserElement], savelist: bool = False):
|
||||
def __init__(self, exprs: typing.Iterable[ParserElement], savelist: bool = False):
|
||||
super().__init__(exprs, savelist)
|
||||
if self.exprs:
|
||||
self.mayReturnEmpty = any(e.mayReturnEmpty for e in self.exprs)
|
||||
|
@ -4058,7 +4081,7 @@ class MatchFirst(ParseExpression):
|
|||
print(number.search_string("123 3.1416 789")) # Better -> [['123'], ['3.1416'], ['789']]
|
||||
"""
|
||||
|
||||
def __init__(self, exprs: IterableType[ParserElement], savelist: bool = False):
|
||||
def __init__(self, exprs: typing.Iterable[ParserElement], savelist: bool = False):
|
||||
super().__init__(exprs, savelist)
|
||||
if self.exprs:
|
||||
self.mayReturnEmpty = any(e.mayReturnEmpty for e in self.exprs)
|
||||
|
@ -4209,7 +4232,7 @@ class Each(ParseExpression):
|
|||
- size: 20
|
||||
"""
|
||||
|
||||
def __init__(self, exprs: IterableType[ParserElement], savelist: bool = True):
|
||||
def __init__(self, exprs: typing.Iterable[ParserElement], savelist: bool = True):
|
||||
super().__init__(exprs, savelist)
|
||||
if self.exprs:
|
||||
self.mayReturnEmpty = all(e.mayReturnEmpty for e in self.exprs)
|
||||
|
@ -4545,7 +4568,7 @@ class FollowedBy(ParseElementEnhance):
|
|||
label = data_word + FollowedBy(':')
|
||||
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
|
||||
|
||||
OneOrMore(attr_expr).parse_string("shape: SQUARE color: BLACK posn: upper left").pprint()
|
||||
attr_expr[1, ...].parse_string("shape: SQUARE color: BLACK posn: upper left").pprint()
|
||||
|
||||
prints::
|
||||
|
||||
|
@ -4596,7 +4619,7 @@ class PrecededBy(ParseElementEnhance):
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, expr: Union[ParserElement, str], retreat: OptionalType[int] = None
|
||||
self, expr: Union[ParserElement, str], retreat: typing.Optional[int] = None
|
||||
):
|
||||
super().__init__(expr)
|
||||
self.expr = self.expr().leave_whitespace()
|
||||
|
@ -4707,7 +4730,7 @@ class NotAny(ParseElementEnhance):
|
|||
|
||||
# very crude boolean expression - to support parenthesis groups and
|
||||
# operation hierarchy, use infix_notation
|
||||
boolean_expr = boolean_term + ZeroOrMore((AND | OR) + boolean_term)
|
||||
boolean_expr = boolean_term + ((AND | OR) + boolean_term)[...]
|
||||
|
||||
# integers that are followed by "." are actually floats
|
||||
integer = Word(nums) + ~Char(".")
|
||||
|
@ -4735,9 +4758,9 @@ class _MultipleMatch(ParseElementEnhance):
|
|||
def __init__(
|
||||
self,
|
||||
expr: ParserElement,
|
||||
stop_on: OptionalType[Union[ParserElement, str]] = None,
|
||||
stop_on: typing.Optional[Union[ParserElement, str]] = None,
|
||||
*,
|
||||
stopOn: OptionalType[Union[ParserElement, str]] = None,
|
||||
stopOn: typing.Optional[Union[ParserElement, str]] = None,
|
||||
):
|
||||
super().__init__(expr)
|
||||
stopOn = stopOn or stop_on
|
||||
|
@ -4826,7 +4849,7 @@ class OneOrMore(_MultipleMatch):
|
|||
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).set_parse_action(' '.join))
|
||||
|
||||
text = "shape: SQUARE posn: upper left color: BLACK"
|
||||
OneOrMore(attr_expr).parse_string(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]
|
||||
attr_expr[1, ...].parse_string(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']]
|
||||
|
||||
# use stop_on attribute for OneOrMore to avoid reading label string as part of the data
|
||||
attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
|
||||
|
@ -4856,9 +4879,9 @@ class ZeroOrMore(_MultipleMatch):
|
|||
def __init__(
|
||||
self,
|
||||
expr: ParserElement,
|
||||
stop_on: OptionalType[Union[ParserElement, str]] = None,
|
||||
stop_on: typing.Optional[Union[ParserElement, str]] = None,
|
||||
*,
|
||||
stopOn: OptionalType[Union[ParserElement, str]] = None,
|
||||
stopOn: typing.Optional[Union[ParserElement, str]] = None,
|
||||
):
|
||||
super().__init__(expr, stopOn=stopOn or stop_on)
|
||||
self.mayReturnEmpty = True
|
||||
|
@ -5002,20 +5025,20 @@ class SkipTo(ParseElementEnhance):
|
|||
prints::
|
||||
|
||||
['101', 'Critical', 'Intermittent system crash', '6']
|
||||
- days_open: 6
|
||||
- desc: Intermittent system crash
|
||||
- issue_num: 101
|
||||
- sev: Critical
|
||||
- days_open: '6'
|
||||
- desc: 'Intermittent system crash'
|
||||
- issue_num: '101'
|
||||
- sev: 'Critical'
|
||||
['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14']
|
||||
- days_open: 14
|
||||
- desc: Spelling error on Login ('log|n')
|
||||
- issue_num: 94
|
||||
- sev: Cosmetic
|
||||
- days_open: '14'
|
||||
- desc: "Spelling error on Login ('log|n')"
|
||||
- issue_num: '94'
|
||||
- sev: 'Cosmetic'
|
||||
['79', 'Minor', 'System slow when running too many reports', '47']
|
||||
- days_open: 47
|
||||
- desc: System slow when running too many reports
|
||||
- issue_num: 79
|
||||
- sev: Minor
|
||||
- days_open: '47'
|
||||
- desc: 'System slow when running too many reports'
|
||||
- issue_num: '79'
|
||||
- sev: 'Minor'
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
@ -5023,7 +5046,7 @@ class SkipTo(ParseElementEnhance):
|
|||
other: Union[ParserElement, str],
|
||||
include: bool = False,
|
||||
ignore: bool = None,
|
||||
fail_on: OptionalType[Union[ParserElement, str]] = None,
|
||||
fail_on: typing.Optional[Union[ParserElement, str]] = None,
|
||||
*,
|
||||
failOn: Union[ParserElement, str] = None,
|
||||
):
|
||||
|
@ -5120,7 +5143,7 @@ class Forward(ParseElementEnhance):
|
|||
parser created using ``Forward``.
|
||||
"""
|
||||
|
||||
def __init__(self, other: OptionalType[Union[ParserElement, str]] = None):
|
||||
def __init__(self, other: typing.Optional[Union[ParserElement, str]] = None):
|
||||
self.caller_frame = traceback.extract_stack(limit=2)[0]
|
||||
super().__init__(other, savelist=False)
|
||||
self.lshift_line = None
|
||||
|
@ -5372,7 +5395,7 @@ class Combine(TokenConverter):
|
|||
join_string: str = "",
|
||||
adjacent: bool = True,
|
||||
*,
|
||||
joinString: OptionalType[str] = None,
|
||||
joinString: typing.Optional[str] = None,
|
||||
):
|
||||
super().__init__(expr)
|
||||
joinString = joinString if joinString is not None else join_string
|
||||
|
@ -5459,10 +5482,10 @@ class Dict(TokenConverter):
|
|||
attr_expr = (label + Suppress(':') + OneOrMore(data_word, stop_on=label).set_parse_action(' '.join))
|
||||
|
||||
# print attributes as plain groups
|
||||
print(OneOrMore(attr_expr).parse_string(text).dump())
|
||||
print(attr_expr[1, ...].parse_string(text).dump())
|
||||
|
||||
# instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names
|
||||
result = Dict(OneOrMore(Group(attr_expr))).parse_string(text)
|
||||
# instead of OneOrMore(expr), parse using Dict(Group(expr)[1, ...]) - Dict will auto-assign names
|
||||
result = Dict(Group(attr_expr)[1, ...]).parse_string(text)
|
||||
print(result.dump())
|
||||
|
||||
# access named fields as dict entries, or output as dict
|
||||
|
@ -5473,10 +5496,10 @@ class Dict(TokenConverter):
|
|||
|
||||
['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']
|
||||
[['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
|
||||
- color: light blue
|
||||
- posn: upper left
|
||||
- shape: SQUARE
|
||||
- texture: burlap
|
||||
- color: 'light blue'
|
||||
- posn: 'upper left'
|
||||
- shape: 'SQUARE'
|
||||
- texture: 'burlap'
|
||||
SQUARE
|
||||
{'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}
|
||||
|
||||
|
@ -5535,12 +5558,12 @@ class Suppress(TokenConverter):
|
|||
|
||||
source = "a, b, c,d"
|
||||
wd = Word(alphas)
|
||||
wd_list1 = wd + ZeroOrMore(',' + wd)
|
||||
wd_list1 = wd + (',' + wd)[...]
|
||||
print(wd_list1.parse_string(source))
|
||||
|
||||
# often, delimiters that are useful during parsing are just in the
|
||||
# way afterward - use Suppress to keep them out of the parsed output
|
||||
wd_list2 = wd + ZeroOrMore(Suppress(',') + wd)
|
||||
wd_list2 = wd + (Suppress(',') + wd)[...]
|
||||
print(wd_list2.parse_string(source))
|
||||
|
||||
# Skipped text (using '...') can be suppressed as well
|
||||
|
@ -5564,13 +5587,13 @@ class Suppress(TokenConverter):
|
|||
expr = _PendingSkip(NoMatch())
|
||||
super().__init__(expr)
|
||||
|
||||
def __add__(self, other):
|
||||
def __add__(self, other) -> "ParserElement":
|
||||
if isinstance(self.expr, _PendingSkip):
|
||||
return Suppress(SkipTo(other)) + other
|
||||
else:
|
||||
return super().__add__(other)
|
||||
|
||||
def __sub__(self, other):
|
||||
def __sub__(self, other) -> "ParserElement":
|
||||
if isinstance(self.expr, _PendingSkip):
|
||||
return Suppress(SkipTo(other)) - other
|
||||
else:
|
||||
|
@ -5599,7 +5622,7 @@ def trace_parse_action(f: ParseAction) -> ParseAction:
|
|||
def remove_duplicate_chars(tokens):
|
||||
return ''.join(sorted(set(''.join(tokens))))
|
||||
|
||||
wds = OneOrMore(wd).set_parse_action(remove_duplicate_chars)
|
||||
wds = wd[1, ...].set_parse_action(remove_duplicate_chars)
|
||||
print(wds.parse_string("slkdjs sld sldd sdlf sdljf"))
|
||||
|
||||
prints::
|
||||
|
@ -5705,18 +5728,18 @@ def token_map(func, *args) -> ParseAction:
|
|||
|
||||
Example (compare the last to example in :class:`ParserElement.transform_string`::
|
||||
|
||||
hex_ints = OneOrMore(Word(hexnums)).set_parse_action(token_map(int, 16))
|
||||
hex_ints = Word(hexnums)[1, ...].set_parse_action(token_map(int, 16))
|
||||
hex_ints.run_tests('''
|
||||
00 11 22 aa FF 0a 0d 1a
|
||||
''')
|
||||
|
||||
upperword = Word(alphas).set_parse_action(token_map(str.upper))
|
||||
OneOrMore(upperword).run_tests('''
|
||||
upperword[1, ...].run_tests('''
|
||||
my kingdom for a horse
|
||||
''')
|
||||
|
||||
wd = Word(alphas).set_parse_action(token_map(str.title))
|
||||
OneOrMore(wd).set_parse_action(' '.join).run_tests('''
|
||||
wd[1, ...].set_parse_action(' '.join).run_tests('''
|
||||
now is the winter of our discontent made glorious summer by this sun of york
|
||||
''')
|
||||
|
||||
|
@ -5772,7 +5795,9 @@ punc8bit = srange(r"[\0xa1-\0xbf\0xd7\0xf7]")
|
|||
|
||||
# build list of built-in expressions, for future reference if a global default value
|
||||
# gets updated
|
||||
_builtin_exprs = [v for v in vars().values() if isinstance(v, ParserElement)]
|
||||
_builtin_exprs: List[ParserElement] = [
|
||||
v for v in vars().values() if isinstance(v, ParserElement)
|
||||
]
|
||||
|
||||
# backward compatibility names
|
||||
tokenMap = token_map
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue