Ë
    \;jŽ  ã                   ó  — d Z ddlZddlZ	 ej                  Z G d„ de«      Zddee	e
eefd„Zddddd	eej                  ee
eefd
„Zeej                  ee
eefd„Z G d„ dej$                  «      Zd„ Zd„ Zy# e$ r ej
                  ZY Œrw xY w)a  
Part of the astor library for Python AST manipulation.

License: 3-clause BSD

Copyright 2012-2015 (c) Patrick Maupin
Copyright 2013-2015 (c) Berker Peksag

Utilities for node (and, by extension, tree) manipulation.
For a whole-tree approach, see the treewalk submodule.

é    Nc                   ó   — e Zd ZdZy)ÚNonExistentz/This is not the class you are looking for.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úXG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\astor/node_util.pyr   r      s
   „ ñàr
   r   Ú c              #   óð   K  —  || dd«      }|�O|D ]  } || ||«      }	|	|usŒ|	|f–— Œ |�0|j                  t        t        | «      «      t        |«      z
  «       yy || |«      r| D ]  }	|	|f–— Œ
 yy­w)aÞ  Iterates over an object:

       - If the object has a _fields attribute,
         it gets attributes in the order of this
         and returns name, value pairs.

       - Otherwise, if the object is a list instance,
         it returns name, value pairs for each item
         in the list, where the name is passed into
         this function (defaults to blank).

       - Can update an unknown set with information about
         attributes that do not exist in fields.
    Ú_fieldsN)ÚupdateÚsetÚvars)
ÚnodeÚnameÚunknownÚlistÚgetattrÚ
isinstanceÚ	enumerateÚmissingÚfieldsÚvalues
             r   Ú	iter_noder      s“   è ø€ ñ$ �T˜9 dÓ+€FØÐÛˆDÙ˜D $¨Ó0ˆEØ˜GÒ#Ø˜T�kÓ!ð ð ÐØ�N‰Nœ3œt D›z›?¬S°«[Ñ8Õ9ð á	�D˜$Ô	ÛˆEØ˜�+Óñ ð 
 ùs   ‚ A6£AA6ú    éx   éP   c                 óH   ‡‡‡‡‡‡‡	‡
‡‡— dˆˆˆ	ˆˆˆˆˆˆˆ
f
d„	Š ‰| ||«      S )z}Dumps an AST or similar structure:

       - Pretty-prints with indentation
       - Doesn't print line/column/ctx info

    c           	      óf  •
— |‰z   }|xr |dz   xs d} ‰ ‰| «      «      } ‰| ‰«      rd|z  d}}nL|r|› ‰| «      j                   ›d�d}}n0 ‰| ‰«      r| ‰| «      j                   z   d}}n|›t        | «      ›�S |D ��cg c]  \  }}|dk7  sŒ ‰
|||«      ‘Œ } }}|›dj                  | «      ›|›�}	 ‰|	«       ‰|«      z   ‰k  rd	|	z  S | r- ‰|«       ‰| d
   «      z   ‰k  r|›| j                  d
