HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/pip/_vendor/pyparsing/__pycache__/results.cpython-310.pyc
o

@%Ne�b�@s�UddlmZmZmZmZddlZddlmZddl	m
Z
mZee
fZe
edfed<edd�d	D��ZGd
d�d�ZGdd
�d
�Ze�e�e�e�dS)�)�MutableMapping�Mapping�MutableSequence�IteratorN)�ref)�Tuple�Any.�str_typeccs�|]}|VqdS�N�)�.0�_rr�?/usr/lib/python3/dist-packages/pip/_vendor/pyparsing/results.py�	<genexpr>s�rrc@s2eZdZdgZdd�Zdd�Zdd�Zdd	�Zd
S)�_ParseResultsWithOffset�tupcCs||f|_dSr
�r)�self�p1�p2rrr�__init__�z _ParseResultsWithOffset.__init__cCs
|j|Sr
r�r�irrr�__getitem__�
z#_ParseResultsWithOffset.__getitem__cCs|jSr
r�rrrr�__getstate__sz$_ParseResultsWithOffset.__getstate__cGs|d|_dS�Nrr)r�argsrrr�__setstate__rz$_ParseResultsWithOffset.__setstate__N)�__name__�
__module__�__qualname__�	__slots__rrrr rrrrrsrc@s�eZdZUdZdgddfZeedfed<gd�ZGdd	�d	e	�Z
dYd
d�Zddddefd
d�Z
dd�Zefdd�Zdd�Zdefdd�Zdefdd�Zdefdd�Zdefdd�Zdefdd�Zd d!�Zd"d#�Zd$d%�Zdefd&d'�Zd(d)�ZdZd*d+�Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"d4d5�Z#d[d6d7�Z$d[d8d9�Z%d[d:d;�Z&de'fd<d=�Z(de'fd>d?�Z)d\d@dA�Z*de	fdBdC�Z+de,fdDdE�Z-d[dFdG�Z.dHdI�Z/d]de'fdKdL�Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dUdV�Z5e6dZd[dWdX��Z7e+Z8e-Z9e/Z:dS)^�ParseResultsaStructured 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("{} -> {}".format(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
    N�r.�_null_values)�_name�_parent�
