HEX
Server: Apache
System: Linux sg2plmcpnl492417.prod.sin2.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: nyiet8349bzl (9207396)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/python38/lib/python3.8/site-packages/pip/_vendor/pyparsing/__pycache__/results.cpython-38.pyc
U

��eDh�@s�UddlmZmZmZmZmZmZddlZddlm	Z	m
Z
mZmZm
Z
eefZe	edfed<edd�dD��ZGd	d
�d
�ZGdd�d�Ze�e�e�e�dS)
�)�MutableMapping�Mapping�MutableSequence�Iterator�Sequence�	ContainerN)�Tuple�Any�Dict�Set�List.�str_typeccs|]
}|VqdS�N�)�.0�_rr�A/tmp/pip-unpacked-wheel-uzdrexel/pip/_vendor/pyparsing/results.py�	<genexpr>srrc@sLeZdZUedefed<dgZded�dd�Zdd�Zdd	�Z	d
d�Z
dS)
�_ParseResultsWithOffset�ParseResults�tup)�p1�p2cCs||f|_dSr�r)�selfrrrrr�__init__sz _ParseResultsWithOffset.__init__cCs
|j|Srr�r�irrr�__getitem__sz#_ParseResultsWithOffset.__getitem__cCs|jSrr�rrrr�__getstate__sz$_ParseResultsWithOffset.__getstate__cGs|d|_dS�Nrr)r�argsrrr�__setstate__sz$_ParseResultsWithOffset.__setstate__N)�__name__�
__module__�__qualname__r�int�__annotations__�	__slots__rrr r#rrrrrs
rc@sLeZdZUdZdgdfZeedfed<eed<ded<e	eed<e
ed	<eeed
<eeefed<dZ
Gd
d�de�Zdbdd�Zddddefdd�Zdd�Zefdd�Zdd�Ze
d�dd�Zed�dd�Ze
d�dd �Zed�d!d"�Zed�d#d$�Zd%d&�Zd'd(�Zd)d*�Ze
d�d+d,�Zd-d.�Z dcd/d0�Z!d1d2�Z"d3d4�Z#d5d6�Z$d7d8�Z%d9d:�Z&ddd;�d<d=�Z'ddd;�d>d?�Z(dd�d@dA�Z)ed�dBdC�Z*ed�dDdE�Z+dddGdH�Z,ed�dIdJ�Z-e.d�dKdL�Z/dd�dMdN�Z0dd�dOdP�Z1dQdR�Z2deed�dTdU�Z3dVdW�Z4dXdY�Z5dZd[�Z6d\d]�Z7d^d_�Z8e9dfdd�d`da��Z:e-Z;e/Z<e2Z=dS)gra{Structured parse results, to provide multiple means of access to
    the parsed data:

    - as a list (``len(results)``)
    - by list index (``results[0], results[1]``, etc.)
    - by attribute (``results.<results_name>`` - see :class:`ParserElement.set_results_name`)

    Example::

        integer = Word(nums)
        date_str = (integer.set_results_name("year") + '/'
                    + integer.set_results_name("month") + '/'
                    + integer.set_results_name("day"))
        # equivalent form:
        # date_str = (integer("year") + '/'
        #             + integer("month") + '/'
        #             + integer("day"))

        # parse_string returns a ParseResults object
        result = date_str.parse_string("1999/12/31")

        def test(s, fn=repr):
            print(f"{s} -> {fn(eval(s))}")
        test("list(result)")
        test("result[0]")
        test("result['month']")
        test("result.day")
        test("'month' in result")
        test("'minutes' in result")
        test("result.dump()", str)

    prints::

        list(result) -> ['1999', '/', '12', '/', '31']
        result[0] -> '1999'
        result['month'] -> '12'
        result.day -> '31'
        'month' in result -> True
        'minutes' in result -> False
        result.dump() -> ['1999', '/', '12', '/', '31']
        - day: '31'
        - month: '12'
        - year: '1999'
    Nr.�_null_values�_name�_parent�
_all_names�_modal�_toklist�_tokdict)r+r,r-r.r/r0c@seZdZdZddd�ZdS)zParseResults.Lista�
        Simple wrapper class to distinguish parsed list results that should be preserved
        as actual Python lists, instead of being converted to :class:`ParseResults`::

            LBRACK, RBRACK = map(pp.Suppress, "[]")
            element = pp.Forward()
            item = ppc.integer
            element_list = LBRACK + pp.DelimitedList(element) + RBRACK

            # add parse actions to convert from ParseResults to actual Python collection types
            def as_python_list(t):
                return pp.ParseResults.List(t.as_list())
            element_list.add_parse_action(as_python_list)

            element <<= item | element_list

            element.run_tests('''
                100
                [2,3,4]
                [[2, 1],3,4]
                [(2, 1),3,4]
                (2,3,4)
                ''', post_parse=lambda s, r: (r[0], type(r[0])))

        prints::

            100
            (100, <class 'int'>)

            [2,3,4]
            ([2, 3, 4], <class 'list'>)

            [[2, 1],3,4]
            ([[2, 1], 3, 4], <class 'list'>)

        (Used internally by :class:`Group` when `aslist=True`.)
        NcCs:|dkrg}t|t�s0t|j�dt|�j����t�|�S)Nz* may only be constructed with a list, not )�
isinstance�list�	TypeErrorr$�type�__new__)�clsZ	containedrrrr5�s
�zParseResults.List.__new__)N)r$r%r&�__doc__r5rrrrrbs&rcKs�t|t�r|St�|�}d|_d|_t�|_|dkr<g|_n<t|t	t
f�rpt|tj�rd|dd�gnt	|�|_n|g|_t�|_
|Sr)r1r�objectr5r+r,�setr-r/r2�_generator_typer�dictr0)r6�toklist�name�kwargsrrrrr5�s 


��zParseResults.__new__Tc
Cs�|||_|dk	r�|dkr�||t�r,t|�}|s8|h|_||_||jkr�||ttf�r\|g}|r�||t�r�t	t|j
�d�||<nt	t|d�d�||<|||_nDz|d||<Wn2ttt
fk
r�||k	r�|||<n||_YnXdS)N�r)r.r'�strr-r+r*r
r4rrr/�KeyErrorr3�
IndexError)rr<r=�asList�modalr1rrrr�s8


�

�
zParseResults.__init__cCsPt|ttf�r|j|S||jkr4|j|ddStdd�|j|D��SdS)N���rcSsg|]}|d�qS)rr�r�vrrr�
<listcomp>�sz,ParseResults.__getitem__.<locals>.<listcomp>)r1r'�slicer/r-r0rrrrrr�s


zParseResults.__getitem__cCs�||t�r0|j�|t��|g|j|<|d}nD||ttf�rN||j|<|}n&|j�|t��t|d�g|j|<|}||t�r�||_dSr!)	rr0�getr2r'rIr/rr,)r�krGr1�subrrr�__setitem__�s


�
zParseResults.__setitem__c
Cs�t|ttf�r�t|j�}|j|=t|t�rH|dkr:||7}t||d�}tt|�|���}|��|j	�
�D]>\}}|D]0}t|�D]"\}\}}	t||	|	|k�||<q�qxqln|j	|=dS)Nr�)
r1r'rI�lenr/r2�range�indices�reverser0�items�	enumerater)
rr�mylen�removedr=�occurrences�jrK�value�positionrrr�__delitem__�s"


�zParseResults.__delitem__)�returncCs
||jkSr�r0)rrKrrr�__contains__�szParseResults.__contains__cCs
t|j�Sr)rOr/rrrr�__len__�szParseResults.__len__cCs|jp
|jSr)r/r0rrrr�__bool__szParseResults.__bool__cCs
t|j�Sr��iterr/rrrr�__iter__szParseResults.__iter__cCst|jddd��S)NrErarrrr�__reversed__szParseResults.__reversed__cCs
t|j�Sr)rbr0rrrr�keys
szParseResults.keyscs�fdd����D�S)Nc3s|]}�|VqdSrr�rrKrrrrsz&ParseResults.values.<locals>.<genexpr>�rerrrr�values
szParseResults.valuescs�fdd����D�S)Nc3s|]}|�|fVqdSrrrfrrrrsz%ParseResults.items.<locals>.<genexpr>rgrrrrrSszParseResults.itemscCs
|jS)z�
        Since ``keys()`` returns an iterator, this method is helpful in bypassing
        code that looks for the existence of any defined results names.r]rrrr�haskeysszParseResults.haskeyscOs�|s
dg}|��D],\}}|dkr0|d|f}qtd|����qt|dt�sft|�dksf|d|kr�|d}||}||=|S|d}|SdS)a�
        Removes and returns item at specified index (default= ``last``).
        Supports both ``list`` and ``dict`` semantics for ``pop()``. If
        passed no argument or an integer argument, it will use ``list``
        semantics and pop tokens from the list of parsed tokens. If passed
        a non-integer argument (most likely a string), it will use ``dict``
        semantics and pop the corresponding value from any defined results
        names. A second default return value argument is supported, just as in
        ``dict.pop()``.

        Example::

            numlist = Word(nums)[...]
            print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

            def remove_first(tokens):
                tokens.pop(0)
            numlist.add_parse_action(remove_first)
            print(numlist.parse_string("0 123 321")) # -> ['123', '321']

            label = Word(alphas)
            patt = label("LABEL") + Word(nums)[1, ...]
            print(patt.parse_string("AAB 123 321").dump())

            # Use pop() in a parse action to remove named result (note that corresponding value is not
            # removed from list form of results)
            def remove_LABEL(tokens):
                tokens.pop("LABEL")
                return tokens
            patt.add_parse_action(remove_LABEL)
            print(patt.parse_string("AAB 123 321").dump())

        prints::

            ['AAB', '123', '321']
            - LABEL: 'AAB'

            ['AAB', '123', '321']
        rE�defaultrz)pop() got an unexpected keyword argument rNN)rSr3r1r'rO)rr"r>rKrG�index�ret�defaultvaluerrr�pops(&zParseResults.popcCs||kr||S|SdS)a^
        Returns named result matching the given key, or if there is no
        such name, then returns the given ``default_value`` or ``None`` if no
        ``default_value`` is specified.

        Similar to ``dict.get()``.

        Example::

            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

            result = date_str.parse_string("1999/12/31")
            print(result.get("year")) # -> '1999'
            print(result.get("hour", "not specified")) # -> 'not specified'
            print(result.get("hour")) # -> None
        Nr)r�key�
default_valuerrrrJQszParseResults.getcCsR|j�||�|j��D]4\}}t|�D]"\}\}}t||||k�||<q(qdS)a;
        Inserts new element at location index in the list of parsed tokens.

        Similar to ``list.insert()``.

        Example::

            numlist = Word(nums)[...]
            print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

            # use a parse action to insert the parse location in the front of the parsed results
            def insert_locn(locn, tokens):
                tokens.insert(0, locn)
            numlist.add_parse_action(insert_locn)
            print(numlist.parse_string("0 123 321")) # -> [0, '0', '123', '321']
        N)r/�insertr0rSrTr)rrkZ
ins_stringr=rWrKrYrZrrrrqhs
�zParseResults.insertcCs|j�|�dS)a
        Add single element to end of ``ParseResults`` list of elements.

        Example::

            numlist = Word(nums)[...]
            print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321']

            # use a parse action to compute the sum of the parsed integers, and add it to the end
            def append_sum(tokens):
                tokens.append(sum(map(int, tokens)))
            numlist.add_parse_action(append_sum)
            print(numlist.parse_string("0 123 321")) # -> ['0', '123', '321', 444]
        N)r/�append)r�itemrrrrr�szParseResults.appendcCs&t|t�r|�|�n|j�|�dS)a
        Add sequence of elements to end of ``ParseResults`` list of elements.

        Example::

            patt = Word(alphas)[1, ...]

            # use a parse action to append the reverse of the matched strings, to make a palindrome
            def make_palindrome(tokens):
                tokens.extend(reversed([t[::-1] for t in tokens]))
                return ''.join(tokens)
            patt.add_parse_action(make_palindrome)
            print(patt.parse_string("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl'
        N)r1r�__iadd__r/�extend)r�itemseqrrrru�s
zParseResults.extendcCs|jdd�=|j��dS)z7
        Clear all elements and results names.
        N)r/r0�clearrrrrrw�szParseResults.clearcCs8z
||WStk
r2|�d�r,t|��YdSXdS)N�__r?)rA�
startswith�AttributeError)rr=rrr�__getattr__�s

zParseResults.__getattr__)�otherr\cCs|��}||7}|Sr)�copy)rr|rlrrr�__add__�szParseResults.__add__cs�|s|S|jrnt|j���fdd��|j��}�fdd�|D�}|D](\}}|||<t|dt�rD||d_qD|j|j7_|j|jO_|S)Ncs|dkr�S|�Sr!r)�a)�offsetrr�<lambda>��z'ParseResults.__iadd__.<locals>.<lambda>c	s4g|],\}}|D]}|t|d�|d��f�qqS)rrN)r)rrK�vlistrG)�	addoffsetrrrH�s�z)ParseResults.__iadd__.<locals>.<listcomp>r)r0rOr/rSr1rr,r-)rr|�
otheritems�otherdictitemsrKrGr)r�r�rrt�s 


