
    9iC                        S r SSKJrJrJrJrJrJrJrJ	r	  SSK
JrJr  SSKJr  SSKJr  SSKrS rSS jrSS	 jrSS
 jrS rS rS rS rSS jr\R6                  \R8                  \R:                  \R<                  \R>                  4r \RB                  \RD                  4r#S r$SS jr%S r&S r'S r(S r)S r*S r+S r,Sr-Sr.S r/S r0SS jr1g) z
Utility functions from 2to3, 3to2 and python-modernize (and some home-grown
ones).

Licences:
2to3: PSF License v2
3to2: Apache Software License (from 3to2/setup.py)
python-modernize licence: BSD (from python-modernize/LICENSE)
    )
FromImportNewline	is_import	find_rootdoes_tree_importCallNameComma)LeafNode)python_symbols)tokenNc                 h   SU ;   a  U $ U R                  S5      (       a  U SS n U Vs/ s H,  nUR                  SR                  U 5      5      (       d  M*  UPM.     nn[        U5      S:  a$  [	        SSR                  S	 U 5       5      -   5      e[        U5      S
:X  a  [	        S5      eUS
   $ s  snf )aD  
Examples:
>>> canonical_fix_name('fix_wrap_text_literals')
'libfuturize.fixes.fix_wrap_text_literals'
>>> canonical_fix_name('wrap_text_literals')
'libfuturize.fixes.fix_wrap_text_literals'
>>> canonical_fix_name('wrap_te')
ValueError("unknown fixer name")
>>> canonical_fix_name('wrap')
ValueError("ambiguous fixer name")
z.fix_fix_   Nzfix_{0}   zOAmbiguous fixer name. Choose a fully qualified module name instead from these:

c              3   ,   #    U  H
  nS U-   v   M     g7f)z  N ).0myfs     V/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/libfuturize/fixer_util.py	<genexpr>%canonical_fix_name.<locals>.<genexpr>-   s     8%3D3J%s   r   z1Unknown fixer. Use --list-fixes or -l for a list.)
startswithendswithformatlen
ValueErrorjoin)fixavail_fixesffounds       r   canonical_fix_namer%      s     #~
>>&!!ab'C ( 7KqJJy//45 K 7u:> 6))8%889 : : Z1_PQQQx7s   )B/B/c                 4    [        [        R                  SU S9$ )N*prefix)r   r   STARr(   s    r   Starr+   6   s    

D00    c                 4    [        [        R                  SU S9$ )Nz**r(   )r   r   
DOUBLESTARr(   s    r   
DoubleStarr/   9   s      %77r,   c                 4    [        [        R                  SU S9$ )N-r(   )r   r   MINUSr(   s    r   Minusr3   <   s    T&11r,   c                 v    / nU  H-  nUR                  U5        UR                  [        5       5        M/     US	 U$ )zo
Accepts/turns: (Name, Name, ..., Name, Name)
Returns/into: (Name, Comma, Name, Comma, ..., Name, Comma, Name)
)appendr
   )leafs	new_leafsleafs      r   	commatizer:   ?   s@    
 I!  	"r,   c                 ,   U R                   bk  U R                   R                  [        R                  :w  aC  U R                   n U R                   b*  U R                   R                  [        R                  :w  a  MC  U R                   c  gU R                  [        R
                  :X  a  U R                  $ U R                  b>  U R                  R                  [        R
                  :X  a  U R                  R                  $ U R                  c  gU R                  $ )zZ
Returns the indentation for this node
Iff a node is in a suite, then it has indentation.
 )	parenttypesymssuiter   INDENTvalueprev_siblingr)   nodes    r   indentationrF   K   s    
 ++
!dkk&6&6$**&D{{ ++
!dkk&6&6$**&D{{ yyELL zz				&4+<+<+A+AU\\+Q  &&&				"{{r,   c                 ~    [        U 5      n[        S UR                  5        5       5      nU(       d  g[        U5      $ )a  
Dirty little trick to get the difference between each indentation level
Implemented by finding the shortest indentation string
(technically, the "least" of all of the indentation strings, but
tabs and spaces mixed won't get this far, so those are synonymous.)
c              3   x   #    U  H0  oR                   [        R                  :X  d  M"  UR                  v   M2     g 7fN)r>   r   rA   rB   )r   is     r   r   #indentation_step.<locals>.<genexpr>i   s#     O}!%,,8Ngagg}s   !::z    )r   set	pre_ordermin)rE   rall_indentss      r   indentation_steprQ   `   s4     	$AOq{{}OOK;r,   c                 4   U R                    H#  nUR                  [        R                  :X  d  M#    g   [	        U R                   5       H%  u  p!UR                  [
        R                  :X  d  M%    O   [        S5      e[        [        R                  [        5       [        [
        R                  [        U5      [        U5      -   5      /5      nU R                   US-      nUR                  5         SUl        UR!                  U5        U R!                  U5        g)z^
Turn the stuff after the first colon in parent's children
into a suite, if it wasn't already
NzNo class suite and no ':'!r   r<   )childrenr>   r?   r@   	enumerater   COLONr   r   r   r   rA   rF   rQ   remover)   append_child)r=   rE   rJ   r@   one_nodes        r   suitifyrY   p   s    
 99

"   V__-99# . 677giellK<MP`aePf<f)ghiEqs#HOOHO	x 
r,   c                     Uc  Sn[        SUS9U /nUb#  UR                  [        SSS9[        USS9/5        [        [        R                  U5      $ )z
Accepts a package (Name node), name to import it as (string), and
optional prefix and returns a node:
import <package> [as <as_name>]
r<   importr(   as )r	   extendr   r?   import_name)packageas_namer)   rS   s       r   
NameImportrb      s\     ~Yv.8HeD1gd35 	6  (++r,   c              #     #    U R                   [        ;   d   eU R                  nUR                   [        R                  :X  a[  UR                  nUR                   [        R
                  :X  a  O0Uv   UR                  nUR                   [        R                  :X  a  M[  U R                  nUR                   [        R                  :X  d   eUR                  nUb  Uv   UR                  nUb  M  UR                  nUR                   [        ;   aD  UnUR                  b)  UR                  v   UR                  nUR                  b  M)  UR                  nUR                  nUc  gUR                   [        ;   ad  UR                   [        R                  :X  a  Uv   UR                  nUc  UR                  nUR                  nUc  gUR                   [        ;   a  Mc  gg7f)z
Generator yields all nodes for which a node (an import_stmt) has scope
The purpose of this is for a call to _find() on each of them
N)r>   _import_stmtsnext_siblingr   SEMINEWLINEr=   r?   simple_stmt_compound_stmtsr@   )rE   testnxtr=   contextcps          r   import_binding_scopero      s~     99%%%D
))uzz
!88u}}$I ))uzz
! [[F;;$*****D


   

 mmG||&nn(.. A nn( .. 	Ay &&O
#<<4::%M&&?hhGAy &&O
#s!   BGAG.AGBGGc                     [        U 5      n[        SSS9n[        USS9n[        [        R                  X4U/5      nUb  X&l        U$ )Nr\   r]   r(   )r	   r   r?   import_as_namer)   )namera   r)   new_namenew_asnew_as_namenew_nodes          r   ImportAsNamerw      sJ    DzH%%Fwt,KD''(K)HIH Or,   c                     U R                   [        R                  :H  =(       aI    [        U R                  5      S:  =(       a*    U R                  S   R                   [
        R                  :H  $ )z4
Returns True if the node appears to be a docstring
r   )r>   r?   rh   r   rS   r   STRINGrD   s    r   is_docstringrz      sT     II))) M"M'+}}Q'7'<'<'LNr,   c           	      L   [        U5      n[        SX5      (       a  gSn[        UR                  5       HT  u  pA[	        U5      (       d  [        U5      (       a  Un[        U5      (       a  M9  [        U5      nU(       d    OX;   d  MT    g   [        S[        [        R                  U SS9/5      nUS:X  a8  WS:X  a2  UR                  S   R                  Ul        SUR                  S   l        U[        5       /nUR                  W[        [         R"                  U5      5        g)z
This seems to work

__future__Nr]   r(   r   r<   )r   r   rT   rS   is_shebang_commentis_encoding_commentrz   check_future_importr   r   r   NAMEr)   r   insert_childr   r?   rh   )featurerE   rootshebang_encoding_idxidxnamesimport_rS   s           r   future_importr      s     T?Dw55  t}}-	d##':4'@'@#& #D) . ejj'#)N(OPGq SAX q)00"%a ')$Hc4 0 0(;<r,   c           	         [        U5      n[        SX5      (       a  gSn[        UR                  5       Hj  u  pAUR                  [
        R                  :X  d  M%  UR                  (       d  M8  UR                  S   R                  [        R                  :X  d  Me  US-   n  O   UR                  US  H;  nUR                  [        R                  :X  a  US-  nM(  UR                  nSUl
          O   Sn[        S[        [        R                  U SS9/5      nU[        5       /nUR                  U[!        [
        R                  XS95        g)z<
An alternative to future_import() which might not work ...
r|   Nr   r   r<   r]   r(   )r   r   rT   rS   r>   r?   rh   r   ry   rg   r)   r   r   r   r   r   r   )	r   rE   r   
insert_posr   thing_afterr)   r   rS   s	            r   future_import2r     s    T?Dw55Jt}}-	99(((T]]]==  ELL0qJ	 . }}Z[1u}},!OJ##  2 ejj'$)O(PQG#Hj$t'7'7"QRr,   c                    U  Vs/ s H$  o"R                   [        R                  :w  d  M"  UPM&     n n[        U Vs/ s H  o3S4PM     sn5      n[	        U 5       H  u  p%UR                   [
        R                  :X  aW  UR                  S   R                   [        R                  :X  a,  UR                  S   R                  nUR                  S   XF'   Mz  X   nXTU'   M     U$ s  snf s  snf )z'
