a
    hl                     @  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 eefZded< ed	d
 dD ZG dd dZG dd dZee ee dS )    )annotationsN)MutableMappingMappingMutableSequenceIteratorIterable)Any   )replaced_by_pep8ztuple[type, ...]str_typec                 c  s   | ]
}|V  qd S N ).0_r   r   ^/mounts/lovelace/software/anaconda3/envs/py39/lib/python3.9/site-packages/pyparsing/results.py	<genexpr>       r   r   c                   @  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)r-   r.   r/   r1   r2   r3   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   r8      s    
zParseResults.List.__new__)N)r&   r'   r(   __doc__r8   r   r   r   r   Listn   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   )r4   r   objectr8   r-   r.   setr/   r2   r5   _generator_typer;   dictr3   )r9   toklistnamekwargsr   r   r   r   r8      s     


zParseResults.__new__Tr   )r   c              
   C  s   |  || _ |d u s|dkrd S ||tr0t|}|s<|h| _|| _|| jv rPd S ||ttfrd|g}|r||trt	t|j
d| |< nt	t|d d| |< || | _d S z|d | |< W n0 tttfy   || ur|| |< n|| _Y n0 d S )N r   )r1   r   r,   r/   r-   r+   r   r7   r   r   r2   KeyErrorr6   
IndexError)r   r@   rA   asListZmodalr4   r   r   r   r      s2    




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 )Nr   c                 S  s   g | ]}|d  qS )r   r   r   vr   r   r   
<listcomp>   r   z,ParseResults.__getitem__.<locals>.<listcomp>)r4   r   slicer2   r/   r3   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   r3   getr5   r   rK   r2   r   r.   )r   krI   r4   subr   r   r   __setitem__   s    



zParseResults.__setitem__c           	      C  s   t |ttfs| j|= d S t| j}| j|= t |trT|dk rF||7 }t||d }tt|| }|	  | j
 D ]:}|D ]0}t|D ]"\}\}}t||||k ||< qqqxd S )Nr   r	   )r4   r   rK   r3   lenr2   r5   rangeindicesreversevalues	enumerater   )	r   r   ZmylenZremovedoccurrencesjrM   valuepositionr   r   r   __delitem__  s"    

zParseResults.__delitem__c                 C  s
   || j v S r   r3   )r   rM   r   r   r   __contains__#  s    zParseResults.__contains__r   c                 C  s
   t | jS r   )rP   r2   r!   r   r   r   __len__&  s    zParseResults.__len__c                 C  s   | j p