�zParseResults.__iadd__cCs&t|t�r|dkr|��S||SdSr!)r1r'r})rr|rrr�__radd__�szParseResults.__radd__cCs"t|�j�d|j�d|���d�S)N�(�, �))r4r$r/�as_dictrrrr�__repr__�szParseResults.__repr__cCsdd�dd�|jD��dS)N�[r�cSs&g|]}t|t�rt|�nt|��qSr)r1rr@�repr)rrrrrrH�s�z(ParseResults.__str__.<locals>.<listcomp>�])�joinr/rrrr�__str__�s�����zParseResults.__str__r?cCsLg}|jD]<}|r |r |�|�t|t�r8||��7}q
|�t|��q
|Sr)r/rrr1r�
_asStringListr@)r�sep�outrsrrrr��s


zParseResults._asStringListcCsdd�|jD�S)ax
        Returns the parse results as a nested list of matching tokens, all converted to strings.

        Example::

            patt = Word(alphas)[1, ...]
            result = patt.parse_string("sldkj lsdkj sldkj")
            # even though the result prints in string-like form, it is actually a pyparsing ParseResults
            print(type(result), result) # -> <class 'pyparsing.ParseResults'> ['sldkj', 'lsdkj', 'sldkj']

            # Use as_list() to create an actual list
            result_list = result.as_list()
            print(type(result_list), result_list) # -> <class 'list'> ['sldkj', 'lsdkj', 'sldkj']
        cSs"g|]}t|t�r|��n|�qSr)r1r�as_list)r�resrrrrHs�z(ParseResults.as_list.<locals>.<listcomp>)r/rrrrr��s�zParseResults.as_listcs&�fdd��t�fdd�|��D��S)a�
        Returns the named parse results as a nested dictionary.

        Example::

            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

            result = date_str.parse_string('12/31/1999')
            print(type(result), repr(result)) # -> <class 'pyparsing.ParseResults'> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]})

            result_dict = result.as_dict()
            print(type(result_dict), repr(result_dict)) # -> <class 'dict'> {'day': '1999', 'year': '12', 'month': '31'}

            # even though a ParseResults supports dict-like access, sometime you just need to have a dict
            import json
            print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable
            print(json.dumps(result.as_dict())) # -> {"month": "31", "day": "1999", "year": "12"}
        cs4t|t�r,|��r|��S�fdd�|D�S|SdS)Ncsg|]}�|��qSrrrF��to_itemrrrHsz9ParseResults.as_dict.<locals>.to_item.<locals>.<listcomp>)r1rrir���objr�rrr�s
"z%ParseResults.as_dict.<locals>.to_itemc3s|]\}}|�|�fVqdSrr�rrKrGr�rrr!sz'ParseResults.as_dict.<locals>.<genexpr>)r;rSrrr�rr�szParseResults.as_dictcCs:t|j�}|j��|_|j|_|j|jO_|j|_|S)a
        Returns a new shallow copy of a :class:`ParseResults` object. `ParseResults`
        items contained within the source are shared with the copy. Use
        :class:`ParseResults.deepcopy()` to create a copy with its own separate
        content values.
        )rr/r0r}r,r-r+)rrlrrrr}#s
zParseResults.copycCs�|��}t|j�D]�\}}t|t�r4|��|j|<qt|ttf�rDqt|t�r�t	|��|j|<}|�
�D]"\}}t|t�r�|��n|||<qjqt|t�rt	|�dd�|D��|j|<q|S)zL
        Returns a new deep copy of a :class:`ParseResults` object.
        css$|]}t|t�r|��n|VqdSr)r1r�deepcopyrFrrrrAsz(ParseResults.deepcopy.<locals>.<genexpr>)r}rTr/r1rr�r@�bytesrr4rSr)rrlrr��destrKrGrrrr�1s


�zParseResults.deepcopycs��jr�jS�jr:�j}|j��}t�fdd�|D�d�St��dkr�t�j�dkr�tt�j����dddkr�tt�j����SdSdS)a
        Returns the results name for this token expression. Useful when several
        different expressions might match at a particular location.

        Example::

            integer = Word(nums)
            ssn_expr = Regex(r"\d\d\d-\d\d-\d\d\d\d")
            house_number_expr = Suppress('#') + Word(nums, alphanums)
            user_data = (Group(house_number_expr)("house_number")
                        | Group(ssn_expr)("ssn")
                        | Group(integer)("age"))
            user_info = user_data[1, ...]

            result = user_info.parse_string("22 111-22-3333 #221B")
            for item in result:
                print(item.get_name(), ':', item[0])

        prints::

            age : 22
            ssn : 111-22-3333
            house_number : 221B
        c3s,|]$\}}|D]\}}|�kr|VqqdSrr)rrKr�rG�locrrrres
