a
    .PÎjÓk  ã                   @  sÀ   U d dl mZ d dlZd dlmZmZmZmZmZ d dl	Z	d dl
mZ ddlmZmZmZ eefZded< ed	d
„ dD ƒƒZedƒZded< G dd„ dƒZG dd„ dƒZe e¡ e e¡ dS )é    )ÚannotationsN)ÚMutableMappingÚMappingÚMutableSequenceÚIteratorÚIterable)ÚAnyé   )Údeprecate_argumentÚ_is_iterableÚ_flattenztuple[type, ...]Ústr_typec                 c  s   | ]
}|V  qd S ©N© )Ú.0Ú_r   r   úa/mounts/lovelace/software/anaconda3/envs/metadmg/lib/python3.9/site-packages/pyparsing/results.pyÚ	<genexpr>   ó    r   r   ÚsliceÚ
NULL_SLICEc                   @  sF   e Zd ZU ded< dgZddddœdd„Zd	d
„ Zdd„ Zdd„ ZdS )Ú_ParseResultsWithOffsetztuple[ParseResults, int]ÚtupÚParseResultsÚintÚNone)Úp1Úp2Úreturnc                 C  s   ||f| _ d S r   ©r   )Úselfr   r   r   r   r   Ú__init__   s    z _ParseResultsWithOffset.__init__c                 C  s
   | j | S r   r   ©r    Úir   r   r   Ú__getitem__   s    z#_ParseResultsWithOffset.__getitem__c                 C  s   | j S r   r   ©r    r   r   r   Ú__getstate__"   s    z$_ParseResultsWithOffset.__getstate__c                 G  s   |d | _ d S ©Nr   r   )r    Úargsr   r   r   Ú__setstate__%   s    z$_ParseResultsWithOffset.__setstate__N)	Ú__name__Ú
__module__Ú__qualname__Ú__annotations__Ú	__slots__r!   r$   r&   r)   r   r   r   r   r      s   
r   c                   @  sH  e Zd ZU dZdg dfZded< ded< d ed< d	ed
< ded< ded< ded< dZG dd„ deƒZdpdd„Z	dddde
fddœdd„Zdd„ Ze
fdd„Zdd „ Zddœd!d"„Zd#dœd$d%„Zddœd&d'„Zd(dœd)d*„Zd(dœd+d,„Zd-d.„ Zd/d0„ Zd1d2„ Zddœd3d4„Zd5d6„ Zdqd7d8„Zd9d:„ Zd;d<„ Zd=d>„ Zd?d@„ ZdAdB„ Zd d dCœdDdE„Zd d dCœdFdG„Z d dœdHdI„Z!ddœdJdK„Z"ddœdLdM„Z#drdOdP„Z$dQdRœddSdTœdUdV„Z%dWdœdXdY„Z&d dœdZd[„Z'd dœd\d]„Z(d^dœd_d`„Z)dsddœdbdc„Z*ddde„ Z+dfdg„ Z,dhdi„ Z-djdk„ Z.dldm„ Z/e0dtd dœdndo„ƒZ1e%Z2e&Z3e)Z4dS )ur   a†  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:

    .. testcode::

       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:

    .. testoutput::

       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   ztuple[Any, ...]Ú_null_valuesÚstrÚ_nameÚ_parentzset[str]Ú
_all_namesÚboolÚ_modalz	list[Any]Ú_toklistzdict[str, Any]Ú_tokdict)r1   r2   r3   r5   r6   r7   c                   @  s   e Zd ZdZddd„ZdS )zParseResults.Lista9  
        Simple wrapper class to distinguish parsed list results that should be preserved
        as actual Python lists, instead of being converted to :class:`ParseResults`:

        .. testcode::

           import pyparsing as pp
           ppc = pp.common

           LBRACK, RBRACK, LPAR, RPAR = pp.Suppress.using_each("[]()")
           element = pp.Forward()
           item = ppc.integer
           item_list = pp.DelimitedList(element)
           element_list = LBRACK + item_list + RBRACK | LPAR + item_list + RPAR
           element <<= item | element_list

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

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

        prints:

        .. testoutput::
           :options: +NORMALIZE_WHITESPACE


           100
           (100, <class 'int'>)

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

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

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

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

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

        (Used internally by :class:`Group` when `aslist=True`.)
        Nc                 C  s:   |d u rg }t |tƒs0t| j› dt|ƒj› �ƒ‚t | ¡S )Nz* may only be constructed with a list, not )Ú
isinstanceÚlistÚ	TypeErrorr*   ÚtypeÚ__new__)ÚclsZ	containedr   r   r   r<   «   s    
ÿzParseResults.List.__new__)N)r*   r+   r,   Ú__doc__r<   r   r   r   r   ÚListo   s   ;r?   c                 K  s„   t |tƒr|S t | ¡}d |_d |_tƒ |_|d u r<g |_n<t |t	t
fƒrpt |tjƒrd|d d … gnt	|ƒ|_n|g|_tƒ |_|S r   )r8   r   Úobjectr<   r1   r2   Úsetr3   r6   r9   Ú_generator_typer?   Údictr7   )r=   ÚtoklistÚnameÚkwargsr    r   r   r   r<   ¶   s     


ÿýzParseResults.__new__Tr   )r   c              
   K  s  t |dddd�}|o|}|  || _|d u s2|dkr6d S ||tƒrHt|ƒ}|sT|h| _|| _|| jv rhd S ||ttfƒr||g}|rÄ||t	ƒr t
t	|jƒdƒ| |< nt
t	|d ƒdƒ| |< || | _d S z|d | |< W n2 tttf�y   || urü|| |< n|| _Y n0 d S )NÚasListTÚaslist)Únew_nameÚ r   )r
   r5   r   r0   r3   r1   r/   r   r;   r   r   r6   ÚKeyErrorr:   Ú
IndexError)r    rD   rE   rH   Zmodalr8   rF   rG   r   r   r   r!   Í   s6    	




zParseResults.__init__c                 C  sL   t |ttfƒr| j| S || jvr4| j| d d S tdd„ | j| D ƒƒS )Néÿÿÿÿr   c                 S  s   g | ]}|d  ‘qS )r   r   ©r   Úvr   r   r   Ú
<listcomp>  r   z,ParseResults.__getitem__.<locals>.<listcomp>)r8   r   r   r6   r3   r7   r   r"   r   r   r   r$   ý   s
    

zParseResults.__getitem__c                 C  s†   ||t ƒr0| j |tƒ ¡|g | j|< |d }nB||ttfƒrN|| j|< |}n$| j |g ¡t |dƒg | j|< |}||tƒr‚| |_d S r'   )	r   r7   Úgetr9   r   r   r6   r   r2   )r    ÚkrO   r8   Úsubr   r   r   Ú__setitem__  s    


ÿ
zParseResults.__setitem__c           	      C  sÎ   t |ttfƒs| j|= d S |tkr0| j ¡  d S t| jƒ}| j|= t |tƒrj|dk r\||7 }t||d ƒ}tt	| 
|¡Ž ƒ}| ¡  | j ¡ D ]:}|D ]0}t|ƒD ]"\}\}}t||||k ƒ||< q¢q–qŽd S )Nr   r	   )r8   r   r   r7   r   r6   ÚclearÚlenr9   ÚrangeÚindicesÚreverseÚvaluesÚ	enumerater   )	r    r#   ZmylenZremovedÚoccurrencesÚjrR   ÚvalueÚpositionr   r   r   Ú__delitem__  s(    


ÿzParseResults.__delitem__c                 C  s
   || j v S r   ©r7   )r    rR   r   r   r   Ú__contains__2  s    zParseResults.__contains__r   c                 C  s
   t | jƒS r   )rV   r6   r%   r   r   r   Ú__len__5  s    zParseResults.__len__c                 C  s   | j p
| j  S r   )r6   r7   r%   r   r   r   Ú__bool__8  s    zParseResults.__bool__r   c                 C  s
   t | jƒS r   ©Úiterr6   r%   r   r   r   Ú__iter__;  s    zParseResults.__iter__c                 C  s   t | jd d d… ƒS )NrM   re   r%   r   r   r   Ú__reversed__>  s    zParseResults.__reversed__c                 C  s
   t | jƒS r   )rf   r7   r%   r   r   r   ÚkeysA  s    zParseResults.keysc                   s   ‡ fdd„ˆ   ¡ D ƒS )Nc                 3  s   | ]}ˆ | V  qd S r   r   ©r   rR   r%   r   r   r   E  r   z&ParseResults.values.<locals>.<genexpr>©ri   r%   r   r%   r   rZ   D  s    zParseResults.valuesc                   s   ‡ fdd„ˆ   ¡ D ƒS )Nc                 3  s   | ]}|ˆ | fV  qd S r   r   rj   r%   r   r   r   H  r   z%ParseResults.items.<locals>.<genexpr>rk   r%   r   r%   r   ÚitemsG  s    zParseResults.itemsc                 C  s
   | 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.ra   r%   r   r   r   ÚhaskeysJ  s    zParseResults.haskeysc                 O  s�   |s
dg}|  ¡ D ],\}}|dkr0|d |f}qtd|›�ƒ‚qt|d tƒsft|ƒdksf|d | v r€|d }| | }| |= |S |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:

        .. doctest::

           >>> 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)
           [W:(0-9)]...
           >>> 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())
           ['AAB', '123', '321']
           - LABEL: 'AAB'

           >>> # 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)
           {W:(A-Za-z) {W:(0-9)}...}
           >>> print(patt.parse_string("AAB 123 321").dump())
           ['AAB', '123', '321']

        rM   Údefaultr   z)pop() got an unexpected keyword argument r	   N)rl   r:   r8   r   rV   )r    r(   rF   rR   rO   ÚindexÚretZdefaultvaluer   r   r   ÚpopP  s    .&zParseResults.popc                 C  s   || v r| | S |S dS )as  
        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:

        .. doctest::

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

           >>> result = date_str.parse_string("1999/12/31")
           >>> result.get("year")
           '1999'
           >>> result.get("hour", "not specified")
           'not specified'
           >>> result.get("hour")

        Nr   )r    ÚkeyÚdefault_valuer   r   r   rQ   Ž  s    zParseResults.getc                 C  sN   | j  ||¡ | j ¡ D ]0}t|ƒD ]"\}\}}t||||k ƒ||< q$qdS )aª  
        Inserts new element at location index in the list of parsed tokens.

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

        Example:

        .. doctest::

           >>> 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)
           [W:(0-9)]...
           >>> print(numlist.parse_string("0 123 321"))
           [0, '0', '123', '321']

        N)r6   Úinsertr7   rZ   r[   r   )r    ro   Z
ins_stringr\   rR   r^   r_   r   r   r   rt   ª  s    ÿzParseResults.insertc                 C  s   | j  |¡ dS )a‡  
        Add single element to end of ``ParseResults`` list of elements.

        Example:

        .. doctest::

           >>> 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)
           [W:(0-9)]...
           >>> print(numlist.parse_string("0 123 321"))
           ['0', '123', '321', 444]
        N)r6   Úappend)r    Úitemr   r   r   ru   Ë  s    zParseResults.appendc                 C  s&   t |tƒr|  |¡ n| j |¡ dS )as  
        Add sequence of elements to end of :class:`ParseResults` list of elements.

        Example:

        .. testcode::

           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"))

        prints:

        .. testoutput::

           ['lskdjsdlkjflksddsklfjkldsjdksl']
        N)r8   r   Ú__iadd__r6   Úextend)r    Zitemseqr   r   r   rx   ã  s    
zParseResults.extendc                 C  s   | j dd…= | j ¡  dS )z7
        Clear all elements and results names.
        N)r6   r7   rU   r%   r   r   r   rU     s    zParseResults.clearc                 C  s6   z
| | W S  t y0   | d¡r*t|ƒ‚Y dS 0 d S )NÚ__rJ   )rK   Ú
startswithÚAttributeError)r    rE   r   r   r   Ú__getattr__  s    

zParseResults.__getattr__)Úotherr   c                 C  s   |   ¡ }||7 }|S r   )Úcopy)r    r}   rp   r   r   r   Ú__add__  s    zParseResults.__add__c                   s’   |s| S |j rnt| jƒ‰‡fdd„‰ |j  ¡ }‡ fdd„|D ƒ}|D ](\}}|| |< t|d tƒrD| |d _qD|  j|j7  _|  j|jO  _| S )Nc                   s   | dk rˆ S | ˆ  S r'   r   )Úa)Úoffsetr   r   Ú<lambda>  r   z'ParseResults.__iadd__.<locals>.<lambda>c              	     s4   g | ],\}}|D ]}|t |d  ˆ |d ƒƒf‘qqS )r   r	   )r   )r   rR   ÚvlistrO   )Ú	addoffsetr   r   rP     s   þz)ParseResults.__iadd__.<locals>.<listcomp>r   )r7   rV   r6   rl   r8   r   r2   r3   )r    r}   Z
otheritemsZotherdictitemsrR   rO   r   )r„   r�   r   rw     s     


þzParseResults.__iadd__c                 C  s&   t |tƒr|dkr|  ¡ S ||  S d S r'   )r8   r   r~   )r    r}   r   r   r   Ú__radd__+  s    zParseResults.__radd__c                 C  s"   t | ƒj› d| j›d|  ¡ › d�S )Nú(ú, ú))r;   r*   r6   Úas_dictr%   r   r   r   Ú__repr__3  s    zParseResults.__repr__c                 C  s   dd  dd„ | jD ƒ¡ d S )Nú[r‡   c                 S  s&   g | ]}t |tƒrt|ƒnt|ƒ‘qS r   )r8   r   r0   Úrepr)r   r#   r   r   r   rP   :  s   ÿz(ParseResults.__str__.<locals>.<listcomp>ú])Újoinr6   r%   r   r   r   Ú__str__6  s    þÿÿùÿzParseResults.__str__rJ   c                 C  sL   g }| j D ]<}|r |r | |¡ t|tƒr8|| ¡ 7 }q
| t|ƒ¡ q
|S r   )r6   ru   r8   r   Ú_asStringListr0   )r    ÚsepÚoutrv   r   r   r   r�   B  s    


zParseResults._asStringListF)Úflattenr9   )r“   r   c                C  s$   |rg t | ƒ¢S dd„ | jD ƒS dS )a²  
        Returns the parse results as a nested list of matching tokens, all converted to strings.
        If ``flatten`` is True, all the nesting levels in the returned list are collapsed.

        Example:

        .. doctest::

           >>> 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
           >>> type(result)
           <class 'pyparsing.results.ParseResults'>
           >>> print(result)
           ['sldkj', 'lsdkj', 'sldkj']

        .. doctest::

           >>> # Use as_list() to create an actual list
           >>> result_list = result.as_list()
           >>> type(result_list)
           <class 'list'>
           >>> print(result_list)
           ['sldkj', 'lsdkj', 'sldkj']

        .. versionchanged:: 3.2.0
           New ``flatten`` argument.
        c                 S  s"   g | ]}t |tƒr| ¡ n|‘qS r   )r8   r   Úas_list)r   Úresr   r   r   rP   o  s   ÿz(ParseResults.as_list.<locals>.<listcomp>N)r   r6   )r    r“   r   r   r   r”   M  s
    þzParseResults.as_listrC   c                   s&   ‡ fdd„‰ t ‡ fdd„|  ¡ D ƒƒS )ac  
        Returns the named parse results as a nested dictionary.

        Example:

        .. doctest::

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

           >>> result = date_str.parse_string('1999/12/31')
           >>> type(result)
           <class 'pyparsing.results.ParseResults'>
           >>> result
           ParseResults(['1999', '/', '12', '/', '31'], {'year': '1999', 'month': '12', 'day': '31'})

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

           >>> # even though a ParseResults supports dict-like access,
           >>> # sometime you just need to have a dict
           >>> import json
           >>> print(json.dumps(result))
           Traceback (most recent call last):
           TypeError: Object of type ParseResults is not JSON serializable
           >>> print(json.dumps(result.as_dict()))
           {"year": "1999", "month": "12", "day": "31"}
        c                   s4   t | tƒr,|  ¡ r|  ¡ S ‡ fdd„| D ƒS | S d S )Nc                   s   g | ]}ˆ |ƒ‘qS r   r   rN   ©Úto_itemr   r   rP   —  r   z9ParseResults.as_dict.<locals>.to_item.<locals>.<listcomp>)r8   r   rm   r‰   )Úobjr–   r   r   r—   •  s    
"z%ParseResults.as_dict.<locals>.to_itemc                 3  s   | ]\}}|ˆ |ƒfV  qd S r   r   ©r   rR   rO   r–   r   r   r   ›  r   z'ParseResults.as_dict.<locals>.<genexpr>)rC   rl   r%   r   r–   r   r‰   t  s    !zParseResults.as_dictc                 C  s:   t | jƒ}| j ¡ |_| j|_| j| jO  _| j|_|S )a  
        Returns a new shallow copy of a :class:`ParseResults` object.
        :class:`ParseResults` items contained within the source are
        shared with the copy. Use :meth:`ParseResults.deepcopy` to
        create a copy with its own separate content values.
        )r   r6   r7   r~   r2   r3   r1   )r    rp   r   r   r   r~   �  s    
zParseResults.copyc                 C  s¼   |   ¡ }t| jƒD ]¤\}}t|tƒr4| ¡ |j|< qt|ttfƒrDqt|tƒr�t	|ƒƒ  |j|< }| 
¡ D ]"\}}t|tƒr„| ¡ n|||< qjqt|tƒrt	|ƒdd„ |D ƒƒ|j|< q|S )zm
        Returns a new deep copy of a :class:`ParseResults` object.

        .. versionadded:: 3.1.0
        c                 s  s$   | ]}t |tƒr| ¡ n|V  qd S r   )r8   r   ÚdeepcopyrN   r   r   r   r   ½  s   z(ParseResults.deepcopy.<locals>.<genexpr>)r~   r[   r6   r8   r   rš   r0   Úbytesr   r;   rl   r   )r    rp   r#   r˜   ÚdestrR   rO   r   r   r   rš   «  s    


ÿzParseResults.deepcopyz
str | Nonec                   sŒ   ˆ j rˆ j S ˆ jr:ˆ j}|j ¡ }t‡ fdd„|D ƒdƒS tˆ ƒdkr„tˆ jƒdkr„ttˆ j ¡ ƒƒd d dv r„ttˆ j ¡ ƒƒS dS dS )aG  
        Returns the results name for this token expression.

        Useful when several different expressions might match
        at a particular location.

        Example:

        .. testcode::

           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:

        .. testoutput::

           age : 22
           ssn : 111-22-3333
           house_number : 221B

        c                 3  s,   | ]$\}}|D ]\}}|ˆ u r|V  qqd S r   r   )r   rR   rƒ   rO   Úlocr%   r   r   r   è  s   ýz(ParseResults.get_name.<locals>.<genexpr>Nr	   r   )r   rM   )	r1   r2   r7   rl   ÚnextrV   rf   rZ   ri   )r    ÚparZparent_tokdict_itemsr   r%   r   Úget_nameÂ  s&     

þù