_all_names�_modal�_toklist�_tokdict�__weakref__c@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.delimited_list(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`.)
        NcCs8|durg}t|t�std�|jt|�j���t�|�S)Nz.{} may only be constructed with a list, not {})�
isinstance�list�	TypeError�formatr!�type�__new__)�cls�	containedrrrr4|s
�
zParseResults.List.__new__r
)r!r"r#�__doc__r4rrrr�ListUs&r8cKs�t|t�r|St�|�}d|_d|_t�|_|durg|_nt|t	t
f�r8t|tj�r2|dd�gnt	|�|_n|g|_t�|_
|Sr
)r/r%�objectr4r(r)�setr*r,r0�_generator_typer8�dictr-)r5�toklist�name�kwargsrrrrr4�s 


��zParseResults.__new__Tc
Cs�||_|duru|dkrw||t�rt|�}|s|h|_||_||jvry||ttf�r,|g}|rP||t�r>t	t|j
�d�||<nt	t|d�d�||<|||_dSz	|d||<WdSttt
fyt||urn|||<YdS||_YdSwdSdSdS)Nr&r)r+�int�strr*r(r'r	r3r%rr,�KeyErrorr1�
IndexError)rr=r>�asList�modalr/rrrr�s8




����zParseResults.__init__cCsLt|ttf�r|j|S||jvr|j|ddStdd�|j|D��S)N���rcSsg|]}|d�qS)rr�r�vrrr�
<listcomp>��z,ParseResults.__getitem__.<locals>.<listcomp>)r/r@�slicer,r*r-r%rrrrr�s


zParseResults.__getitem__cCs�||t�r|j�|t��|g|j|<|d}n"||ttf�r'||j|<|}n|j�|t��t|d�g|j|<|}||t�rFt|�|_	dSdSr)
rr-�getr0r@rKr,r%�wkrefr))r�krHr/�subrrr�__setitem__�s


�
�zParseResults.__setitem__c
Cs�t|ttf�rXt|j�}|j|=t|t�r$|dkr||7}t||d�}tt|�|���}|��|j	�
�D]\}}|D]}t|�D]\}\}}	t||	|	|k�||<qBq<q6dS|j	|=dS)Nr�)
r/r@rK�lenr,r0�range�indices�reverser-�items�	enumerater)
rr�mylen�removedr>�occurrences�jrN�value�positionrrr�__delitem__�s&


����zParseResults.__delitem__�returncCs
||jvSr
)r-)rrNrrr�__contains__�rzParseResults.__contains__cC�
t|j�Sr
)rRr,rrrr�__len__�rzParseResults.__len__cCs|jp|jSr
)r,r-rrrr�__bool__�szParseResults.__bool__cCrar
��iterr,rrrr�__iter__�rzParseResults.__iter__cCst|jddd��S)NrFrdrrrr�__reversed__�szParseResults.__reversed__cCrar
)rer-rrrr�keys�rzParseResults.keysc��fdd����D�S)Nc3s�|]}�|VqdSr
r�rrNrrrrs�z&ParseResults.values.<locals>.<genexpr>�rhrrrr�values�zParseResults.valuescri)Nc3s�|]	}|�|fVqdSr
rrjrrrrs�z%ParseResults.items.<locals>.<genexpr>rkrrrrrVrmzParseResults.itemscCra)z�
        Since ``keys()`` returns an iterator, this method is helpful in bypassing
        code that looks for the existence of any defined results names.)�boolr-rrrr�haskeyss
zParseResults.haskeyscOs�|sdg}|��D]\}}|dkr|d|f}q	td�|���t|dt�s2t|�dks2|d|vr?|d}||}||=|S|d}|S)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") + OneOrMore(Word(nums))
            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']
        rF�defaultrz-pop() got an unexpected keyword argument {!r}rQ)rVr1r2r/r@rR)rrr?rNrH�index�ret�defaultvaluerrr�pops(�&zParseResults.popcCs||vr||S|S)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
        r)r�key�
default_valuerrrrLFszParseResults.getcCsR|j�||�|j��D]\}}t|�D]\}\}}t||||k�||<qqdS)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,�insertr-rVrWr)rrq�
ins_stringr>rZrNr\r]rrrrw]s
���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�itemrrrryvszParseResults.appendcCs(t|t�r|�|�dS|j�|�dS)a!
        Add sequence of elements to end of ``ParseResults`` list of elements.

        Example::

            patt = OneOrMore(Word(alphas))

            # 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)r/r%�__iadd__r,�extend)r�itemseqrrrr|�s
zParseResults.extendcCs|jdd�=|j��dS)z7
        Clear all elements and results names.
        N)r,r-�clearrrrrr~�szParseResults.clearcCs2z||WSty|�d�rt|��YdSw)N�__r&)rB�
startswith�AttributeError)rr>rrr�__getattr__�s

�zParseResults.__getattr__cCs|��}||7}|Sr
)�copy)r�otherrrrrr�__add__�szParseResults.__add__cs�|jr5t|j���fdd��|j��}�fdd�|D�}|D]\}}|||<t|dt�r4t|�|d_q|j|j7_|j|jO_|S)Ncs|dkr�S|�Srr)�a)�offsetrr�<lambda>�rJz'ParseResults.__iadd__.<locals>.<lambda>c	s4g|]\}}|D]}|t|d�|d��f�qqS)rrQ)r)rrN�vlistrH)�	addoffsetrrrI�s���z)ParseResults.__iadd__.<locals>.<listcomp>r)	r-rRr,rVr/r%rMr)r*)rr��
otheritems�otherdictitemsrNrHr)r�r�rr{�s


��zParseResults.__iadd__cCs"t|t�r
|dkr
|��S||Sr)r/r@r�)rr�rrr�__radd__�szParseResults.__radd__cCsd�t|�j|j|���S)Nz{}({!r}, {}))r2r3r!r,�as_dictrrrr�__repr__�szParseResults.__repr__cCsdd�dd�|jD��dS)N�[z, cSs&g|]}t|t�r
t|�nt|��qSr)r/r%rA�repr)rrrrrrI�s��z(ParseResults.__str__.<locals>.<listcomp>�])�joinr,rrrr�__str__�s�����zParseResults.__str__cCsLg}|jD]}|r|r|�|�t|t�r||��7}q|�t|��q|Sr
)r,ryr/r%�
_asStringListrA)r�sep�outrzrrrr��s


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

        Example::

            patt = OneOrMore(Word(alphas))
            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)r/r%�as_list)r�resrrrrI�s��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"}
        cs0t|t�r|��r
|��S�fdd�|D�S|S)Ncsg|]}�|��qSrrrG��to_itemrrrIrJz9ParseResults.as_dict.<locals>.to_item.<locals>.<listcomp>)r/r%ror���objr�rrr�
s
"z%ParseResults.as_dict.<locals>.to_itemc3s �|]\}}|�|�fVqdSr
r�rrNrHr�rrr��z'ParseResults.as_dict.<locals>.<genexpr>)r<rVrrr�rr��szParseResults.as_dictcCs:t|j�}|j��|_|j|_|j|jO_|j|_|S)zG
        Returns a new copy of a :class:`ParseResults` object.
        )r%r,r-r�r)r*r()rrrrrrr�s
zParseResults.copycs�|jr|jS|jr|����fdd�}�r||�SdSt|�dkr@t|j�dkr@tt|j����dddvr@tt|j����SdS)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 = OneOrMore(user_data)

            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
        cst�fdd��j��D�d�S)Nc3s.�|]\}}|D]\}}�|ur|VqqdSr
r)rrNr�rH�loc�rOrrr@s����z@ParseResults.get_name.<locals>.find_in_parent.<locals>.<genexpr>)�nextr-rVr���parr�r�find_in_parent>s
��z-ParseResults.get_name.<locals>.find_in_parentNrQr)rrF)r(r)rRr-r�rerlrh)rr�rr�r�get_name szParseResults.get_namercCsfg}d}|�|r|t|���nd�|r�|��rctdd�|��D��}|D]<\}}	|r1|�|�|�d�|d||��t|	t�r[|	rS|�|	j	||||dd��q&|�t|	��q&|�t
|	��q&td	d�|D��r�|}	t|	�D];\}
}t|t�r�|�d
�|d||
|d|d|j	||||dd���qr|�d|d||
|d|dt|�f�qrd�
|�S)aG
        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('12/31/1999')
            print(result.dump())

        prints::

            ['12', '/', '31', '/', '1999']
            - day: 1999
            - month: 31
            - year: 12
        �
r&css �|]\}}t|�|fVqdSr
)rAr�rrrrnr�z$ParseResults.dump.<locals>.<genexpr>z
{}{}- {}: z  rQ)�indent�full�include_list�_depthcss�|]}t|t�VqdSr
)r/r%)r�vvrrrr�s�z
{}{}[{}]:
{}{}{}z
%s%s[%d]:
%s%s%s)ryrAr�ro�sortedrVr2r/r%�dumpr��anyrWr�)rr�r�r�r�r��NLrVrNrHrr�rrrr�Ssj

��	

���
���
zParseResults.dumpcOs tj|��g|�Ri|��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(delimited_list(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�)rrr?rrrr��s zParseResults.pprintcCs.|j|j��|jdur|��pd|j|jffSr
)r,r-r�r)r*r(rrrrr�s��zParseResults.__getstate__cCs@|\|_\|_}}|_t|�|_|durt|�|_dSd|_dSr
)r,r-r(r:r*rMr))r�stater��inAccumNamesrrrr �s


zParseResults.__setstate__cCs|j|jfSr
)r,r(rrrr�__getnewargs__�szParseResults.__getnewargs__cCstt|��t|���Sr
)�dirr3r0rhrrrr�__dir__�szParseResults.__dir__cCsrdd�}|g�}|��D]\}}t|t�r||j||d�7}q|||g|||�d�7}q|dur7||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.
        cSs.zt|�Wn
tyYdSwt|t�S)NF)re�	Exceptionr/r	r�rrr�is_iterable�s�z+ParseResults.from_dict.<locals>.is_iterable)r>)r>rDN)rVr/r�	from_dict)r5r�r>r�rrrNrHrrrr��s
zParseResults.from_dict)NNr
)r_r%)r&)r&TTr);r!r"r#r7r'rr�__annotations__r$r0r8r4r/rrrPr^rnr`r@rbrcrrfrgrhrlrVrortrLrwryr|r~r�r�r{r�rAr�r�r�r�r<r�r�r�r�r�rr r�r��classmethodr�rD�asDict�getNamerrrrr%s`
-

3

� 	
:




3Pr%)�collections.abcrrrrr��weakrefrrM�typingrrrA�bytesr	r3r�r;rr%�registerrrrr�<module>s
a