�z(ParseResults.get_name.<locals>.<genexpr>NrNr)rrE)	r+r,r0rS�nextrOrbrhre)r�parZparent_tokdict_itemsrrr�get_nameFs&

��

���zParseResults.get_namercCsrg}d}|�|r |t|���nd�|�rh|��r�tdd�|��D��}|D]~\}}	|rd|�|�|�|�d|�d|�d��t|	t�r�|	r�|�|	j||||dd	��q�|�t|	��qN|�t	|	��qNt
d
d�|D���rh|}	t|	�D]x\}
}t|t��r<|�d�|d||
|d|d|j||||dd	���q�|�d|d||
|d|dt|�f�q�d�
|�S)
aM
        Diagnostic method for listing out the contents of
        a :class:`ParseResults`. Accepts an optional ``indent`` argument so
        that this string can be embedded in a nested display of other data.

        Example::

            integer = Word(nums)
            date_str = integer("year") + '/' + integer("month") + '/' + integer("day")

            result = date_str.parse_string('1999/12/31')
            print(result.dump())

        prints::

            ['1999', '/', '12', '/', '31']
            - day: '31'
            - month: '12'
            - year: '1999'
        �
r?css|]\}}t|�|fVqdSr)r@r�rrrr�sz$ParseResults.dump.<locals>.<genexpr>z  z- z: rN)�indent�full�include_list�_depthcss|]}t|t�VqdSr)r1r)r�vvrrrr�sz
{}{}[{}]:
{}{}{}z
%s%s[%d]:
%s%s%s)rrr@r�ri�sortedrSr1r�dumpr��anyrT�formatr�)rr�r�r�r�r��NLrSrKrGrr�rrrr�vsj

��	
���
���zParseResults.dumpcOstj|��f|�|�dS)a$
        Pretty-printer for parsed results as a list, using the
        `pprint <https://docs.python.org/3/library/pprint.html>`_ module.
        Accepts additional positional or keyword args as defined for
        `pprint.pprint <https://docs.python.org/3/library/pprint.html#pprint.pprint>`_ .

        Example::

            ident = Word(alphas, alphanums)
            num = Word(nums)
            func = Forward()
            term = ident | num | Group('(' + func + ')')
            func <<= ident + Group(Optional(DelimitedList(term)))
            result = func.parse_string("fna a,b,(fnb c,d,200),100")
            result.pprint(width=40)

        prints::

            ['fna',
             ['a',
              'b',
              ['(', 'fnb', ['c', 'd', '200'], ')'],
              '100']]
        N)�pprintr�)rr"r>rrrr��szParseResults.pprintcCs|j|j��d|j|jffSr)r/r0r}r-r+rrrrr �s��zParseResults.__getstate__cCs*|\|_\|_}}|_t|�|_d|_dSr)r/r0r+r9r-r,)r�stater��inAccumNamesrrrr#�s
zParseResults.__setstate__cCs|j|jfSr)r/r+rrrr�__getnewargs__�szParseResults.__getnewargs__cCstt|��t|���Sr)�dirr4r2rerrrr�__dir__�szParseResults.__dir__cCsrdd�}|g�}|��D]>\}}t|t�r>||j||d�7}q|||g|||�d�7}q|dk	rn||g|d�}|S)z�
        Helper classmethod to construct a ``ParseResults`` from a ``dict``, preserving the
        name-value relations as results names. If an optional ``name`` argument is
        given, a nested ``ParseResults`` will be returned.
        cSs4zt|�Wntk
r"YdSXt|t�SdS)NF)rb�	Exceptionr1r
r�rrr�is_iterables
z+ParseResults.from_dict.<locals>.is_iterable)r=)r=rCN)rSr1r�	from_dict)r6r|r=r�rlrKrGrrrr��s	
zParseResults.from_dict)NN)N)r?)r?TTr)N)>r$r%r&r7r*rr	r(r@r�boolrr
r)r2r5r1rrrMr[r^r'r_r`rrcrdrerhrSrirnrJrqrrrurwr{r~rtr�r�r�r�r�r;r�r}r�r�r�r�r r#r�r��classmethodr�rC�asDict�getNamerrrrr"sv
-	2
�
!	8

0Pr)�collections.abcrrrrrrr��typingrr	r
rrr@r�r
r4r(r:rr�registerrrrr�<module>s ~