«      ›d�}d|z  j                  | «      j	                  «       } |›d|›| ›|›�S c c}}w )NÚ=r   z%s[Ú]Ú(Ú)Úctxz, z%sr   Ú,z,
%sÚ
)r   ÚreprÚjoinÚpopÚlstrip)r   r   ÚindentÚlevelÚvaluesÚprefixÚsuffixÚaÚbÚonelineÚdumpÚindentationr   r   Úlenr   ÚmaxlineÚ	maxmergedÚspecialÚtypes             €€€€€€€€€€r   r5   zdump_tree.<locals>.dumpH   sJ  ø€ Ø˜Ñ$ˆØÒ"˜˜s™
Ò( bˆÙ‘i “oÓ&ˆÙ�d˜DÔ!Ø" T™\¨3�F‰FÙÙ(,©d°4«j×.AÓ.AÐBÀC�F‰FÙ˜˜gÔ&Ø!¡D¨£J×$7Ñ$7Ñ7¸�F‰Fá!¤4¨¤:Ð.Ð.Ù.4ÔC©f¡d a¨¸¸U»
‘�Q˜˜5Õ!¨fˆÑCÙ$ d§i¡i°¤o±vÐ>ˆÙˆw‹<™#˜f›+Ñ%¨Ò/Ø˜'‘>Ð!Ù‘C˜“K¡# d¨1¡g£,Ñ.°Ò:Ù &¨¯©°­Ð4ˆFØ˜%‘×%Ñ% dÓ+×2Ñ2Ó4ˆÚ%¡u©d±FÐ;Ð;ùó Ds   ÂD-ÂD-)Nr   r	   )r   r   Úinitial_indentr6   r8   r9   r   r:   r   r   r;   r7   r5   s      `````````@r   Ú	dump_treer=   =   s   ÿù€ ÷<ö <ñ( ��d˜NÓ+Ð+r
   c                 óL   ‡‡‡‡‡‡— t        «       Šˆˆˆˆˆˆfd„Š ‰| d«       ‰S )z´Strips an AST by removing all attributes not in _fields.

    Returns a set of the names of all attributes stripped.

    This canonicalizes two trees for comparison purposes.
    c                 óˆ  •— t        «       }d} ‰	| |¬«      D ]  \  }}d} ‰||dz   «       Œ |r ‰| ‰«      rt        t        | «      «      }‰j                  |«       |D ]  }t        | |«       Œ t	        | d«      rFt        | d«       d| j
                  v r+ ‰
| j
                  «      }|j                  d«       || _        y y y )NT)r   Fr   r&   )r   r   r   ÚdelattrÚhasattrr   Úremove)r   r-   r   ÚleafÚsubnodeÚ_r   Úmylistr   r   r   r:   ÚstripÚstrippeds           €€€€€€r   rG   zstrip_tree.<locals>.stripk   s¾   ø€ Ü“%ˆØˆÙ# D°'×:‰JˆG�QØˆDÙ�'˜6 F™?Õ+ð ;ñ Ù˜$ Ô(Üœd 4›j›/�Ø�‰˜Ô ÛˆDÜ�D˜$Õð ä�4˜ÔÜ�D˜%Ô Ø˜Ÿ™Ñ$Ù˜dŸl™lÓ+�Ø—‘˜eÔ$Ø%�•ð %ð  r
   r   )r   )	r   r   r:   r   r   r;   r7   rG   rH   s	    ````  @@r   Ú
strip_treerI   _   s&   ý€ ô ‹u€H÷&ñ &ñ$ 
ˆ$�„OØ€Or
   c                   ó    — e Zd ZdZd„ Zefd„Zy)ÚExplicitNodeVisitorz[This expands on the ast module's NodeVisitor class
    to remove any implicit visits.

    c                 óJ   — d}t        || j                  j                  z  «      ‚)Nz&No defined handler for node of type %s)ÚAttributeErrorÚ	__class__r   )r   Úmsgs     r   Úabort_visitzExplicitNodeVisitor.abort_visit‡   s!   € Ø6ˆÜ˜S 4§>¡>×#:Ñ#:Ñ:Ó;Ð;r
   c                 ó^   — d|j                   j                  z   }t        | ||«      } ||«      S )zVisit a node.Úvisit_)rN   r   r   )Úselfr   ÚabortÚmethodÚvisitors        r   ÚvisitzExplicitNodeVisitor.visit‹   s.   € à˜DŸN™N×3Ñ3Ñ3ˆÜ˜$ ¨Ó.ˆÙ�t‹}Ðr
   N)r   r   r   r   rP   rW   r	   r
   r   rK   rK   �   s   „ ñò