| j  S r   )r2   r3   r!   r   r   r   __bool__)  s    zParseResults.__bool__r   c                 C  s
   t | jS r   iterr2   r!   r   r   r   __iter__,  s    zParseResults.__iter__c                 C  s   t | jd d d S NrG   r_   r!   r   r   r   __reversed__/  s    zParseResults.__reversed__c                 C  s
   t | jS r   )r`   r3   r!   r   r   r   keys2  s    zParseResults.keysc                   s    fdd   D S )Nc                 3  s   | ]} | V  qd S r   r   r   rM   r!   r   r   r   6  r   z&ParseResults.values.<locals>.<genexpr>rd   r!   r   r!   r   rT   5  s    zParseResults.valuesc                   s    fdd   D S )Nc                 3  s   | ]}| | fV  qd S r   r   re   r!   r   r   r   9  r   z%ParseResults.items.<locals>.<genexpr>rf   r!   r   r!   r   items8  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.r[   r!   r   r   r   haskeys;  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']

        rG   defaultr   z)pop() got an unexpected keyword argument r	   N)rg   r6   r4   r   rP   )r   r$   rB   rM   rI   indexretZdefaultvaluer   r   r   popA  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   rL     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)r2   insertr3   rT   rU   r   )r   rj   Z
ins_stringrV   rM   rX   rY   r   r   r   ro     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)r2   append)r   itemr   r   r   rp     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)r4   r   __iadd__r2   extend)r   Zitemseqr   r   r   rs     s    
zParseResults.extendc                 C  s   | j dd= | j  dS )z7
        Clear all elements and results names.
        N)r2   r3   clearr!   r   r   r   rt     s    zParseResults.clearc                 C  s6   z
| | W S  t y0   |dr*t|Y dS 0 d S )N__rC   )rD   
startswithAttributeError)r   rA   r   r   r   __getattr__  s    

zParseResults.__getattr__)otherr   c                 C  s   |   }||7 }|S r   )copy)r   ry   rk   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   rM   vlistrI   )	addoffsetr   r   rJ     s   z)ParseResults.__iadd__.<locals>.<listcomp>r   )r3   rP   r2   rg   r4   r   r.   r/   )r   ry   Z
otheritemsZotherdictitemsrM   rI   r   )r   r}   r   rr     s     


zParseResults.__iadd__c                 C  s&   t |tr|dkr|  S ||  S d S r#   )r4   r   rz   )r   ry   r   r   r   __radd__  s    zParseResults.__radd__c                 C  s"   t | j d| jd|   dS )N(, ))r7   r&   r2   as_dictr!   r   r   r   __repr__$  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   )r4   r   r,   repr)r   r   r   r   r   rJ   +  s   z(ParseResults.__str__.<locals>.<listcomp>])joinr2   r!   r   r   r   __str__'  s    zParseResults.__str__rC   c                 C  sL   g }| j D ]<}|r |r || t|tr8|| 7 }q
|t| q
|S r   )r2   rp   r4   r   _asStringListr,   )r   sepoutrq   r   r   r   r   3  s    


zParseResults._asStringListF)flattenr5   )r   r   c                  s0    fdd}|rg | 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                 3  sF   t g  }|rB| }t|tr:||d d d  q|V  qd S rb   )collectionsdequepopleftr4   r   
extendleft)prZto_visitZto_dor!   r   r   	flattened]  s    
z'ParseResults.as_list.<locals>.flattenedc                 S  s"   g | ]}t |tr| n|qS r   )r4   r   as_list)r   resr   r   r   rJ   i  s   z(ParseResults.as_list.<locals>.<listcomp>N)r2   )r   r   r   r   r!   r   r   >  s    	zParseResults.as_listr?   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   rH   to_itemr   r   rJ     r   z9ParseResults.as_dict.<locals>.to_item.<locals>.<listcomp>)r4   r   rh   r   objr   r   r   r     s    
"z%ParseResults.as_dict.<locals>.to_itemc                 3  s   | ]\}}| |fV  qd S r   r   r   rM   rI   r   r   r   r     r   z'ParseResults.as_dict.<locals>.<genexpr>)r?   rg   r!   r   r   r   r   n  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   r2   r3   rz   r.   r/   r-   )r   rk   r   r   r   rz     s    
zParseResults.copyc                 C  s   |   }t| jD ]\}}t|tr4| |j|< qt|ttfrDqt|trt	|  |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   )r4   r   deepcopyrH   r   r   r   r     s   z(ParseResults.deepcopy.<locals>.<genexpr>)rz   rU   r2   r4   r   r   r,   bytesr   r7   rg   r   )r   rk   r   r   destrM   rI   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rt jdkrtt j d d dv rt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   rM   r   rI   locr!   r   r   r     s   z(ParseResults.get_name.<locals>.<genexpr>Nr	   r   )r   rG   )	r-   r.   r3   rg   nextrP   r`   rT   rd   )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 |  rtdd |  D }|D ]~\}}	|rl| | | | d|  d| d t|	ts| t	|	 qV|	s| t|	 qV| |	j
||||d d	 qVtd
d | D sd|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'
        
rC   c                 s  s   | ]\}}t ||fV  qd S r   )r,   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   )r4   r   )r   vvr   r   r   r   )  r   r   z]:)rp   r,   r   r   rh   sortedrg   r4   r   r   dumpanyrU   )r   r   r   r   r   r   NLrg   rM   rI   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$   rB   r   r   r   r   A  s    zParseResults.pprintc                 C  s   | j | j d | j| jffS r   )r2   r3   rz   r/   r-   r!   r   r   r   r"   a  s    zParseResults.__getstate__c                 C  s*   |\| _ \| _}}| _t|| _d | _d S r   )r2   r3   r-   r=   r/   r.   )r   stater   ZinAccumNamesr   r   r   r%   l  s    
zParseResults.__setstate__c                 C  s   | j | jfS r   )r2   r-   r!   r   r   r   __getnewargs__q  s    zParseResults.__getnewargs__c                 C  s   t t| t|   S r   )dirr7   r5   rd   r!   r   r   r   __dir__t  s    zParseResults.__dir__c                 C  sr   dd }| g }|  D ]>\}}t|tr>|| j||d7 }q|| |g|||d7 }q|durn| |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.
        c                 S  s2   zt |  W n ty    Y dS 0 t| t S d S )NF)r`   	Exceptionr4   r   r   r   r   r   is_iterable  s
    z+ParseResults.from_dict.<locals>.is_iterable)rA   )rA   rF   N)rg   r4   r   	from_dict)r9   ry   rA   r   rk   rM   rI   r   r   r   r   w  s    	
zParseResults.from_dict)NN)N)rC   )rC   TTr   )N)5r&   r'   r(   r:   r+   r)   r*   r5   r;   r8   r4   r   r    rO   rZ   r\   r]   r^   ra   rc   rd   rT   rg   rh   rl   rL   ro   rp   rs   rt   rx   r{   rr   r   r   r   r   r   r   rz   r   r   r   r   r"   r%   r   r   classmethodr   rF   ZasDictgetNamer   r   r   r   r   (   sn   
3	G

'	>
!
0)7N r   )
__future__r   r   collections.abcr   r   r   r   r   r   typingr   utilr
   r,   r   r   r)   r7   r>   r   r   registerr   r   r   r   <module>   s$          