ÿþýzParseResults.get_namer   c                 C  s´  g }d}|  |r |t|  ¡ ƒ nd¡ |s4d |¡S |  ¡ rÖtdd„ |  ¡ D ƒƒ}|D ]~\}}	|rl|  |¡ |  |› d| › d|› d�¡ t|	tƒs¤|  t	|	ƒ¡ qV|	s¸|  t|	ƒ¡ qV|  |	j
||||d d	�¡ qVtd
d„ | D ƒƒsòd |¡S | }	d}
d}t|	ƒD ]¢\}}t|tƒ�rl|j
||||d d	�}|  |› |› |
| › d|› d|› |› |
|d  › |› �
¡ n:|  |› |› |
| › d|› d|› |› |
|d  › |› �
¡ �qd |¡S )as  
        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:

        .. testcode::

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

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

        prints:

        .. testoutput::

           ['1999', '/', '12', '/', '31']
           - day: '31'
           - month: '12'
           - year: '1999'
        Ú
rJ   c                 s  s   | ]\}}t |ƒ|fV  qd S r   )r0   r™   r   r   r   r     r   z$ParseResults.dump.<locals>.<genexpr>z  z- z: r	   )ÚindentÚfullÚinclude_listÚ_depthc                 s  s   | ]}t |tƒV  qd S r   )r8   r   )r   Úvvr   r   r   r   /  r   r‹   z]:)ru   r0   r”   rŽ   rm   Úsortedrl   r8   r   rŒ   ÚdumpÚanyr[   )r    r¢   r£   r¤   r¥   r’   ÚNLrl   rR   rO   ÚincrÚnlr#   r¦   Zvv_dumpr   r   r   r¨   ù  sZ    


üÿ
ü2ÿ2ÿzParseResults.dumpc                 O  s    t j |  ¡ g|¢R i |¤Ž dS )aF  
        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:

        .. testcode::

           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:

        .. testoutput::

           ['fna',
            ['a',
             'b',
             ['(', 'fnb', ['c', 'd', '200'], ')'],
             '100']]
        N)Úpprintr”   )r    r(   rF   r   r   r   r­   G  s    zParseResults.pprintc                 C  s   | j | j ¡ d | j| jffS r   )r6   r7   r~   r3   r1   r%   r   r   r   r&   g  s    üþzParseResults.__getstate__c                 C  s*   |\| _ \| _}}| _t|ƒ| _d | _d S r   )r6   r7   r1   rA   r3   r2   )r    ÚstaterŸ   ZinAccumNamesr   r   r   r)   r  s    
zParseResults.__setstate__c                 C  s   | j | jfS r   )r6   r1   r%   r   r   r   Ú__getnewargs__w  s    zParseResults.__getnewargs__c                 C  s   t t| ƒƒt|  ¡ ƒ S r   )Údirr;   r9   ri   r%   r   r   r   Ú__dir__z  s    zParseResults.__dir__c                 C  sj   | g ƒ}|  ¡ D ]>\}}t|tƒr6|| j||d�7 }q|| |g|t|ƒd�7 }q|durf| |g|d�}|S )zü
        Helper classmethod to construct a :class:`ParseResults` from a ``dict``, preserving the
        name-value relations as results names. If an optional ``name`` argument is
        given, a nested :class:`ParseResults` will be returned.
        )rE   )rE   rH   N)rl   r8   r   Ú	from_dictr   )r=   r}   rE   rp   rR   rO   r   r   r   r²   }  s    
zParseResults.from_dict)NN)N)rJ   )rJ   TTr   )N)5r*   r+   r,   r>   r/   r-   r.   r9   r?   r<   r8   r!   r$   rT   r`   rb   rc   rd   rg   rh   ri   rZ   rl   rm   rq   rQ   rt   ru   rx   rU   r|   r   rw   r…   rŠ   r�   r�   r”   r‰   r~   rš   r    r¨   r­   r&   r)   r¯   r±   Úclassmethodr²   rG   ZasDictÚgetNamer   r   r   r   r   )   sv   
3	G
ú0	>
!
')7N r   )Ú
__future__r   ÚcollectionsÚcollections.abcr   r   r   r   r   r­   Útypingr   Úutilr
   r   r   r0   r›   r   r-   r;   rB   r   r   r   r   Úregisterr   r   r   r   Ú<module>   s$         |