<ð !,ô r
   rK   c                  ó0  —  G d„ dt         «      } t        t        «      j                  «       D ]X  }t	        |«      t        k7  rŒt        |t        j                  «      sŒ1	 t        t        |j                  «      | gz   «      |_	        ŒZ y# t        $ r Y Œgw xY w)aP  This ugly little monkey-patcher adds in a helper class
    to all the AST node types.  This helper class allows
    eq/ne comparisons to work, so that entire trees can
    be easily compared by Python's comparison machinery.
    Used by the anti8 functions to compare old and new ASTs.
    Could also be used by the test library.


    c                   ó   — e Zd Zd„ Zd„ Zy)ú+allow_ast_comparison.<locals>.CompareHelperc                 ób   — t        | «      t        |«      k(  xr t        | «      t        |«      k(  S ©N©r;   r   ©rS   Úothers     r   Ú__eq__z2allow_ast_comparison.<locals>.CompareHelper.__eq__ž   s'   € Ü˜“:¤ e£Ñ,ÒJ´°d³¼tÀE»{Ñ1JÐJr
   c                 ób   — t        | «      t        |«      k7  xs t        | «      t        |«      k7  S r\   r]   r^   s     r   Ú__ne__z2allow_ast_comparison.<locals>.CompareHelper.__ne__¡   s'   € Ü˜“:¤ e£Ñ,ÒI´°T³
¼dÀ5»kÑ0IÐIr
   N)r   r   r   r`   rb   r	   r
   r   ÚCompareHelperrZ   �   s   „ ò	Kó	Jr
   rc   N)Úobjectr   Úastr/   r;   Ú
issubclassÚASTÚtupler   Ú	__bases__Ú	TypeError)rc   Úitems     r   Úallow_ast_comparisonrl   ’   s{   € ôJœô Jô ”S“	× Ñ Ö"ˆÜ�‹:œÒØÜ�dœCŸG™GÕ$ðÜ!&¤t¨D¯N©NÓ';¸}¸oÑ'MÓ!N�•ñ #øô ò Ùðús   Á'B	Â		BÂBc                 óê  ‡‡‡— t         j                  j                  Š| |fg}|j                  }|j                  }t
        t        f}t        }t        }t        }|rb |«       \  ŠŠ	  ‰‰d«      }	 ‰‰d«      }
|	D �cg c]
  }|dk7  sŒ	|‘Œ }	}|	|
D �cg c]
  }|dk7  sŒ	|‘Œ c}k7  ry |ˆˆˆfd„|	D «       «       |rŒbyc c}w c c}w # |$ r%  |‰«      |u r | |‰‰«      «       Y Œ�‰‰k(  rY Œ–Y yw xY w)zÈ This is optimized to compare two AST trees for equality.
        It makes several assumptions that are currently true for
        AST trees used by rtrip, and it doesn't examine the _attributes.
    r   r&   Fc              3   óB   •K  — | ]  } ‰‰|«       ‰‰|«      f–— Œ y ­wr\   r	   )Ú.0ÚfnameÚgetaÚn1Ún2s     €€€r   Ú	<genexpr>zfast_compare.<locals>.<genexpr>Î   s#   øè ø€ ÐFÁ2¸%‘D˜˜U“O¡T¨"¨e£_Ô5Á2ùs   ƒT)
re   rg   Ú__getattribute__r+   Úextendrj   rM   Úzip_longestr;   r   )Útree1Útree2Úworkr+   rv   Ú	exceptionÚziplÚtype_Úlist_Úf1Úf2Úxrq   rr   rs   s               @@@r   Úfast_comparer‚   ®   s  ú€ ô �7‰7×#Ñ#€Dà�EˆNÐ€DØ
�(‰(€CØ�[‰[€Fäœ>Ð)€IÜ€DÜ€EÜ€EÙ
Ù“‰ˆˆBð	GÙ�b˜)Ó$ˆBÙ�b˜)Ó$ˆBñ  Ó.™R˜ 1¨£:’!˜RˆBÐ.Ø¡Ó2¡˜A q¨E£z’a Ñ2Ò2ØÙÕFÁ2ÓFÔFò! ð$ ùò /ùÚ2øð ò 	Ù�R‹y˜EÑ!Ù‘t˜B “|Ô$ÙØ�RŠxÙÙð	ús0   Á&C Á<
B>ÂB>Â
CÂCÃC2Ã(C2Ã1C2)r   re   Ú	itertoolsrw   rM   Úizip_longestrd   r   r   r   r   r   r   rg   r;   r7   r=   rI   ÚNodeVisitorrK   rl   r‚   r	   r
   r   Ú<module>r†      s½   ðñó Û ð)Ø×'Ñ'€Kô
	�&ô 	ð  Tà °ZØ!¨;óð> ¨b¸fØ Rà!¨3¯7©7Ø J°T¸só	,ðH #¨C¯G©GØ Z°dÀóôD˜#Ÿ/™/ô ò"ó8"øðu ò )Ø×(Ñ(‚Kð)ús   ŒA7 Á7BÂ
B