Parse a list of arguments into a dict
Nr   r      )
r>   r   COMMAdictrT   r?   argumentrS   EQUALrB   )arglistschemerJ   kret_mappingargslots          r   
parse_argsr   .  s     ";'QVVu{{%:q'G;626aD	623KG$88t}}$a)=)=)L<<?((D #QK9D # %  <2s   !C"C"C'c                     U R                   [        R                  :H  =(       a+    U R                  =(       a    [	        U R                  S   5      $ )Nr   )r>   r?   rh   rS   r   rD   s    r   is_import_stmtr   H  s:    II))) (dmm (dmmA&')r,   c                 2   [        U5      n[        XU5      (       a  gSnS H  n[        SXS5      (       d  M  Sn  O   U(       ay  Su  pg[        UR                  5       HO  u  p[	        U5      (       d  M  UnUn	U(       a-  UR
                  nU	S-  n	[	        U5      (       d  U	nO	U(       a  M-    O   Uc   eUc   eUn
OR[        UR                  5       H7  u  pUR                  [        R                  :w  a    O[        U5      (       a  M7    O   Wn
/ nU cM  [        [        R                  [        [        R                  S5      [        [        R                  US	S
9/5      nGO[        U [        [        R                  US	S
9/5      nUS:X  a  [        [        R                  [        [        R                   [        [        R                  S5      [        [        R"                  [        [        R$                  S5      [        [        R                  S5      /5      [        [        R"                  [        [        R&                  S5      [        [        R(                  S5      /5      /5      /5      nU[+        5       /nU[+        5       /nUR                  U
   R,                  nSUR                  U
   l        UR/                  U
[        [        R                  XS
95        [1        U5      S:  a.  UR/                  U
S-   [        [        R                  U5      5        gg)a  Works like `does_tree_import` but adds an import statement at the
top if it was not imported (but below any __future__ imports) and below any
comments such as shebang lines).

Based on lib2to3.fixer_util.touch_import()

Calling this multiple times adds the imports in reverse order.

Also adds "standard_library.install_aliases()" after "from future import
standard_library".  This should probably be factored into another function.
NF)absolute_importdivisionprint_functionunicode_literalsr|   TNNr   r[   r]   r(   standard_library.install_aliases()r<   r   )r   r   rT   rS   r   re   r>   r?   rh   rz   r   r_   r   r   r   r   powertrailerDOTLPARRPARr   r)   r   r   )r`   name_to_importrE   r   r$   rr   startendr   idx2r   children_hooksr   install_hookschildren_import
old_prefixs                   r   touch_import_topr   M  s    T?D66 E%L$55E	%
   
"4==1IC"4((,,DAID.t44" d  2    

 #4==1ICyyD,,,%% 2 
Nt''Y'^D9*
 
 WtEJJt'T&UV00
 !!1!1"&tzz(,UZZ9L(M(,T\\DD<Q(,UZZ9K(L<N )O(,T\\DT<R<@T<R<T )U()#* "#	"M ,WY7N 	*Oz*11J'*DMM*$j$t'7'7"\]
>Q*q.$t/?/?*PQ r,   c                    U nU R                   [        R                  :X  a  U R                  (       d
  [	        5       $ U R                  S   n U R                   [        R
                  :X  a;  [        U R                  S   S5      (       a  U R                  S   R                  S:X  d
  [	        5       $ U R                  S   R                   [        R                  :X  a  U R                  S   n OU R                  S   n U R                   [        R                  :X  a  [	        5       nU R                   H  nUR                   [        R                  :X  a  UR                  UR                  5        M>  UR                   [        R                  :X  d  M^  UR                  S   nUR                   [        R                  :X  d   eUR                  UR                  5        M     U$ U R                   [        R                  :X  aE  U R                  S   n U R                   [        R                  :X  d   e[	        U R                  /5      $ U R                   [        R                  :X  a  [	        U R                  /5      $  SU-  5       e)zVIf this is a future import, return set of symbols that are imported,
else return None.r   r   rB   r|      r   zstrange import: %s)r>   r?   rh   rS   rL   import_fromhasattrrB   r   r   import_as_namesr   addrq   )rE   savenoderesultns       r   r   r     s    HII)))dmmu==DII)))DMM!$g..MM!""m3u}}Q

*}}Q}}QyyD(((Avv#

177#4...JJqMvv+++

177#  	d))	)}}QyyEJJ&&&DJJ<  	ejj	 DJJ<   	6*X55ur,   z^#!.*pythonz^#.*coding[:=]\s*([-\w.]+)c                 ^    [        [        R                  " [        U R                  5      5      $ )z
Comments are prefixes for Leaf nodes. Returns whether the given node has a
prefix that looks like a shebang line or an encoding line:

    #!/usr/bin/env python
    #!/usr/bin/python3
)boolrematchSHEBANG_REGEXr)   rD   s    r   r}   r}     s     455r,   c                 ^    [        [        R                  " [        U R                  5      5      $ )z
Comments are prefixes for Leaf nodes. Returns whether the given node has a
prefix that looks like an encoding line:

    # coding: utf-8
    # encoding: utf-8
    # -*- coding: <encoding name> -*-
    # vim: set fileencoding=<encoding name> :
)r   r   r   ENCODING_REGEXr)   rD   s    r   r~   r~     s     566r,   c                     [        U5      S:  d   e[        U5      S:X  a  Uu  p4U[        5       U/nOUn[        [        U 5      XRS9$ )z
Example:
>>> wrap_in_fn_call("oldstr", (arg,))
oldstr(arg)

>>> wrap_in_fn_call("olddiv", (arg1, arg2))
olddiv(arg1, arg2)

>>> wrap_in_fn_call("olddiv", [arg1, comma, arg2, comma, arg3])
olddiv(arg1, arg2, arg3)
r   r   r(   )r   r
   r   r	   )fn_nameargsr)   expr1expr2newargss         r   wrap_in_fn_callr     sJ     t9q==
4yA~%'5)Ww66r,   rI   r   )2__doc__lib2to3.fixer_utilr   r   r   r   r   r   r	   r
   lib2to3.pytreer   r   lib2to3.pygramr   r?   r   r   r%   r+   r/   r3   r:   rF   rQ   rY   rb   if_stmt
while_stmtfor_stmttry_stmt	with_stmtri   r_   r   rd   ro   rw   rz   r   r   r   r   r   r   r   r   r}   r~   r   r   r,   r   <module>r      s   3 3 3 & 1   	D182
*  0, <<$--PTP^P^_!!4#3#349vN%=PS@4)
\RD&6R .6
77r,   