mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-07 05:31:15 -07:00
Bump pyparsing from 3.1.1 to 3.1.2 (#2296)
* Bump pyparsing from 3.1.1 to 3.1.2 Bumps [pyparsing](https://github.com/pyparsing/pyparsing) from 3.1.1 to 3.1.2. - [Release notes](https://github.com/pyparsing/pyparsing/releases) - [Changelog](https://github.com/pyparsing/pyparsing/blob/master/CHANGES) - [Commits](https://github.com/pyparsing/pyparsing/compare/3.1.1...pyparsing_3.1.2) --- 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.1.2 --------- Signed-off-by: dependabot[bot] <support@github.com> 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
1d96e0f859
commit
26358427ce
12 changed files with 610 additions and 706 deletions
|
@ -120,8 +120,8 @@ class version_info(NamedTuple):
|
||||||
return f"{__name__}.{type(self).__name__}({', '.join('{}={!r}'.format(*nv) for nv in zip(self._fields, self))})"
|
return f"{__name__}.{type(self).__name__}({', '.join('{}={!r}'.format(*nv) for nv in zip(self._fields, self))})"
|
||||||
|
|
||||||
|
|
||||||
__version_info__ = version_info(3, 1, 1, "final", 1)
|
__version_info__ = version_info(3, 1, 2, "final", 1)
|
||||||
__version_time__ = "29 Jul 2023 22:27 UTC"
|
__version_time__ = "06 Mar 2024 07:08 UTC"
|
||||||
__version__ = __version_info__.__version__
|
__version__ = __version_info__.__version__
|
||||||
__versionTime__ = __version_time__
|
__versionTime__ = __version_time__
|
||||||
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"
|
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"
|
||||||
|
|
|
@ -111,7 +111,6 @@ def with_attribute(*args, **attr_dict):
|
||||||
<div type="graph">1,3 2,3 1,1</div>
|
<div type="graph">1,3 2,3 1,1</div>
|
||||||
<div>this has no type</div>
|
<div>this has no type</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
'''
|
'''
|
||||||
div,div_end = make_html_tags("div")
|
div,div_end = make_html_tags("div")
|
||||||
|
|
||||||
|
@ -199,19 +198,9 @@ def with_class(classname, namespace=""):
|
||||||
|
|
||||||
# pre-PEP8 compatibility symbols
|
# pre-PEP8 compatibility symbols
|
||||||
# fmt: off
|
# fmt: off
|
||||||
@replaced_by_pep8(replace_with)
|
replaceWith = replaced_by_pep8("replaceWith", replace_with)
|
||||||
def replaceWith(): ...
|
removeQuotes = replaced_by_pep8("removeQuotes", remove_quotes)
|
||||||
|
withAttribute = replaced_by_pep8("withAttribute", with_attribute)
|
||||||
@replaced_by_pep8(remove_quotes)
|
withClass = replaced_by_pep8("withClass", with_class)
|
||||||
def removeQuotes(): ...
|
matchOnlyAtCol = replaced_by_pep8("matchOnlyAtCol", match_only_at_col)
|
||||||
|
|
||||||
@replaced_by_pep8(with_attribute)
|
|
||||||
def withAttribute(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(with_class)
|
|
||||||
def withClass(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(match_only_at_col)
|
|
||||||
def matchOnlyAtCol(): ...
|
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
@ -206,7 +206,7 @@ class pyparsing_common:
|
||||||
scientific notation and returns a float"""
|
scientific notation and returns a float"""
|
||||||
|
|
||||||
# streamlining this expression makes the docs nicer-looking
|
# streamlining this expression makes the docs nicer-looking
|
||||||
number = (sci_real | real | signed_integer).setName("number").streamline()
|
number = (sci_real | real | signed_integer).set_name("number").streamline()
|
||||||
"""any numeric expression, returns the corresponding Python type"""
|
"""any numeric expression, returns the corresponding Python type"""
|
||||||
|
|
||||||
fnumber = (
|
fnumber = (
|
||||||
|
@ -216,6 +216,13 @@ class pyparsing_common:
|
||||||
)
|
)
|
||||||
"""any int or real number, returned as float"""
|
"""any int or real number, returned as float"""
|
||||||
|
|
||||||
|
ieee_float = (
|
||||||
|
Regex(r"(?i)[+-]?((\d+\.?\d*(e[+-]?\d+)?)|nan|inf(inity)?)")
|
||||||
|
.set_name("ieee_float")
|
||||||
|
.set_parse_action(convert_to_float)
|
||||||
|
)
|
||||||
|
"""any floating-point literal (int, real number, infinity, or NaN), returned as float"""
|
||||||
|
|
||||||
identifier = Word(identchars, identbodychars).set_name("identifier")
|
identifier = Word(identchars, identbodychars).set_name("identifier")
|
||||||
"""typical code identifier (leading alpha or '_', followed by 0 or more alphas, nums, or '_')"""
|
"""typical code identifier (leading alpha or '_', followed by 0 or more alphas, nums, or '_')"""
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -473,7 +473,7 @@ def _to_diagram_element(
|
||||||
:param show_groups: bool flag indicating whether to show groups using bounding box
|
:param show_groups: bool flag indicating whether to show groups using bounding box
|
||||||
"""
|
"""
|
||||||
exprs = element.recurse()
|
exprs = element.recurse()
|
||||||
name = name_hint or element.customName or element.__class__.__name__
|
name = name_hint or element.customName or type(element).__name__
|
||||||
|
|
||||||
# Python's id() is used to provide a unique identifier for elements
|
# Python's id() is used to provide a unique identifier for elements
|
||||||
el_id = id(element)
|
el_id = id(element)
|
||||||
|
|
|
@ -14,11 +14,13 @@ from .util import (
|
||||||
from .unicode import pyparsing_unicode as ppu
|
from .unicode import pyparsing_unicode as ppu
|
||||||
|
|
||||||
|
|
||||||
class ExceptionWordUnicode(ppu.Latin1, ppu.LatinA, ppu.LatinB, ppu.Greek, ppu.Cyrillic):
|
class _ExceptionWordUnicodeSet(
|
||||||
|
ppu.Latin1, ppu.LatinA, ppu.LatinB, ppu.Greek, ppu.Cyrillic
|
||||||
|
):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
_extract_alphanums = _collapse_string_to_ranges(ExceptionWordUnicode.alphanums)
|
_extract_alphanums = _collapse_string_to_ranges(_ExceptionWordUnicodeSet.alphanums)
|
||||||
_exception_word_extractor = re.compile("([" + _extract_alphanums + "]{1,16})|.")
|
_exception_word_extractor = re.compile("([" + _extract_alphanums + "]{1,16})|.")
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,41 +88,39 @@ class ParseBaseException(Exception):
|
||||||
ret.append(" " * (exc.column - 1) + "^")
|
ret.append(" " * (exc.column - 1) + "^")
|
||||||
ret.append(f"{type(exc).__name__}: {exc}")
|
ret.append(f"{type(exc).__name__}: {exc}")
|
||||||
|
|
||||||
if depth > 0:
|
if depth <= 0:
|
||||||
callers = inspect.getinnerframes(exc.__traceback__, context=depth)
|
return "\n".join(ret)
|
||||||
seen = set()
|
|
||||||
for i, ff in enumerate(callers[-depth:]):
|
|
||||||
frm = ff[0]
|
|
||||||
|
|
||||||
f_self = frm.f_locals.get("self", None)
|
callers = inspect.getinnerframes(exc.__traceback__, context=depth)
|
||||||
if isinstance(f_self, ParserElement):
|
seen = set()
|
||||||
if not frm.f_code.co_name.startswith(
|
for ff in callers[-depth:]:
|
||||||
("parseImpl", "_parseNoCache")
|
frm = ff[0]
|
||||||
):
|
|
||||||
continue
|
|
||||||
if id(f_self) in seen:
|
|
||||||
continue
|
|
||||||
seen.add(id(f_self))
|
|
||||||
|
|
||||||
self_type = type(f_self)
|
f_self = frm.f_locals.get("self", None)
|
||||||
ret.append(
|
if isinstance(f_self, ParserElement):
|
||||||
f"{self_type.__module__}.{self_type.__name__} - {f_self}"
|
if not frm.f_code.co_name.startswith(("parseImpl", "_parseNoCache")):
|
||||||
)
|
continue
|
||||||
|
if id(f_self) in seen:
|
||||||
|
continue
|
||||||
|
seen.add(id(f_self))
|
||||||
|
|
||||||
elif f_self is not None:
|
self_type = type(f_self)
|
||||||
self_type = type(f_self)
|
ret.append(f"{self_type.__module__}.{self_type.__name__} - {f_self}")
|
||||||
ret.append(f"{self_type.__module__}.{self_type.__name__}")
|
|
||||||
|
|
||||||
else:
|
elif f_self is not None:
|
||||||
code = frm.f_code
|
self_type = type(f_self)
|
||||||
if code.co_name in ("wrapper", "<module>"):
|
ret.append(f"{self_type.__module__}.{self_type.__name__}")
|
||||||
continue
|
|
||||||
|
|
||||||
ret.append(code.co_name)
|
else:
|
||||||
|
code = frm.f_code
|
||||||
|
if code.co_name in ("wrapper", "<module>"):
|
||||||
|
continue
|
||||||
|
|
||||||
depth -= 1
|
ret.append(code.co_name)
|
||||||
if not depth:
|
|
||||||
break
|
depth -= 1
|
||||||
|
if not depth:
|
||||||
|
break
|
||||||
|
|
||||||
return "\n".join(ret)
|
return "\n".join(ret)
|
||||||
|
|
||||||
|
@ -220,8 +220,10 @@ class ParseBaseException(Exception):
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
|
# an expression to parse 3 integers
|
||||||
expr = pp.Word(pp.nums) * 3
|
expr = pp.Word(pp.nums) * 3
|
||||||
try:
|
try:
|
||||||
|
# a failing parse - the third integer is prefixed with "A"
|
||||||
expr.parse_string("123 456 A789")
|
expr.parse_string("123 456 A789")
|
||||||
except pp.ParseException as pe:
|
except pp.ParseException as pe:
|
||||||
print(pe.explain(depth=0))
|
print(pe.explain(depth=0))
|
||||||
|
@ -244,8 +246,7 @@ class ParseBaseException(Exception):
|
||||||
return self.explain_exception(self, depth)
|
return self.explain_exception(self, depth)
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
@replaced_by_pep8(mark_input_line)
|
markInputline = replaced_by_pep8("markInputline", mark_input_line)
|
||||||
def markInputline(self): ...
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,16 +256,16 @@ class ParseException(ParseBaseException):
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
|
integer = Word(nums).set_name("integer")
|
||||||
try:
|
try:
|
||||||
Word(nums).set_name("integer").parse_string("ABC")
|
integer.parse_string("ABC")
|
||||||
except ParseException as pe:
|
except ParseException as pe:
|
||||||
print(pe)
|
print(pe)
|
||||||
print("column: {}".format(pe.column))
|
print(f"column: {pe.column}")
|
||||||
|
|
||||||
prints::
|
prints::
|
||||||
|
|
||||||
Expected integer (at char 0), (line:1, col:1)
|
Expected integer (at char 0), (line:1, col:1) column: 1
|
||||||
column: 1
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ def counted_array(
|
||||||
intExpr = intExpr.copy()
|
intExpr = intExpr.copy()
|
||||||
intExpr.set_name("arrayLen")
|
intExpr.set_name("arrayLen")
|
||||||
intExpr.add_parse_action(count_field_parse_action, call_during_try=True)
|
intExpr.add_parse_action(count_field_parse_action, call_during_try=True)
|
||||||
return (intExpr + array_expr).set_name("(len) " + str(expr) + "...")
|
return (intExpr + array_expr).set_name(f"(len) {expr}...")
|
||||||
|
|
||||||
|
|
||||||
def match_previous_literal(expr: ParserElement) -> ParserElement:
|
def match_previous_literal(expr: ParserElement) -> ParserElement:
|
||||||
|
@ -95,15 +95,17 @@ def match_previous_literal(expr: ParserElement) -> ParserElement:
|
||||||
rep = Forward()
|
rep = Forward()
|
||||||
|
|
||||||
def copy_token_to_repeater(s, l, t):
|
def copy_token_to_repeater(s, l, t):
|
||||||
if t:
|
if not t:
|
||||||
if len(t) == 1:
|
|
||||||
rep << t[0]
|
|
||||||
else:
|
|
||||||
# flatten t tokens
|
|
||||||
tflat = _flatten(t.as_list())
|
|
||||||
rep << And(Literal(tt) for tt in tflat)
|
|
||||||
else:
|
|
||||||
rep << Empty()
|
rep << Empty()
|
||||||
|
return
|
||||||
|
|
||||||
|
if len(t) == 1:
|
||||||
|
rep << t[0]
|
||||||
|
return
|
||||||
|
|
||||||
|
# flatten t tokens
|
||||||
|
tflat = _flatten(t.as_list())
|
||||||
|
rep << And(Literal(tt) for tt in tflat)
|
||||||
|
|
||||||
expr.add_parse_action(copy_token_to_repeater, callDuringTry=True)
|
expr.add_parse_action(copy_token_to_repeater, callDuringTry=True)
|
||||||
rep.set_name("(prev) " + str(expr))
|
rep.set_name("(prev) " + str(expr))
|
||||||
|
@ -230,7 +232,7 @@ def one_of(
|
||||||
if isequal(other, cur):
|
if isequal(other, cur):
|
||||||
del symbols[i + j + 1]
|
del symbols[i + j + 1]
|
||||||
break
|
break
|
||||||
elif masks(cur, other):
|
if masks(cur, other):
|
||||||
del symbols[i + j + 1]
|
del symbols[i + j + 1]
|
||||||
symbols.insert(i, other)
|
symbols.insert(i, other)
|
||||||
break
|
break
|
||||||
|
@ -534,7 +536,9 @@ def nested_expr(
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
ret <<= Group(Suppress(opener) + ZeroOrMore(ret | content) + Suppress(closer))
|
ret <<= Group(Suppress(opener) + ZeroOrMore(ret | content) + Suppress(closer))
|
||||||
ret.set_name("nested %s%s expression" % (opener, closer))
|
ret.set_name(f"nested {opener}{closer} expression")
|
||||||
|
# don't override error message from content expressions
|
||||||
|
ret.errmsg = None
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -580,7 +584,7 @@ def _makeTags(tagStr, xml, suppress_LT=Suppress("<"), suppress_GT=Suppress(">"))
|
||||||
)
|
)
|
||||||
closeTag = Combine(Literal("</") + tagStr + ">", adjacent=False)
|
closeTag = Combine(Literal("</") + tagStr + ">", adjacent=False)
|
||||||
|
|
||||||
openTag.set_name("<%s>" % resname)
|
openTag.set_name(f"<{resname}>")
|
||||||
# add start<tagname> results name in parse action now that ungrouped names are not reported at two levels
|
# add start<tagname> results name in parse action now that ungrouped names are not reported at two levels
|
||||||
openTag.add_parse_action(
|
openTag.add_parse_action(
|
||||||
lambda t: t.__setitem__(
|
lambda t: t.__setitem__(
|
||||||
|
@ -589,7 +593,7 @@ def _makeTags(tagStr, xml, suppress_LT=Suppress("<"), suppress_GT=Suppress(">"))
|
||||||
)
|
)
|
||||||
closeTag = closeTag(
|
closeTag = closeTag(
|
||||||
"end" + "".join(resname.replace(":", " ").title().split())
|
"end" + "".join(resname.replace(":", " ").title().split())
|
||||||
).set_name("</%s>" % resname)
|
).set_name(f"</{resname}>")
|
||||||
openTag.tag = resname
|
openTag.tag = resname
|
||||||
closeTag.tag = resname
|
closeTag.tag = resname
|
||||||
openTag.tag_body = SkipTo(closeTag())
|
openTag.tag_body = SkipTo(closeTag())
|
||||||
|
@ -777,7 +781,7 @@ def infix_notation(
|
||||||
rpar = Suppress(rpar)
|
rpar = Suppress(rpar)
|
||||||
|
|
||||||
# if lpar and rpar are not suppressed, wrap in group
|
# if lpar and rpar are not suppressed, wrap in group
|
||||||
if not (isinstance(rpar, Suppress) and isinstance(rpar, Suppress)):
|
if not (isinstance(lpar, Suppress) and isinstance(rpar, Suppress)):
|
||||||
lastExpr = base_expr | Group(lpar + ret + rpar)
|
lastExpr = base_expr | Group(lpar + ret + rpar)
|
||||||
else:
|
else:
|
||||||
lastExpr = base_expr | (lpar + ret + rpar)
|
lastExpr = base_expr | (lpar + ret + rpar)
|
||||||
|
@ -787,7 +791,7 @@ def infix_notation(
|
||||||
pa: typing.Optional[ParseAction]
|
pa: typing.Optional[ParseAction]
|
||||||
opExpr1: ParserElement
|
opExpr1: ParserElement
|
||||||
opExpr2: ParserElement
|
opExpr2: ParserElement
|
||||||
for i, operDef in enumerate(op_list):
|
for operDef in op_list:
|
||||||
opExpr, arity, rightLeftAssoc, pa = (operDef + (None,))[:4] # type: ignore[assignment]
|
opExpr, arity, rightLeftAssoc, pa = (operDef + (None,))[:4] # type: ignore[assignment]
|
||||||
if isinstance(opExpr, str_type):
|
if isinstance(opExpr, str_type):
|
||||||
opExpr = ParserElement._literalStringClass(opExpr)
|
opExpr = ParserElement._literalStringClass(opExpr)
|
||||||
|
@ -1058,43 +1062,17 @@ dblSlashComment = dbl_slash_comment
|
||||||
cppStyleComment = cpp_style_comment
|
cppStyleComment = cpp_style_comment
|
||||||
javaStyleComment = java_style_comment
|
javaStyleComment = java_style_comment
|
||||||
pythonStyleComment = python_style_comment
|
pythonStyleComment = python_style_comment
|
||||||
|
delimitedList = replaced_by_pep8("delimitedList", DelimitedList)
|
||||||
@replaced_by_pep8(DelimitedList)
|
delimited_list = replaced_by_pep8("delimited_list", DelimitedList)
|
||||||
def delimitedList(): ...
|
countedArray = replaced_by_pep8("countedArray", counted_array)
|
||||||
|
matchPreviousLiteral = replaced_by_pep8("matchPreviousLiteral", match_previous_literal)
|
||||||
@replaced_by_pep8(DelimitedList)
|
matchPreviousExpr = replaced_by_pep8("matchPreviousExpr", match_previous_expr)
|
||||||
def delimited_list(): ...
|
oneOf = replaced_by_pep8("oneOf", one_of)
|
||||||
|
dictOf = replaced_by_pep8("dictOf", dict_of)
|
||||||
@replaced_by_pep8(counted_array)
|
originalTextFor = replaced_by_pep8("originalTextFor", original_text_for)
|
||||||
def countedArray(): ...
|
nestedExpr = replaced_by_pep8("nestedExpr", nested_expr)
|
||||||
|
makeHTMLTags = replaced_by_pep8("makeHTMLTags", make_html_tags)
|
||||||
@replaced_by_pep8(match_previous_literal)
|
makeXMLTags = replaced_by_pep8("makeXMLTags", make_xml_tags)
|
||||||
def matchPreviousLiteral(): ...
|
replaceHTMLEntity = replaced_by_pep8("replaceHTMLEntity", replace_html_entity)
|
||||||
|
infixNotation = replaced_by_pep8("infixNotation", infix_notation)
|
||||||
@replaced_by_pep8(match_previous_expr)
|
|
||||||
def matchPreviousExpr(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(one_of)
|
|
||||||
def oneOf(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(dict_of)
|
|
||||||
def dictOf(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(original_text_for)
|
|
||||||
def originalTextFor(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(nested_expr)
|
|
||||||
def nestedExpr(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(make_html_tags)
|
|
||||||
def makeHTMLTags(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(make_xml_tags)
|
|
||||||
def makeXMLTags(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(replace_html_entity)
|
|
||||||
def replaceHTMLEntity(): ...
|
|
||||||
|
|
||||||
@replaced_by_pep8(infix_notation)
|
|
||||||
def infixNotation(): ...
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
@ -173,42 +173,48 @@ class ParseResults:
|
||||||
):
|
):
|
||||||
self._tokdict: Dict[str, _ParseResultsWithOffset]
|
self._tokdict: Dict[str, _ParseResultsWithOffset]
|
||||||
self._modal = modal
|
self._modal = modal
|
||||||
if name is not None and name != "":
|
|
||||||
if isinstance(name, int):
|
if name is None or name == "":
|
||||||
name = str(name)
|
return
|
||||||
if not modal:
|
|
||||||
self._all_names = {name}
|
if isinstance(name, int):
|
||||||
self._name = name
|
name = str(name)
|
||||||
if toklist not in self._null_values:
|
|
||||||
if isinstance(toklist, (str_type, type)):
|
if not modal:
|
||||||
toklist = [toklist]
|
self._all_names = {name}
|
||||||
if asList:
|
|
||||||
if isinstance(toklist, ParseResults):
|
self._name = name
|
||||||
self[name] = _ParseResultsWithOffset(
|
|
||||||
ParseResults(toklist._toklist), 0
|
if toklist in self._null_values:
|
||||||
)
|
return
|
||||||
else:
|
|
||||||
self[name] = _ParseResultsWithOffset(
|
if isinstance(toklist, (str_type, type)):
|
||||||
ParseResults(toklist[0]), 0
|
toklist = [toklist]
|
||||||
)
|
|
||||||
self[name]._name = name
|
if asList:
|
||||||
else:
|
if isinstance(toklist, ParseResults):
|
||||||
try:
|
self[name] = _ParseResultsWithOffset(ParseResults(toklist._toklist), 0)
|
||||||
self[name] = toklist[0]
|
else:
|
||||||
except (KeyError, TypeError, IndexError):
|
self[name] = _ParseResultsWithOffset(ParseResults(toklist[0]), 0)
|
||||||
if toklist is not self:
|
self[name]._name = name
|
||||||
self[name] = toklist
|
return
|
||||||
else:
|
|
||||||
self._name = name
|
try:
|
||||||
|
self[name] = toklist[0]
|
||||||
|
except (KeyError, TypeError, IndexError):
|
||||||
|
if toklist is not self:
|
||||||
|
self[name] = toklist
|
||||||
|
else:
|
||||||
|
self._name = name
|
||||||
|
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if isinstance(i, (int, slice)):
|
if isinstance(i, (int, slice)):
|
||||||
return self._toklist[i]
|
return self._toklist[i]
|
||||||
else:
|
|
||||||
if i not in self._all_names:
|
if i not in self._all_names:
|
||||||
return self._tokdict[i][-1][0]
|
return self._tokdict[i][-1][0]
|
||||||
else:
|
|
||||||
return ParseResults([v[0] for v in self._tokdict[i]])
|
return ParseResults([v[0] for v in self._tokdict[i]])
|
||||||
|
|
||||||
def __setitem__(self, k, v, isinstance=isinstance):
|
def __setitem__(self, k, v, isinstance=isinstance):
|
||||||
if isinstance(v, _ParseResultsWithOffset):
|
if isinstance(v, _ParseResultsWithOffset):
|
||||||
|
@ -226,27 +232,28 @@ class ParseResults:
|
||||||
sub._parent = self
|
sub._parent = self
|
||||||
|
|
||||||
def __delitem__(self, i):
|
def __delitem__(self, i):
|
||||||
if isinstance(i, (int, slice)):
|
if not isinstance(i, (int, slice)):
|
||||||
mylen = len(self._toklist)
|
|
||||||
del self._toklist[i]
|
|
||||||
|
|
||||||
# convert int to slice
|
|
||||||
if isinstance(i, int):
|
|
||||||
if i < 0:
|
|
||||||
i += mylen
|
|
||||||
i = slice(i, i + 1)
|
|
||||||
# get removed indices
|
|
||||||
removed = list(range(*i.indices(mylen)))
|
|
||||||
removed.reverse()
|
|
||||||
# fixup indices in token dictionary
|
|
||||||
for name, occurrences in self._tokdict.items():
|
|
||||||
for j in removed:
|
|
||||||
for k, (value, position) in enumerate(occurrences):
|
|
||||||
occurrences[k] = _ParseResultsWithOffset(
|
|
||||||
value, position - (position > j)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
del self._tokdict[i]
|
del self._tokdict[i]
|
||||||
|
return
|
||||||
|
|
||||||
|
mylen = len(self._toklist)
|
||||||
|
del self._toklist[i]
|
||||||
|
|
||||||
|
# convert int to slice
|
||||||
|
if isinstance(i, int):
|
||||||
|
if i < 0:
|
||||||
|
i += mylen
|
||||||
|
i = slice(i, i + 1)
|
||||||
|
# get removed indices
|
||||||
|
removed = list(range(*i.indices(mylen)))
|
||||||
|
removed.reverse()
|
||||||
|
# fixup indices in token dictionary
|
||||||
|
for occurrences in self._tokdict.values():
|
||||||
|
for j in removed:
|
||||||
|
for k, (value, position) in enumerate(occurrences):
|
||||||
|
occurrences[k] = _ParseResultsWithOffset(
|
||||||
|
value, position - (position > j)
|
||||||
|
)
|
||||||
|
|
||||||
def __contains__(self, k) -> bool:
|
def __contains__(self, k) -> bool:
|
||||||
return k in self._tokdict
|
return k in self._tokdict
|
||||||
|
@ -376,7 +383,7 @@ class ParseResults:
|
||||||
"""
|
"""
|
||||||
self._toklist.insert(index, ins_string)
|
self._toklist.insert(index, ins_string)
|
||||||
# fixup indices in token dictionary
|
# fixup indices in token dictionary
|
||||||
for name, occurrences in self._tokdict.items():
|
for occurrences in self._tokdict.values():
|
||||||
for k, (value, position) in enumerate(occurrences):
|
for k, (value, position) in enumerate(occurrences):
|
||||||
occurrences[k] = _ParseResultsWithOffset(
|
occurrences[k] = _ParseResultsWithOffset(
|
||||||
value, position + (position > index)
|
value, position + (position > index)
|
||||||
|
@ -652,58 +659,52 @@ class ParseResults:
|
||||||
NL = "\n"
|
NL = "\n"
|
||||||
out.append(indent + str(self.as_list()) if include_list else "")
|
out.append(indent + str(self.as_list()) if include_list else "")
|
||||||
|
|
||||||
if full:
|
if not full:
|
||||||
if self.haskeys():
|
return "".join(out)
|
||||||
items = sorted((str(k), v) for k, v in self.items())
|
|
||||||
for k, v in items:
|
if self.haskeys():
|
||||||
if out:
|
items = sorted((str(k), v) for k, v in self.items())
|
||||||
out.append(NL)
|
for k, v in items:
|
||||||
out.append(f"{indent}{(' ' * _depth)}- {k}: ")
|
if out:
|
||||||
if isinstance(v, ParseResults):
|
out.append(NL)
|
||||||
if v:
|
out.append(f"{indent}{(' ' * _depth)}- {k}: ")
|
||||||
out.append(
|
if not isinstance(v, ParseResults):
|
||||||
v.dump(
|
out.append(repr(v))
|
||||||
indent=indent,
|
continue
|
||||||
full=full,
|
|
||||||
include_list=include_list,
|
if not v:
|
||||||
_depth=_depth + 1,
|
out.append(str(v))
|
||||||
)
|
continue
|
||||||
)
|
|
||||||
else:
|
out.append(
|
||||||
out.append(str(v))
|
v.dump(
|
||||||
else:
|
indent=indent,
|
||||||
out.append(repr(v))
|
full=full,
|
||||||
if any(isinstance(vv, ParseResults) for vv in self):
|
include_list=include_list,
|
||||||
v = self
|
_depth=_depth + 1,
|
||||||
for i, vv in enumerate(v):
|
)
|
||||||
if isinstance(vv, ParseResults):
|
)
|
||||||
out.append(
|
if not any(isinstance(vv, ParseResults) for vv in self):
|
||||||
"\n{}{}[{}]:\n{}{}{}".format(
|
return "".join(out)
|
||||||
indent,
|
|
||||||
(" " * (_depth)),
|
v = self
|
||||||
i,
|
incr = " "
|
||||||
indent,
|
nl = "\n"
|
||||||
(" " * (_depth + 1)),
|
for i, vv in enumerate(v):
|
||||||
vv.dump(
|
if isinstance(vv, ParseResults):
|
||||||
indent=indent,
|
vv_dump = vv.dump(
|
||||||
full=full,
|
indent=indent,
|
||||||
include_list=include_list,
|
full=full,
|
||||||
_depth=_depth + 1,
|
include_list=include_list,
|
||||||
),
|
_depth=_depth + 1,
|
||||||
)
|
)
|
||||||
)
|
out.append(
|
||||||
else:
|
f"{nl}{indent}{incr * _depth}[{i}]:{nl}{indent}{incr * (_depth + 1)}{vv_dump}"
|
||||||
out.append(
|
)
|
||||||
"\n%s%s[%d]:\n%s%s%s"
|
else:
|
||||||
% (
|
out.append(
|
||||||
indent,
|
f"{nl}{indent}{incr * _depth}[{i}]:{nl}{indent}{incr * (_depth + 1)}{vv}"
|
||||||
(" " * (_depth)),
|
)
|
||||||
i,
|
|
||||||
indent,
|
|
||||||
(" " * (_depth + 1)),
|
|
||||||
str(vv),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return "".join(out)
|
return "".join(out)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
# testing.py
|
# testing.py
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
import re
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
|
||||||
from .core import (
|
from .core import (
|
||||||
ParserElement,
|
ParserElement,
|
||||||
ParseException,
|
ParseException,
|
||||||
|
@ -49,23 +51,23 @@ class pyparsing_test:
|
||||||
self._save_context["default_whitespace"] = ParserElement.DEFAULT_WHITE_CHARS
|
self._save_context["default_whitespace"] = ParserElement.DEFAULT_WHITE_CHARS
|
||||||
self._save_context["default_keyword_chars"] = Keyword.DEFAULT_KEYWORD_CHARS
|
self._save_context["default_keyword_chars"] = Keyword.DEFAULT_KEYWORD_CHARS
|
||||||
|
|
||||||
self._save_context[
|
self._save_context["literal_string_class"] = (
|
||||||
"literal_string_class"
|
ParserElement._literalStringClass
|
||||||
] = ParserElement._literalStringClass
|
)
|
||||||
|
|
||||||
self._save_context["verbose_stacktrace"] = ParserElement.verbose_stacktrace
|
self._save_context["verbose_stacktrace"] = ParserElement.verbose_stacktrace
|
||||||
|
|
||||||
self._save_context["packrat_enabled"] = ParserElement._packratEnabled
|
self._save_context["packrat_enabled"] = ParserElement._packratEnabled
|
||||||
if ParserElement._packratEnabled:
|
if ParserElement._packratEnabled:
|
||||||
self._save_context[
|
self._save_context["packrat_cache_size"] = (
|
||||||
"packrat_cache_size"
|
ParserElement.packrat_cache.size
|
||||||
] = ParserElement.packrat_cache.size
|
)
|
||||||
else:
|
else:
|
||||||
self._save_context["packrat_cache_size"] = None
|
self._save_context["packrat_cache_size"] = None
|
||||||
self._save_context["packrat_parse"] = ParserElement._parse
|
self._save_context["packrat_parse"] = ParserElement._parse
|
||||||
self._save_context[
|
self._save_context["recursion_enabled"] = (
|
||||||
"recursion_enabled"
|
ParserElement._left_recursion_enabled
|
||||||
] = ParserElement._left_recursion_enabled
|
)
|
||||||
|
|
||||||
self._save_context["__diag__"] = {
|
self._save_context["__diag__"] = {
|
||||||
name: getattr(__diag__, name) for name in __diag__._all_names
|
name: getattr(__diag__, name) for name in __diag__._all_names
|
||||||
|
@ -180,49 +182,52 @@ class pyparsing_test:
|
||||||
"""
|
"""
|
||||||
run_test_success, run_test_results = run_tests_report
|
run_test_success, run_test_results = run_tests_report
|
||||||
|
|
||||||
if expected_parse_results is not None:
|
if expected_parse_results is None:
|
||||||
merged = [
|
self.assertTrue(
|
||||||
(*rpt, expected)
|
run_test_success, msg=msg if msg is not None else "failed runTests"
|
||||||
for rpt, expected in zip(run_test_results, expected_parse_results)
|
)
|
||||||
]
|
return
|
||||||
for test_string, result, expected in merged:
|
|
||||||
# expected should be a tuple containing a list and/or a dict or an exception,
|
merged = [
|
||||||
# and optional failure message string
|
(*rpt, expected)
|
||||||
# an empty tuple will skip any result validation
|
for rpt, expected in zip(run_test_results, expected_parse_results)
|
||||||
fail_msg = next(
|
]
|
||||||
(exp for exp in expected if isinstance(exp, str)), None
|
for test_string, result, expected in merged:
|
||||||
|
# expected should be a tuple containing a list and/or a dict or an exception,
|
||||||
|
# and optional failure message string
|
||||||
|
# an empty tuple will skip any result validation
|
||||||
|
fail_msg = next((exp for exp in expected if isinstance(exp, str)), None)
|
||||||
|
expected_exception = next(
|
||||||
|
(
|
||||||
|
exp
|
||||||
|
for exp in expected
|
||||||
|
if isinstance(exp, type) and issubclass(exp, Exception)
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if expected_exception is not None:
|
||||||
|
with self.assertRaises(
|
||||||
|
expected_exception=expected_exception, msg=fail_msg or msg
|
||||||
|
):
|
||||||
|
if isinstance(result, Exception):
|
||||||
|
raise result
|
||||||
|
else:
|
||||||
|
expected_list = next(
|
||||||
|
(exp for exp in expected if isinstance(exp, list)), None
|
||||||
)
|
)
|
||||||
expected_exception = next(
|
expected_dict = next(
|
||||||
(
|
(exp for exp in expected if isinstance(exp, dict)), None
|
||||||
exp
|
|
||||||
for exp in expected
|
|
||||||
if isinstance(exp, type) and issubclass(exp, Exception)
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
if expected_exception is not None:
|
if (expected_list, expected_dict) != (None, None):
|
||||||
with self.assertRaises(
|
self.assertParseResultsEquals(
|
||||||
expected_exception=expected_exception, msg=fail_msg or msg
|
result,
|
||||||
):
|
expected_list=expected_list,
|
||||||
if isinstance(result, Exception):
|
expected_dict=expected_dict,
|
||||||
raise result
|
msg=fail_msg or msg,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
expected_list = next(
|
# warning here maybe?
|
||||||
(exp for exp in expected if isinstance(exp, list)), None
|
print(f"no validation for {test_string!r}")
|
||||||
)
|
|
||||||
expected_dict = next(
|
|
||||||
(exp for exp in expected if isinstance(exp, dict)), None
|
|
||||||
)
|
|
||||||
if (expected_list, expected_dict) != (None, None):
|
|
||||||
self.assertParseResultsEquals(
|
|
||||||
result,
|
|
||||||
expected_list=expected_list,
|
|
||||||
expected_dict=expected_dict,
|
|
||||||
msg=fail_msg or msg,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# warning here maybe?
|
|
||||||
print(f"no validation for {test_string!r}")
|
|
||||||
|
|
||||||
# do this last, in case some specific test results can be reported instead
|
# do this last, in case some specific test results can be reported instead
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
@ -230,9 +235,18 @@ class pyparsing_test:
|
||||||
)
|
)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def assertRaisesParseException(self, exc_type=ParseException, msg=None):
|
def assertRaisesParseException(
|
||||||
with self.assertRaises(exc_type, msg=msg):
|
self, exc_type=ParseException, expected_msg=None, msg=None
|
||||||
yield
|
):
|
||||||
|
if expected_msg is not None:
|
||||||
|
if isinstance(expected_msg, str):
|
||||||
|
expected_msg = re.escape(expected_msg)
|
||||||
|
with self.assertRaisesRegex(exc_type, expected_msg, msg=msg) as ctx:
|
||||||
|
yield ctx
|
||||||
|
|
||||||
|
else:
|
||||||
|
with self.assertRaises(exc_type, msg=msg) as ctx:
|
||||||
|
yield ctx
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def with_line_numbers(
|
def with_line_numbers(
|
||||||
|
|
|
@ -102,17 +102,10 @@ class unicode_set:
|
||||||
all characters in this range that are valid identifier body characters,
|
all characters in this range that are valid identifier body characters,
|
||||||
plus the digits 0-9, and · (Unicode MIDDLE DOT)
|
plus the digits 0-9, and · (Unicode MIDDLE DOT)
|
||||||
"""
|
"""
|
||||||
return "".join(
|
identifier_chars = set(
|
||||||
sorted(
|
c for c in cls._chars_for_ranges if ("_" + c).isidentifier()
|
||||||
set(
|
|
||||||
cls.identchars
|
|
||||||
+ "0123456789·"
|
|
||||||
+ "".join(
|
|
||||||
[c for c in cls._chars_for_ranges if ("_" + c).isidentifier()]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
return "".join(sorted(identifier_chars | set(cls.identchars + "0123456789·")))
|
||||||
|
|
||||||
@_lazyclassproperty
|
@_lazyclassproperty
|
||||||
def identifier(cls):
|
def identifier(cls):
|
||||||
|
|
|
@ -237,7 +237,7 @@ def _flatten(ll: list) -> list:
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def _make_synonym_function(compat_name: str, fn: C) -> C:
|
def replaced_by_pep8(compat_name: str, fn: C) -> C:
|
||||||
# In a future version, uncomment the code in the internal _inner() functions
|
# In a future version, uncomment the code in the internal _inner() functions
|
||||||
# to begin emitting DeprecationWarnings.
|
# to begin emitting DeprecationWarnings.
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ def _make_synonym_function(compat_name: str, fn: C) -> C:
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def _inner(self, *args, **kwargs):
|
def _inner(self, *args, **kwargs):
|
||||||
# warnings.warn(
|
# warnings.warn(
|
||||||
# f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=3
|
# f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=2
|
||||||
# )
|
# )
|
||||||
return fn(self, *args, **kwargs)
|
return fn(self, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ def _make_synonym_function(compat_name: str, fn: C) -> C:
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
def _inner(*args, **kwargs):
|
def _inner(*args, **kwargs):
|
||||||
# warnings.warn(
|
# warnings.warn(
|
||||||
# f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=3
|
# f"Deprecated - use {fn.__name__}", DeprecationWarning, stacklevel=2
|
||||||
# )
|
# )
|
||||||
return fn(*args, **kwargs)
|
return fn(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -275,10 +275,3 @@ def _make_synonym_function(compat_name: str, fn: C) -> C:
|
||||||
_inner.__kwdefaults__ = None
|
_inner.__kwdefaults__ = None
|
||||||
_inner.__qualname__ = fn.__qualname__
|
_inner.__qualname__ = fn.__qualname__
|
||||||
return cast(C, _inner)
|
return cast(C, _inner)
|
||||||
|
|
||||||
|
|
||||||
def replaced_by_pep8(fn: C) -> Callable[[Callable], C]:
|
|
||||||
"""
|
|
||||||
Decorator for pre-PEP8 compatibility synonyms, to link them to the new function.
|
|
||||||
"""
|
|
||||||
return lambda other: _make_synonym_function(other.__name__, fn)
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ plexapi==4.15.10
|
||||||
portend==3.2.0
|
portend==3.2.0
|
||||||
profilehooks==1.12.0
|
profilehooks==1.12.0
|
||||||
PyJWT==2.8.0
|
PyJWT==2.8.0
|
||||||
pyparsing==3.1.1
|
pyparsing==3.1.2
|
||||||
python-dateutil==2.9.0.post0
|
python-dateutil==2.9.0.post0
|
||||||
python-twitter==3.5
|
python-twitter==3.5
|
||||||
pytz==2024.1
|
pytz==2024.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue