128
     +ˆÓÒÑ‚h@Ð¿Î ¤    +‹      µ“QOÛ0Çßù7?ì�&Áp<±¤Ò*•¶j3¡	ñàÄnb-‰#ûhW>=N“	&�Ð¤íÉgûçûßÿlóé"É~,'ð-»™Áòû×Ù4vŒx{– ¦Y:lœG'§ˆ“9VuŸw»]´;‹¬+1[aEM}Žžœ)(R¤˜8âýš8^i©ÂœÕZL[¥�Ý ÚòFépnïQé­)´ïcÒ6º±n?—ØZ¥OÆéÅ%ú‡|•3[í<Ç!{ÐÃQ�çVíû:Nÿ›fH}0&óƒt:Á©‚­¬MÙÆŒlÇ7M	Þ1CSØÖc^ËögTšYSÌî¦Éâ>pHUZp	•Ó›˜}IâùÕ"N™˜ËFs”¯37�¹fb&=Ac•Ù­Þ„×¼6�o'L&Õ¾p¦#cÛgƒÅ—V[ûN¯Ÿ‚ƒÊ½¤D½×YüÑŒåõj2ÏÒéjh‰êS<W÷on�‰¥tº%H�Ó…íÑà ö±Í}wõ{
cùÎ”1p¯’ÓßÇÃ+å8ü–'�}�       -ˆÓÒÑ‚hAÐ¿Î ¥    -‹      µ“QOÛ0Çßù7?ðFŽÓ´á±¤Ò*•¶*™¦iâÁ‰ÝÄZGöÑÒ}ú9M �¦IÛ“ÏöÏ÷¿ÿÙæïÒe’}_MáKv3‡Õ×ÏóYìñÛy‚˜fé°q�N§¬"ê>!îv»hwYWb¶ÆŠšú=9SP¤H1qÄû5q¼ÒR…8ªµ˜µJ?€Ý Ú{òFépnïQé­)´ïcÒ6º±n?“³	¶VéÓqþá#úû|$•3[í<Ç!}ÄQ‘çVíûB&ÿO4ä>X“ùA»�àTÁVÖ¦lcF¶c‚›¦ïŠ˜¡)lë1¯eû3*Í†�¬)f?fÉò.pHUZp	•Ó›˜]%ñâr§L,d£9Ê×™›À\31—ž ±ÊlŒVoÂ·|k~½�0˜TûÂ™ŽŒmŸPŸ[-lí;¼¾*÷œõ§nÈâE3V×ëé"Kgë¡%ªOñTÝ?ºB&VÒé– 5N¶G‡ƒÜq›ûîòq
cýÎ”1p¯’ÓÇÃ;å8|˜ßh8nV“    C   /ˆl–Ãa¾”Ê:”Ê�~ão\må1hß�þ_zGÖnQFë£(ÓÀþÌ„eð‰ÿÒ_ŠI|¥�+Wé3ž¯ÁÐ ?÷     /# helpers.py
import html.entities
import re
import typing

from . import __diag__
from .core import *
from .util import _bslash, _flatten, _escape_regex_range_chars


#
# global helpers
#
def delimited_list(
    expr: Union[str, ParserElement],
    delim: Union[str, ParserElement] = ",",
    combine: bool = False,
    min: typing.Optional[int] = None,
    max: typing.Optional[int] = None,
    *,
    allow_trailing_delim: bool = False,
) -> ParserElement:
    """Helper to define a delimited list of expressions - the delimiter
    defaults to ','. By default, the list elements and delimiters can
    have intervening whitespace, and comments, but this can be
    overridden by passing ``combine=True`` in the constructor. If
    ``combine`` is set to ``True``, the matching tokens are
    returned as a single token string, with the delimiters included;
    otherwise, the matching tokens are returned as a list of tokens,
    with the delimiters suppressed.

    If ``allow_trailing_delim`` is set to True, then the list may end with
    a delimiter.

    Example::

        delimited_list(Word(alphas)).parse_string("aa,bb,cc") # -> ['aa', 'bb', 'cc']
        delimited_list(Word(hexnums), delim=':', combine=True).parse_string("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE']
    """
    if isinstance(expr, str_type):
        expr = ParserElement._literalStringClass(expr)

    dlName = "{expr} [{delim} {expr}]...{end}".format(
        expr=str(expr.copy().streamline()),
        delim=str(delim),
        end=" [{}]".format(str(delim)) if allow_trailing_delim else "",
    )

    if not combine:
        delim = Suppress(delim)

    if min is not None:
        if min < 1:
            raise ValueError("min must be greater than 0")
        min -= 1
    if max is not None:
        if min is not None and max <= min:
            raise ValueError("max must be greater than, or equal to min")
        max -= 1
    delimited_list_expr = expr + (delim + expr)[min, max]

    if allow_trailing_delim:
        delimited_list_expr += Opt(delim)

    if combine:
        return Combine(delimited_list_expr).set_name(dlName)
    else:
        return delimited_list_expr.set_name(dlName)


def counted_array(
    expr: ParserElement,
    int_expr: typing.Optional[ParserElement] = None,
    *,
    intExpr: typing.Optional[ParserElement] = None,
) -> ParserElement:
    """Helper to define a counted list of expressions.

    This helper defines a pattern of the form::

        integer expr expr expr...

    where the leading integer tells how many expr expressions follow.
    The matched tokens returns the array of expr tokens as a list - the
    leading count token is suppressed.

    If ``int_expr`` is specified, it should be a pyparsing expression
    that produces an integer value.

    Example::

        counted_array(Word(alphas)).parse_string('2 ab cd ef')  # -> ['ab', 'cd']

        # in this parser, the leading integer value is given in binary,
        # '10' indicating that 2 values are in the array
        binary_constant = Word('01').set_parse_action(lambda t: int(t[0], 2))
        count