Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/pyparsing/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/pyparsing/__pycache__/results.cpython-38.pyc
U

N��g\d�@s�UddlmZmZmZmZmZddlZddlmZm	Z	m
Z
mZmZddl
mZeefZeedfed<edd	�d
D��ZGdd�d�ZGd
d�d�Ze�e�e�e�dS)�)�MutableMapping�Mapping�MutableSequence�Iterator�IterableN)�Tuple�Any�Dict�Set�List�)�replaced_by_pep8.�str_typeccs|]
}|VqdS�N�)�.0�_rr�>/opt/cppython/lib/python3.8/site-packages/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@sReZdZUdZdgdfZeedfed<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�Z1ed�dQdR�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/r0r1c@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	containedrrrr6�s
�zParseResults.List.__new__)N)r%r&r'�__doc__r6rrrrrds&rcKs�t|t�r|St�|�}d|_d|_t�|_|dkr<g|_n<t|t	t
f�rpt|tj�rd|dd�gnt	|�|_n|g|_t�|_
|Sr)r2r�objectr6r,r-�setr.r0r3�_generator_typer�dictr1)r7�toklist�name�kwargsrrrrr6�s 


��zParseResults.__new__Tc
Cs�|||_|dks|dkrdS||t�r0t|�}|s<|h|_||_||jkrPdS||ttf�rd|g}|r�||t�r�t	t|j
�d�||<nt	t|d�d�||<|||_dSz|d||<Wn2ttt
fk
r�||k	r�|||<n||_YnXdS)N�r)r/r(�strr.r,r+rr5rrr0�KeyErrorr4�
IndexError)rr=r>�asListZmodalr2rrrr�s2




zParseResults.__init__cCsLt|ttf�r|j|S||jkr4|j|ddStdd�|j|D��S)N���rcSsg|]}|d�qS)rr�r�vrrr�
<listcomp>�sz,ParseResults.__getitem__.<locals>.<listcomp>)r2r(�slicer0r.r1rrrrrr�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")	rr1�getr3r(rIr0rr-)r�krGr2�subrrr�__setitem__�s


�
zParseResults.__setitem__c	Cs�t|ttf�s|j|=dSt|j�}|j|=t|t�rT|dkrF||7}t||d�}tt|�|���}|�	�|j�
�D]:}|D]0}t|�D]"\}\}}t||||k�||<q�q�qxdS)Nrr)
r2r(rIr1�lenr0r3�range�indices�reverse�values�	enumerater)	rrZmylenZremoved�occurrences�jrK�value�positionrrr�__delitem__�s$


�zParseResults.__delitem__)�returncCs
||jkSr�r1)rrKrrr�__contains__szParseResults.__contains__cCs
t|j�Sr)rNr0r rrr�__len__szParseResults.__len__cCs|jp
|jSr)r0r1r rrr�__bool__
szParseResults.__bool__cCs
t|j�Sr��iterr0r rrr�__iter__
szParseResults.__iter__cCst|jddd��S)NrEr^r rrr�__reversed__szParseResults.__reversed__cCs
t|j�Sr)r_r1r rrr�keysszParseResults.keyscs�fdd����D�S)Nc3s|]}�|VqdSrr�rrKr rrrsz&ParseResults.values.<locals>.<genexpr>�rbr rr rrRszParseResults.valuescs�fdd����D�S)Nc3s|]}|�|fVqdSrrrcr rrrsz%ParseResults.items.<locals>.<genexpr>rdr rr r�itemsszParseResults.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.rZr rrr�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 rN)rer4r2r(rN)rr#r?rKrG�index�retZdefaultvaluerrr�pop"s(&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_valuerrrrJZszParseResults.getcCsN|j�||�|j��D]0}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)r0�insertr1rRrSr)rrhZ
ins_stringrTrKrVrWrrrrmqs
�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)r0�append)r�itemrrrrn�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)r2r�__iadd__r0�extend)rZitemseqrrrrq�s
zParseResults.extendcCs|jdd�=|j��dS)z7
        Clear all elements and results names.
        N)r0r1�clearr rrrrr�szParseResults.clearcCs8z
||WStk
r2|�d�r,t|��YdSXdS)N�__r@)rB�
startswith�AttributeError)rr>rrr�__getattr__�s

zParseResults.__getattr__)�otherrYcCs|��}||7}|Sr)�copy)rrwrirrr�__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)rr)r)rrK�vlistrG)�	addoffsetrrrH�s�z)ParseResults.__iadd__.<locals>.<listcomp>r)r1rNr0rer2rr-r.)rrwZ
otheritemsZotherdictitemsrKrGr)rr{rrp�s 


�zParseResults.__iadd__cCs&t|t�r|dkr|��S||SdSr")r2r(rx)rrwrrr�__radd__�szParseResults.__radd__cCs"t|�j�d|j�d|���d�S)N�(�, �))r5r%r0�as_dictr rrr�__repr__�szParseResults.__repr__cCsdd�dd�|jD��dS)N�[r�cSs&g|]}t|t�rt|�nt|��qSr)r2rrA�repr)rrrrrrH�s�z(ParseResults.__str__.<locals>.<listcomp>�])�joinr0r rrr�__str__�s�����zParseResults.__str__r@cCsLg}|jD]<}|r |r |�|�t|t�r8||��7}q
|�t|��q
|Sr)r0rnr2r�
_asStringListrA)r�sep�outrorrrr��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)r2r�as_list)r�resrrrrH
s�z(ParseResults.as_list.<locals>.<listcomp>)r0r rrrr��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_itemrrrH&sz9ParseResults.as_dict.<locals>.to_item.<locals>.<listcomp>)r2rrfr���objr�rrr�$s
"z%ParseResults.as_dict.<locals>.to_itemc3s|]\}}|�|�fVqdSrr�rrKrGr�rrr*sz'ParseResults.as_dict.<locals>.<genexpr>)r<rer rr�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.
        )rr0r1rxr-r.r,)rrirrrrx,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)r2r�deepcopyrFrrrrJsz(ParseResults.deepcopy.<locals>.<genexpr>)rxrSr0r2rr�rA�bytesrr5rer)rrirr��destrKrGrrrr�:s


�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�locr rrrns
�z(ParseResults.get_name.<locals>.<genexpr>Nrr)rrE)	r,r-r1re�nextrNr_rRrb)r�parZparent_tokdict_itemsrr r�get_nameOs&

��

���zParseResults.get_namercCs�g}d}|�|r |t|���nd�|s4d�|�S|��r�tdd�|��D��}|D]~\}}	|rl|�|�|�|�d|�d|�d��t|	t�s�|�t	|	��qV|	s�|�t|	��qV|�|	j
||||dd	��qVtd
d�|D��s�d�|�S|}	d}
d}t|	�D]�\}}
t|
t��rl|
j
||||dd	�}|�|�|�|
|�d|�d|�|�|
|d�|��
�n:|�|�|�|
|�d|�d|�|�|
|d�|
��
��qd�|�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)rAr�rrrr�sz$ParseResults.dump.<locals>.<genexpr>z  z- z: r)�indent�full�include_list�_depthcss|]}t|t�VqdSr)r2r)r�vvrrrr�sr�z]:)
rnrAr�r�rf�sortedrer2rr��dump�anyrS)rr�r�r�r�r��NLrerKrG�incr�nlrr�Zvv_dumprrrr�sZ


��
�2�2�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)r0r1rxr.r,r rrrr!�s��zParseResults.__getstate__cCs*|\|_\|_}}|_t|�|_d|_dSr)r0r1r,r:r.r-)r�stater�ZinAccumNamesrrrr$�s
zParseResults.__setstate__cCs|j|jfSr)r0r,r rrr�__getnewargs__�szParseResults.__getnewargs__cCstt|��t|���Sr)�dirr5r3rbr rrr�__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)r_�	Exceptionr2rr�rrr�is_iterables
z+ParseResults.from_dict.<locals>.is_iterable)r>)r>rDN)rer2r�	from_dict)r7rwr>r�rirKrGrrrr��s	
zParseResults.from_dict)NN)N)r@)r@TTr)N)>r%r&r'r8r+rrr)rAr
�boolrr	r*r3r6r2rrrMrXr[r(r\r]rr`rarbrRrerfrjrJrmrnrqrrrvryrpr�r�r�r�r�r<r�rxr�r�r�r�r!r$r�r��classmethodr�rDZasDict�getNamerrrrr$sv
-	2
�
'	8

0Jr)�collections.abcrrrrrr��typingrrr	r
r�utilr
rAr�rr5r)r;rr�registerrrrr�<module>s 


F1le Man4ger